1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#!/usr/bin/python3
import rrdtool
import os
import time
print("===== Starting Python bindings test =====")
rrd_file = "python_test.rrd"
png_file = "python_test.png"
try:
print("--> Creating RRD via Python bindings...")
rrdtool.create(
rrd_file,
"--start", "now-10m",
"--step", "60",
"DS:test:GAUGE:120:0:100",
"RRA:AVERAGE:0.5:1:10"
)
print("OK: RRD file created.")
print("--> Updating RRD via Python bindings...")
rrdtool.update(rrd_file, "N:73")
print("OK: RRD file updated.")
print("--> Fetching data via Python bindings...")
start_time = int(time.time()) - 300
fetch_result = rrdtool.fetch(rrd_file, "AVERAGE", "--start", str(start_time))
print(fetch_result)
print("OK: Data fetched.")
print("--> Creating graph via Python bindings...")
rrdtool.graph(png_file, "--start", "now-10m", f"DEF:mydata={rrd_file}:test:AVERAGE", "LINE1:mydata#0000FF:test data")
print("OK: Graph created.")
print("===== Python bindings test PASSED =====")
finally:
if os.path.exists(rrd_file): os.remove(rrd_file)
if os.path.exists(png_file): os.remove(png_file)
|