Skip to content

Commit

Permalink
SONiC Management Framework Release 1.0 (#659)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Change system information poll to not use file locking

Signed-off-by: Howard Persh <[email protected]>

* Modify system system info poller to provide process start time in seconds

Signed-off-by: Howard Persh <[email protected]>

* Small optimization for system info poll script

Signed-off-by: Howard Persh <[email protected]>

* Add new scripts for CLI backend to setup.py

Signed-off-by: Howard Persh <[email protected]>
  • Loading branch information
PrabhuSreenivasan authored and renukamanavalan committed Nov 14, 2019
1 parent be337d4 commit e0e8c2f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/syseeprom-to-json
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 "}" }
48 changes: 48 additions & 0 deletions scripts/syspoll
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)
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit e0e8c2f

Please sign in to comment.