Skip to content

[files/image_config] Adds syspoll daemon - #3785

Open
hpersh wants to merge 1 commit into
sonic-net:masterfrom
hpersh:mgmt_1.0_support
Open

hpersh wants to merge 1 commit into
sonic-net:masterfrom
hpersh:mgmt_1.0_support

Conversation

@hpersh

@hpersh hpersh commented Nov 19, 2019

Copy link
Copy Markdown
Contributor

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

hpersh commented Nov 19, 2019

Copy link
Copy Markdown
Contributor Author

*** 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
Copy Markdown
Contributor

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

@pavel-shirshov pavel-shirshov left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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