Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

[files/image_config] Adds syspoll daemon #3785

wants to merge 1 commit into from

Conversation

hpersh
Copy link
Contributor

@hpersh hpersh commented Nov 19, 2019

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)

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>
@hpersh
Copy link
Contributor Author

hpersh commented Nov 19, 2019

*** This is a placeholder pull-request ***
This commit is linked with pull request to sonic-utilities.
When sonic-net/sonic-utilities#745 merges, this pull request must be updated so that the sonic-utilities submodule points to the correct commit.
In the meantime, changes can be reviewed.

@jleveque
Copy link
Contributor

Looks OK to me. Once sonic-net/sonic-utilities#745 is merged, please update the submodule in the PR.

Copy link
Contributor

@pavel-shirshov pavel-shirshov left a 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Why do we need to update hostname each second?
  2. 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()
Copy link
Contributor

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])
Copy link
Contributor

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'):
Copy link
Contributor

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:]:
Copy link
Contributor

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()
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants