Created
December 11, 2014 08:42
-
-
Save sourceperl/c806639dd141c5de4a16 to your computer and use it in GitHub Desktop.
Find peak in value of an RRDtool base.
This file contains hidden or 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
import rrdtool | |
import datetime | |
# retrieve RRD data (3 days past from now) | |
rrd = rrdtool.fetch('/home/pi/rrd/flow.rrd', 'AVERAGE', '-s -3d') | |
# timestamp start/end | |
start = rrd[0][0] | |
end = rrd[0][1] | |
step = rrd[0][2] | |
# array of data | |
data = rrd[2] | |
# c is current value, last_c is c at cycle -1 | |
c = None | |
last_c = None | |
def ts2str(timestamp): | |
return datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S') | |
# start/stop timestamp banner | |
print("start: %d (%s), end %d (%s)" %(start, ts2str(start), end, ts2str(end))) | |
print("") | |
# display only value with high change rate | |
for i, item in enumerate(data): | |
if item[0] is not None: | |
c = item[0] | |
if last_c is None: | |
last_c = c | |
chg_rate = 100*abs(c - last_c)/c | |
# display value if change rate more than 10% | |
if (chg_rate > 10.0): | |
tstamp = (i*step) + start | |
print("%s: %f (%.1f%% last %.2f)" % (ts2str(tstamp), item[0], chg_rate, last_c)) | |
last_c = c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment