Skip to content

Instantly share code, notes, and snippets.

@giovtorres
Last active January 2, 2016 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giovtorres/8c0d97b4049534ab82b5 to your computer and use it in GitHub Desktop.
Save giovtorres/8c0d97b4049534ab82b5 to your computer and use it in GitHub Desktop.
"scontrol show node" in python
#!/usr/bin/python
"""
scontrol-show-node - python equivalent to `scontrol show node`.
It also takes an optional node as an argument.
"""
import sys
from datetime import datetime
from operator import itemgetter
import argparse
import pyslurm
pyslurmnode = pyslurm.node()
allnodes = pyslurmnode.get()
parser = argparse.ArgumentParser()
parser.add_argument("node", nargs="*", help="show node")
args = parser.parse_args()
if args.node:
values = [allnodes.get(args.node[0])]
else:
values = allnodes.itervalues()
for node in sorted(values, key=itemgetter('name')):
print "NodeName=%s Arch=%s CoresPerSocket=%s" % (
node["name"],
node["arch"],
node["cores"])
print " CPUAlloc=%s CPUErr=%s CPUTot=%s CPULoad=%.2f Features=%s" %(
node["alloc_cpus"],
node["err_cpus"],
node["total_cpus"],
node["cpu_load"] / 100,
node["features"])
print " Gres=%s" % node["gres"]
print " NodeAddr=%s NodeHostName=%s Version=%s" % (
node["node_addr"],
node["node_hostname"],
node["version"])
print " OS=%s RealMemory=%s AllocMem=%s Sockets=%s Boards=%s" % (
node["os"],
node["real_memory"],
node["alloc_memory"],
node["sockets"],
node["boards"])
print " State=%s ThreadsPerCore=%s TmpDisk=%s Weight=%s" % (
node["node_state"],
node["threads"],
node["tmp_disk"],
node["weight"])
print " BootTime=%s SlurmdStartTime=%s" % (
datetime.fromtimestamp(node["boot_time"]).isoformat(),
datetime.fromtimestamp(node["slurmd_start_time"]).isoformat())
print " CurrentWatts=%s LowestJoules=%s ConsumedJoules=%s" % (
node["energy"]["current_watts"],
"",
node["energy"]["consumed_energy"])
print " ExtSensorsJoules=n/s ExtSensorsWatts=%s ExtSensorsTemp=n/s" % ("")
print ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment