-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONiC Management Framework Release 1.0 (#659)
* Added scripts to provide back-end for CLI commands Scripts to provide the files /var/platform/syseeprom and /var/paltform/system, which are JSON files read by CLI commands, to provide system information. Signed-off-by: Howard Persh <Howard_Persh@dell.com> * Change system information poll to not use file locking Signed-off-by: Howard Persh <Howard_Persh@dell.com> * Modify system system info poller to provide process start time in seconds Signed-off-by: Howard Persh <Howard_Persh@dell.com> * Small optimization for system info poll script Signed-off-by: Howard Persh <Howard_Persh@dell.com> * Add new scripts for CLI backend to setup.py Signed-off-by: Howard Persh <Howard_Persh@dell.com>
- Loading branch information
1 parent
be337d4
commit e0e8c2f
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "}" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters