What's the command line for rrdtool to create a graph using the last update time as the end time? - rrdtool

Going off of this question: Print time of recording for LAST value
It appears possible to have rrdtool compute the timestamp of the last update in a rrd. How do you use this in a command as the "end" time?
i.e. I want to do something like this:
rrdtool graph img.png -a PNG -s e-600 -e LASTUPDATETIME -v "CPU Usage" \
--title "CPU Utilization" DEF:ds0a=node.rrd:ds0:AVERAGE \
DEF:ds1a=node.rrd:ds1:AVERAGE AREA:ds0a#35b73d:"User" \
LINE1:ds1a#0400ff:"System"
I tried mucking about the DEF, CDEF and VDEF things to no avail:
rrdtool graph img.png -a PNG -v "CPU Usage" --title "CPU Utilization" \
DEF:data=node.rrd:x:AVERAGE CDEF:count=data,UN,UNKN,COUNT,IF \
VDEF:last=count,MAXIMUM \
DEF:ds0a=node.rrd:ds0:AVERAGE:start=end-600:end=last \
DEF:ds1a=node.rrd:ds1:AVERAGE:start=end-600:end=last \
AREA:ds0a#35b73d:"User" LINE1:ds1a#0400ff:"System"
This results in:
ERROR: end time: unparsable time: last
Any ideas?

on the command line, you could do
rrdtool graph img.png -a PNG -s e-600 -e `date +%s node.rrd` -v "CPU Usage" \
--title "CPU Utilization" DEF:ds0a=node.rrd:ds0:AVERAGE \
DEF:ds1a=node.rrd:ds1:AVERAGE AREA:ds0a#35b73d:User \
LINE1:ds1a#0400ff:System

Related

How to save aws cli scan result

