-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[files/image_config] Adds syspoll daemon #3785
base: master
Are you sure you want to change the base?
Conversation
Adds daemon syspoll, which updates a file to be read by CLI commands, to print system status information. This is an intermediate implementation -- once the redis DB is set up for system information, this daemon should update the DB, not a file. Signed-off-by: Howard Persh <hpersh@yahoo.com>
*** This is a placeholder pull-request *** |
Looks OK to me. Once sonic-net/sonic-utilities#745 is merged, please update the submodule in the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As comments
|
||
while True: | ||
d = {} | ||
d['hostname'] = subprocess.check_output(['hostname']).rstrip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why do we need to update hostname each second?
- It would be simpler to open '/etc/hostname' instead of forking and running bash to run hostname
while True: | ||
d = {} | ||
d['hostname'] = subprocess.check_output(['hostname']).rstrip() | ||
w = subprocess.check_output(['free']).split('\n')[1].split() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read this info from /proc/meminfor
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]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please read the file and extract info using the python language.
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'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use python, not bash in python
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:]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read this from /proc
continue | ||
pid = w[1] | ||
try: | ||
w2 = subprocess.check_output(['bash', '-c', 'cat /proc/{}/stat 2>/dev/null'.format(pid)]).split() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please read the file using python
Adds daemon syspoll, which updates a file to be read by CLI commands, to print system status information. This is an intermediate implementation -- once the redis DB is set up for system information, this daemon should update the DB, not a file.
Signed-off-by: Howard Persh hpersh@yahoo.com
- What I did
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)