Skip to content

Commit

Permalink
CP-49148: Convert rrdd-example.py to python3
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Cheng <stephen.cheng@cloud.com>
  • Loading branch information
stephenchengCloud committed Jul 31, 2024
1 parent c398741 commit 946ca37
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions ocaml/xcp-rrdd/scripts/rrdd/rrdd-example.py
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()

0 comments on commit 946ca37

Please sign in to comment.