I wrote following command to scan DDB (please correct me if I'm wrong). I want to get all value in id column, when sortKey column contains text prefix|:
aws dynamodb scan \
--table-name ProductTable \
--projection-expression "id" \
--filter-expression 'contains(sortKey,:p)' \
--expression-attribute-values '{":p":{"S":"prefix|"}}'
As a result, it returned a vim-view-like list, but how could I copy or save all results?
Thanks
You can output the result of a CLI command to a file using the > or >> operator in the following syntax:
aws dynamodb scan \ --table-name ProductTable \ --projection-expression "id" \ --filter-expression 'contains(sortKey,:p)' \ --expression-attribute-values '{":p":{"S":"prefix|"}}' > output.txt
In this example output.txt is the name of the file you want to output the result to. Its important to note that when you use > operator the output of the command will not be displayed in the terminal and will be written to the specified file.
It’a also important to note that each time you direct output to a file, the contents of the file will be replaced with the output of the most recent command to output to that file. If you’d prefer to append to the end of the file, instead of replacing the file contents you can use the double output operator >> instead of >.

rrdtool update expected 2 data sources

I wrote a simple rrdtool database to graph Wi-Fi signal strength and modulation. The signal strength works, but when I try to update the db with MCS information, I get:
ERROR: ./somefile.rrd: expected 2 data source readings (got 1) from mcsul15
Here's my update code:
rssi=`snmpget -v 2c -c communityname 1.2.3.4 .1.3.6.1.4.1.17713.21.1.2.3.0 | awk -v x=4 '{print $x}' | tr -d -`
noisefloor=`snmpget -v 2c -c communityname 1.2.3.4 .1.3.6.1.4.1.17713.21.1.2.20.1.9.1 | awk -v x=4 '{print $x}' | tr -d -`
ulmcs14=`snmpget -v 2c -c communityname 1.2.3.4 CAMBIUM-PMP80211-MIB::ulWLanMCS14Packets.0 | awk -v x=4 '{print $x}'`
ulmcs15=`snmpget -v 2c -c communityname 1.2.3.4 CAMBIUM-PMP80211-MIB::ulWLanMCS15Packets.0 | awk -v x=4 '{print $x}'`
echo $rssi
echo $noisefloor
echo $ulmcs14
echo $ulmcs15
rrdtool update ./somefile.rrd --template \
rssi:noisefloor N:$rssi:$noisefloor \
mcsul15:mcsul14 N:$ulmcs15:$ulmcs14
Which gives me:
68
94
143679
17602658
ERROR: ./somefile.rrd: expected 2 data source readings (got 1) from mcsul15
What am I missing?
Assuming that somefile.rrd has 4 DS defined in it with those 4 names, you should give all four together when updating. You can only specify one template for the update, and the other parameters should be in that format.
Also, check the names of your DS are correct as your variable is called $ulmcs15 but the DS is being named mcsul15.
rrdtool update ./somefile.rrd --template \
rssi:noisefloor:mcsul15:mcsul14 \
N:$rssi:$noisefloor:$ulmcs15:$ulmcs14
The error message is because in your original commandline, mcsul15:mcsul14 is being taken as an update vector, not a template. Thus it is one timestamp and one value, where two were expected. It would have been a better error message to say something like "timestamp not recognised in 'mcsul15'" but that's a different issue...

How could I print the time of a max value in a rrdtool graph?

I've searched so many times that I'm tired to.
I've a rrdtool database, with which I'm used to print the MAX, Min, Average value.
Now, I would like to print the time of the max value stored in the rrd db.
Here is the definition of my rrd (CPU monitoring) :
rrdtool create CPU.rrd --start $Date \
DS:CPU_ALL:GAUGE:600:U:U \
DS:User:GAUGE:600:U:U \
DS:Sys:GAUGE:600:U:U \
DS:Wait:GAUGE:600:U:U \
DS:Idle:GAUGE:600:U:U \
RRA:AVERAGE:0.5:1:20000 \
RRA:AVERAGE:0.5:1:20000 \
RRA:AVERAGE:0.5:1:20000 \
RRA:AVERAGE:0.5:1:20000 \
RRA:AVERAGE:0.5:1:20000
Here is my graph script :
rrdtool graph CPUUsed.png --start -1w \
DEF:CPUTOTAL=CPU.rrd:CPU_ALL:AVERAGE AREA:CPUTOTAL#FF0000:"CPU Used" LINE2:CPUTOTAL#FF0000 \
--vertical-label "CPU" \
--title "CPU " \
--width 530 \
--height 380 \
GPRINT:CPUTOTAL:MAX:"MAX\:%6.2lf %s" \
GPRINT:CPUTOTAL:MIN:"MIN\:%6.2lf %s" \
GPRINT:CPUTOTAL:AVERAGE:"MOY\:%6.2lf %s" \
GPRINT:CPUTOTAL:LAST:"LAST\:%6.2lf %s"
How could I generate this graph adding the time of the max CPU value ?
OK, you have a couple of problems here.
Firstly, your RRD is misconfigured. You have 5 identical RRAs defined - this does not make sense. One RRA will hold values at the specified resolution for all the defined DSs. However, you may want to have more at higher granularity (to speed up graphs of month or year). You may also want to have a MIN or MAX type RRA so that your MIN and MAX figures are more accurate.
For example, this set defines both MAX and MIN RRAs as well as the average, and will also have 4 rollups that roughly correspond to daily, weekly, monthly and yearly graphs.
RRA:AVERAGE:0.5:1:20000 \
RRA:AVERAGE:0.5:6:2000 \
RRA:AVERAGE:0.5:24:2000 \
RRA:AVERAGE:0.5:288:2000 \
RRA:MAX:0.5:1:20000 \
RRA:MAX:0.5:6:2000 \
RRA:MAX:0.5:24:2000 \
RRA:MAX:0.5:288:2000 \
RRA:MIN:0.5:1:20000 \
RRA:MIN:0.5:6:2000 \
RRA:MIN:0.5:24:2000 \
RRA:MIN:0.5:288:2000
Secondly, when you want to print a single figure in the GPRINT line, you need to use a VDEF to convert your time series data (from the DEF or CDEF) into a single value, using some consolodation functions.
For example, this set of commands will use the MAX and MIN type DEFs defined previously, then calculate summaries over them using a VDEF. Of course, you could just use CPUTOTAL instead of defining CPUTOTALMAX and CPUTOTALMIN (saving yourself the additional RRAs) but, as you move to using the lower-granularity RRAs, accuracy will fall. If you don't have lower-granularity RRAs, then you will be accurate, but will use a lot of additional CPU at graph time and graph creation will be slower. Using different resolution RRAs speeds up graph creation.
DEF:CPUTOTAL=CPU.rrd:CPU_ALL:AVERAGE \
DEF:CPUTOTALMAX=CPU.rrd:CPU_ALL:MAX \
DEF:CPUTOTALMIN=CPU.rrd:CPU_ALL:MIN \
VDEF:overallmax=CPUTOTALMAX,MAXIMUM \
VDEF:overallmin=CPUTOTALMIN,MINIMUM \
VDEF:overallavg=CPUTOTAL,AVG \
VDEF:overalllst=CPUTOTAL,LAST \
AREA:CPUTOTAL#FF0000:"CPU Used" \
LINE2:CPUTOTAL#FF0000 \
GPRINT:overallmax:"MAX\:%6.2lf %s" \
GPRINT:overallmin:"MIN\:%6.2lf %s" \
GPRINT:overallavg:"MOY\:%6.2lf %s" \
GPRINT:overalllst:"LAST\:%6.2lf %s" \
GPRINT:overallmax:"Max was at %c":strftime
The last line will print the time of the maxima rather than the value. When a VDEF calculates a MAX or MIN, it actually returns two components - value, and point in time. Usually you use the value, but by appending :strftime to the GPRINT directrive you can use the time component instead.
I suggest you spend a bit more time working through the tutorials and examples on the RRDTool Website, which should help you gain a better understanding of how RRDTool works.

How do I fetch the hourly average CPUUtilization for my cluster?

I would like to be able to fetch the hourly average CPUUtilization for my cluster. But using amazonica I get this error: com.amazonaws.services.cloudwatch.model.InvalidParameterValueException: The parameter StartTime must not equal parameter EndTime.
(get-metric-statistics {:metric-name "CPUUtilization"
:namespace "AWS/ECS"
:dimensions [{:name "ClusterName" :value "my-cluster"}]
:start-time "2018-08-31T12:00:00Z"
:end-time "2018-08-31T13:00:00Z"
:statistics ["Average"]
:period 3600})
Running this aws cmd returns the correct metric, but I want to use amazonica to do this.
aws cloudwatch get-metric-statistics \
--metric-name CPUUtilization \
--namespace AWS/ECS \
--dimensions Name=ClusterName,Value=my-cluster \
--start-time 2018-08-31T12:00:00Z \
--end-time 2018-08-31T13:00:00Z \
--statistics Average \
--period 3600
Due to the documentation :start-time and :end-time must be a Date object. It does not work with string in your example. You can also take a look at this example
(let [date-string (.. (SimpleDateFormat. "MM-dd-yyyy")
(format (Date.)))]
(get-metric-statistics
....
:start-time (.minusDays (DateTime.) 1)
:end-time date-string
...
))

RRDtool bad format problem

I'm using RRDtool for graphing some monitoring information. One problem I faced when using rrd is using GRPINT directive. I use following command to graph networking Rx/Tx data:
rrdtool graph out.png -v bytes -a PNG --start "-6 hour" --title "WLAN traffic" \
--vertical-label="Bit/s" \
'DEF:_rx=/root/ppp0.rrd:rx:AVERAGE' \
'DEF:_tx=/root/ppp0.rrd:tx:AVERAGE' \
'CDEF:tx=_tx,-8,*' \
'CDEF:rx=_rx,8,*' \
'COMMENT:WLAN traffic\j' \
"AREA:rx#333333:WLAN Rx" \
"AREA:tx#990000:WLAN Tx" \
'GPRINT:rx:AVERAGE:"Rx average - %d"' \
'GPRINT:tx:AVERAGE:"Tx average - %d"'
I've got:
ERROR: bad format for GPRINT in 'Rx average - %d'
I tried to simplify format, but when I've got:
ERROR: bad format for GPRINT in '%d'
I understand that I doing something completely wrong. What's the problem?
Your %d format is for integers. GPRINT (and PRINT) only support double formats ... see man sprintf for inspiration. Try %.0lf for starters.