How to fetch data from smokeping rrd file and make output with txt file when host go down or up in perl or php?
I send 10 ICMP packets every 60sec.
I want to fetch data from rrd and parse it to have such output:
17 Jun 2015 12:03:00 - host is down
17 Jun 2015 12:05:00 - host is up
E.g. host down when no data received or packet loss > 50%
I've already tried:
rrdtool fetch /var/lib/smokeping/Host/Swadzim.rrd AVERAGE
1434546000: -nan 0.0000000000e+00 1.1677527778e-02 9.5520694444e-03 1.0010958333e-02 1.0222916667e-02 1.0669152778e-02 1.1147625000e-02 1.1677527778e-02 1.2782055556e-02 1.3641402778e-02 1.5893805556e-02 2.0290416667e-02 1434546720: -nan 0.0000000000e+00 1.0685083333e-02 9.2544444444e-03 9.5931388889e-03 9.9897500000e-03 1.0258138889e-02 1.0441527778e-02 1.0685083333e-02 1.1117277778e-02 1.1553638889e-02 1.2946375000e-02 1.4254041667e-02
I think you've a mistaken impression of what
rrdtool
does. It's a very nice tool for collecting time series data, collating it and archiving it. But inevitably - when you do archive the data, you lose resolution because you're aggregating your results.Now, what smokeping does is - ping a server, keeps track of latency and packet loss.
That's all to the good, but if you want to monitor and alarm based on this - what you really need is to do the ping test yourself, rather than reading out of archive logs. At best - you'll be getting out of date information.
You can probably extract the data you need from the rrd. I can't do this for you, because I don't have enough information. What you need to do is:
rrdtool fetch
which you refer to - is a step in the right direction. You'll probably need something like:But then - from the values you get - you'll need to figure out which ones are relevant. (You might want to look at the
LAST
consolidation function as well as that may be relevant).can help you figure this out - it will list the data sources you're logging (in order).
But really - it's just much easier to catch the results of the ping in the first place, rather than ping something, process the data, archive it, consolidate it, and extract a time averaged consolidated result from the archive.