javarrdtoolrrdrrd4j

Combine separate RRD files to a single graph


Using rrd4j, how can I combine several .rrd files either into a single .rrd or (ideally) to a single graph?

More details:

I have several copies of essentially the same .rrd. Each file records several sensor data readings, all with the name sensor-1, sensor-2 across files. So data1.rrd, data2.rrd will all contain data sources of sensor-1 etc.

The DS definition is as follows.

DS:sensor-1:GAUGE:35:U:U DS:sensor-2:GAUGE:35:U:U DS:sensor-3:GAUGE:35:U:U

I can generate a graph for each individually by adding a data source to a graph like this;

val graph = new RrdGraphDef()
graph.datasource("sensor-1", data1.rrd", "sensor-1", AVERAGE)
graph.datasource("sensor-2", data1.rrd", "sensor-1", AVERAGE)
graph.line("sensor-1", green)
graph.line("sensor-2", red)

but if I do the same but for data2.rrd (adding another datasource to the same graph instance), it seems to loose the preceding data and graphs just one of the file's data.

I suspect that each DS having the same name across files may be a problem.

Suggestions on how to achieve the same with regular RRD tool might also be helpful as I might be able to translate to rrd4j


Solution

  • This statement: graph.datasource("varname", "filename.rrd", "dsname", AVERAGE) defines a new variable to use called varname, which corresponds to the DS dsname in the file filename.rrd, consolodated using the AVERAGE Consolodation Function.

    Clearly, you cannot have two variables in the same graph with the same name; however, there is nothing to prevent you from pulling data from multiple different RRD files, and nothing to prevent you from using a different varname to the DS name.

    However, you should only use alphanumerics in the variable name -- in particular, avoid '-', even though it is supposed to work. Underscores are OK.

    So, this is perfectly valid: graph.datasource("sensora", "sitea.rrd", "sensor", AVERAGE) graph.datasource("sensorb", "siteb.rrd", "sensor", AVERAGE) and will define two variables, sensora and sensorb corresponding to the same named DS in two different RRD files.

    Do not use sensor-1 as a varname, as it contains a '-' symbol.

    Not having seen the RRD4j code that is failing I can't say for certain, but I would suspect it is either because you are not renaming the varname, making both variables share the same name and overwrite one another, or because of the '-' in the varname.