forked from xapi-project/xen-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CP-49148: Convert rrdd-example.py to python3
Signed-off-by: Stephen Cheng <stephen.cheng@cloud.com>
- Loading branch information
1 parent
c398741
commit 946ca37
Showing
1 changed file
with
16 additions
and
15 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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
#!/usr/bin/env python | ||
#!/usr/bin/env python3 | ||
|
||
import rrdd, os | ||
import os | ||
import rrdd | ||
|
||
if __name__ == "__main__": | ||
# Create a proxy for communicating with xcp-rrdd. | ||
api = rrdd.API(plugin_id="host_mem") | ||
while True: | ||
# Wait until 0.5 seconds before xcp-rrdd is going to read the output file. | ||
api.wait_until_next_reading(neg_shift=.5) | ||
# Collect measurements. | ||
cmd = "free -k | grep Mem | awk '{print $2, $3, $4}'" | ||
vs = os.popen(cmd).read().strip().split() | ||
# Tell the proxy which datasources should be exposed in this iteration. | ||
api.set_datasource("used_mem", vs[1], min_val=0, max_val=vs[0], units="KB") | ||
api.set_datasource("free_mem", vs[2], min_val=0, max_val=vs[0], units="KB") | ||
# Write all required information into a file about to be read by xcp-rrdd. | ||
api.update() | ||
# Create a proxy for communicating with xcp-rrdd. | ||
api = rrdd.API(plugin_id="host_mem") | ||
while True: | ||
# Wait until 0.5 seconds before xcp-rrdd is going to read the output file. | ||
api.wait_until_next_reading(neg_shift=.5) | ||
# Collect measurements. | ||
cmd = "free -k | grep Mem | awk '{print $2, $3, $4}'" | ||
vs = os.popen(cmd).read().strip().split() | ||
# Tell the proxy which datasources should be exposed in this iteration. | ||
api.set_datasource("used_mem", vs[1], min_val=0, max_val=vs[0], units="KB") | ||
api.set_datasource("free_mem", vs[2], min_val=0, max_val=vs[0], units="KB") | ||
# Write all required information into a file about to be read by xcp-rrdd. | ||
api.update() |