API support to get raw RRD data by graph name

Hi,
The existing API supports getting the RRD data in etiher raw (image) or base64 format.

/api/v0/devices/:hostname/:type

  • output: Set how the graph should be outputted (base64, display), defaults to display.

I would like to be able to specify a third option - perharps output=data , where it would run a rrd query instead of a rrd graph, and return the raw data as a lump of JSON.

I can probably code this myself - would there be any interest / how likely is it to get accepted??

I think we would start in graph_inc.php

$image_data = Rrd::graph($rrd_options);

// output the graph
if (\LibreNMS\Util\Debug::isEnabled()) {
    echo '<img src="data:' . get_image_type($graph_image_type) . ';base64,' . base64_encode($image_data) . '" alt="graph" />';
} else {
    header('Content-type: ' . get_image_type(Config::get('webui.graph_type')));
    echo $output === 'base64' ? base64_encode($image_data) : $image_data;
}

and make an alternative call to Rrd instead of

$image_data = Rrd::graph($rrd_options);

then in rrd.php we would need an addition methd fetch a bit like graph:
public function graph(string $options): string
{

Look at this project

Hi… i already have that installed. My problem is getting from the datasource name (like device_power) to the filename of the RRD file, and how many reading etc are in the file.

Ive looked at the code, and concluded its would be a LOT of work to unpick it and return this.

Its all structured around various modules for each device class, which build up a shell command to pass to rrdgraph.

This shell command contains the stuff I want (ie, rrd filename, descriptions of the various lines that are required, labels etc), but its all munged together as a command line :frowning:

I think the best that can be done without a major re-write would be to return the rrdgraph command, and for me to parse it outwith librenms.

I dont this this is going to get accepted as a merge, since im probably the only person in the world wanting API access to the RRD command line by device :slight_smile:

Therefore, im giving up on this one.

I started working on something that would help, but I am a long ways off from it being done and I am currently not working on it. Any help would be appreciated.

1 Like

Hi…
Im afraid ive given up on this one - it would involve abstracting away all the logic in the various device specific modules, and I dont have 99% of the devices to even test against.
Its also PHP, which im not that keen to get back into in a major way :slightly_smiling_face:

Good luck with your changes tho

Any updates on this by anyone? Would be awesome if I could query rdd files from the api