diff --git a/scripts/syseeprom-to-json b/scripts/syseeprom-to-json new file mode 100755 index 0000000000..89b7256f50 --- /dev/null +++ b/scripts/syseeprom-to-json @@ -0,0 +1,31 @@ +#!/usr/bin/awk -f + +BEGIN { print "{"; n = 0 } + +function sep() +{ + if (n > 0) print ", "; + ++n; +} + +/Product Name/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/Part Number/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/Serial Number/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/Base MAC Address/ { sep(); print "\"" $1 " " $2 " " $3 "\": \"" $6 "\""; } +/Manufacture Date/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/Device Version/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/Label Revision/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/Platform Name/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/ONIE Version/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/MAC Addresses/ { sep(); print "\"" $1 " " $2 "\": " $5; } +/Manfacturer/ { sep(); print "\"" $1 "\": \"" $4 "\""; } +/Manfacture Country/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/Vendor Name/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/Diag Version/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/Service Tag/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/Hardware Version/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/Software Version/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/Manfacture Date/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } +/Model Name/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; } + +END { print "}" } diff --git a/scripts/syspoll b/scripts/syspoll new file mode 100755 index 0000000000..e9a2551789 --- /dev/null +++ b/scripts/syspoll @@ -0,0 +1,48 @@ +#!/usr/bin/python + +import sys +import os +import subprocess +import json +import time + +progname = sys.argv[0] + +outfile = '/var/platform/system' +tmpfile = '/var/platform/system.tmp' + +ticks_per_sec = os.sysconf(os.sysconf_names['SC_CLK_TCK']) + +while True: + d = {} + d['hostname'] = subprocess.check_output(['hostname']).rstrip() + w = subprocess.check_output(['free']).split('\n')[1].split() + d['total'] = int(w[1]) + d['used'] = int(w[2]) + d['free'] = int(w[3]) + btime = int(subprocess.check_output(['bash', '-c', "cat /proc/stat | grep '^btime'"]).split()[1]) + cpus = [] + for li in subprocess.check_output(['bash', '-c', "cat /proc/stat | grep '^cpu'"]).rstrip().split('\n'): + w = li.split() + cpus.append({'user': int(w[1]) + int(w[2]), 'system': int(w[3]), 'idle': int(w[4])}) + d['cpus'] = cpus + procs = {} + for li in subprocess.check_output(['ps', 'aux']).rstrip().split('\n')[1:]: + w = li.split() + cmd = ' '.join(w[10:]) + if progname in cmd: + continue + pid = w[1] + try: + w2 = subprocess.check_output(['bash', '-c', 'cat /proc/{}/stat 2>/dev/null'.format(pid)]).split() + except subprocess.CalledProcessError: + continue + procs[pid] = {'cmd': cmd, 'start': btime + int(w2[21]) / ticks_per_sec, 'user': int(w2[13]), 'system': int(w2[14]), 'mem': int(w[4]), 'cpuitil': float(w[2]), 'memutil': float(w[3])} + d['procs'] = procs + + f = open(tmpfile, 'w') + json.dump(d, f) + f.close() + os.rename(tmpfile, outfile) + + time.sleep(1) diff --git a/setup.py b/setup.py index 44c8dabe1c..009a85aae3 100644 --- a/setup.py +++ b/setup.py @@ -83,6 +83,8 @@ 'scripts/route_check.py', 'scripts/route_check_test.sh', 'scripts/sfpshow', + 'scripts/syseeprom-to-json', + 'scripts/syspoll', 'scripts/teamshow', 'scripts/warm-reboot', 'scripts/watermarkstat',