Create multiple graphs of the same rrd?

hi there - I have being trying to create a luci statistic graph for my energy monitor project of using openwrt as the backend.. okay got MQTT to create luci statistic RRD's . figured out how to make rrd definitions.. and how to setup different tabs for different varities of MQTT topic subjects -- ie temperature, power, humidity etc..

but what eludes me is making multiple types of graph within in luci statistics - I can only create single graph of each instance or comparison graph but not both with in the same page.. just wondering if it is possible before I continue to try. example :
test

If you find that RRDTool isn't getting you what you need, you might want to look at https://d3js.org/. It's a Javascript library that is widely used and supported, and very powerful. The data manipulation and rendering can "all" be handled in the browser. I serve tabular data to the browser and it takes it from there. The downside is that the learning curve is pretty steep. The concepts of how it handles data took me a while to wrap my head around, but there are many good tutorials out there.

One can't see it here, but it zooms and pans on a regular browser, as well as with "standard" touch gestures under iOS and Android. It also follows MQTT updates over websockets in real time. Four sensors on the same graph, two different scales.

image

thank you very much for the reply- not so worried about a live web interface. and if so i normally use freeboard ( 1- 3 megs in size) i just drop it in the Luci www directory and it up an running with very easy web configuration for IOT devices ... or I can install node-red and then node dashboard ( big +20 megs) for that. also easy web configuration.

the RRD container is just for simple historic values saved on the router ( bananapi R1 - with a large SSD so space it not really my concern). I also have it set up to automatically send all data to influxdb but that requires a remote server.. all my live data streams for visualization are handled by esp8266 connected to 2.8 - 9" tft lcd screen that render the data directly that way. basically looks like a digital picture screen sitting on a desk or the wall dedicated to displaying your data live all the time any where in the world.

https://community.openenergymonitor.org/t/a-howto-install-freeboard-with-mqtt-for-emontx-shield/ of freeboard in action from a previous incarnation of my energy monitor using bananian as the core if you were curious -- but now I am moving away from that..

Hm, data models for luci-statistics can return multiple items and there is nothing actively preventing rendering of multiple diagrams from the same source. Can you share the the Lua code you use so far and maybe a *.rrd file for experimentation?

thank -you Jow for the response -

I think i figured out how to insert multiple graphs. i was doing its sorting from multiple "if" statement to sort the differing graphs ( but that only works for differing plugin_incidences), but I see if you have to place all similar incidences with in the one "if" statement then it will work-- it seams that if you have similar if statement it just ignores the the next one --

module("luci.statistics.rrdtool.definitions.exec", package.seeall)

function rrdargs(graph, plugin, plugin_instance)
    -- For $HOSTNAME/exec-foo-bar/temperature_baz-quux.rrd, plugin will be
    -- "exec" and plugin_instance will be "foo-bar".  I guess graph will be
    -- "baz-quux"?  We may also be ignoring a fourth argument, dtype.
if "Energy" == plugin_instance then
        --
        -- Energy diagram
        --
        local energy = {

                -- draw this diagram for each plugin instance
                per_instance = true,
                title = "%H: Energy Production and Consumption--%di",
                vlabel = "watts",

                -- diagram data description
                data = {
                        -- defined sources for data types, if ommitted assume a single DS named "value" (optional)
                        sources = {
                                power = { "value" }
                        },

                        -- special options for single data lines
                        options = {
                                power__value = {
                                --        total = true,           -- report total amount 
                               --         color = "0000ff",       -- rx is blue
                                     --  noarea = true,
                                   --    overlay = true,
                                       title = "%di"
                                 --    title = "Energy Production"
                                }
                        }
                }
        }

local test ={
                title = "%H: Compare",
                y_min = "0",
                alt_autoscale_max = true,
                vlabel = "watts",
               -- number_format = "%5.1lf%%",
                data = {
                        instances = {
                                power = { "grid", "wind" }
                        },

                        options = {
                                power_grid      = { color = "ffffff", title = "Grid" },
                                power_wind      = { color = "00e000", title = "wind" }
                        }
                  }


}



 return { energy, test }
end

if "Temp" == plugin_instance then

 --
        -- Temperature diagram
        --
        local temp = {

                -- draw this diagram for each plugin instance
          --      per_instance = true,
                title = "%H: Temperature %di",
                vlabel = "celsius",

                -- diagram data description
                data = {
                        -- defined sources for data types, if ommitted assume a single DS named "value" (optional)
                        sources = {
                                temperature = { "value" }
                        },

                        -- special options for single data lines
                        options = {
                                power__value = {
                                --        total = true,           -- report total amount
                               --         color = "0000ff",       -- rx is blue
                                       noarea = true,
                                       overlay = true,
                                       title = "%di"
                                 --    title = "Energy Production"
                                }
                        }
                }
        }



 return { temp }


end

if "Energy" == plugin_instance then
 return {
                title = "%H: Compare",
                y_min = "0",
                alt_autoscale_max = true,
                vlabel = "watts",
               -- number_format = "%5.1lf%%",
                data = {
                        instances = {
                                power = { "grid", "wind" }
                        },

                        options = {
                                cpu_grid      = { color = "ffffff", title = "Grid" },
                                cpu_wind      = { color = "00e000", title = "wind" }
                        }
                  }
        }
end



end

Screenshot_20180313_223533

though the name is not displayed correctly for some reason

In the compare graph, try power_grid_value and power_wind_value instead of power_grid and power_wind as keys in the options table.

thank you kindly that did the trick, was wondering, is there any way to change the colour of the two top graphs to be independent of each other , so there is a an easy visual division created automatically or will it be always force to the default colour of blue for power

one other question is there a way to incorporate
CDEF:kWh=kw,1,/,24,*
GPRINT:kWh:AVERAGE:" total %6.2lfkWh\

to give a good accurate total for kwh or perhaps dividing the total "total = true " by 3600 would give the number i require

(kw would be the "value" and 24 would be number hours)

In the energy graph definition, add the following to the options table:

options = {
    power_grid_value = {
        title = "Grid power",
        color = "00ff00" -- green
    },
    power_wind_value = {
        title = "Wind power",
        color = "0000ff" -- blue
    }
}

I need to look that up, I believe right now you cannot inject raw rrdtool commands from the graph definitions. Will check

Thank you kindly once again -- that means for each additional "node" I have to add in it own specific colour statement, okay I can work with that..

by the way just tried it does not seam to work. if I enable per_instance = true, I get two graphs at the default colour and if I disable it I get one single graph with two different colours

ie:test2

but I will keep playing around and see if I can figure it out

hi jow - as to generating the proper kwh total for power. i would assume you have a cgi for rrd graph generation similar to say web-collectd example below

    power => ['-v', 'Watt',
    'DEF:avg={file}:value:AVERAGE',
    'DEF:min={file}:value:MIN',
    'DEF:max={file}:value:MAX',
    "AREA:max#$HalfBlue",
    "AREA:min#$Canvas",
    "LINE1:avg#$FullBlue:Watt",
    'GPRINT:min:MIN:%5.1lf%sW Min,',
    'GPRINT:avg:AVERAGE:%5.1lf%sW Avg,',
    'GPRINT:max:MAX:%5.1lf%sW Max,',
    'GPRINT:avg:LAST:%5.1lf%sW Last\l'
    ],

perhaps

 CDEF:kWh=value,3600,*
  GPRINT:kWh:AVERAGE:" total %6.2lfkWh\

I believe that should give the the kwh rating , but i do not know how you would be able to call it in rrd definitions afterwards ..

@sash99

Interesting project. Do you have any other info available related to Energy monitoring and OpenWRT?

BR/Phil...

sure what would you like to know, the projects more then just energy monitoring, it a complete environmental monitoring, all based on esp8266 and MQTT. Energy monitoring is just one aspect of a broader picture

-Energy Monitoring - Grid usage, alternative energy production( solar,wind, evacuated solar tubes , heat pumps ..etc)
Environmental monitoring ( temperature, humidity, irradiance, pressure ..etc)

openwrt is just the back end to simplify everything . the Bananpi R1 or R2 are powerful little router platforms. why have a whole bunch of devices when i can lean it down to one device . but i am sure it will operates on many modern routers that will support openwrt. because currently my cpu usage is barely 0.5 % when operating at idle and with alot of network load 3%

There's two approaches I can think of right now; one is declaring an rrdopts = { ... } array to pass raw arguments directly to rrdtool, the other is using transform_rpn on the datasource and number_format on the graph to calculate the value, like that:

local energy = {
  -- draw this diagram for each plugin instance
  per_instance = true,
  title = "%H: Energy Production and Consumption--%di",
  vlabel = "watts",
  number_format = "%6.2lfkWh",

  -- diagram data description
  data = {
    -- special options for single data lines
    options = {
      power_grid_value = {
        title = "Grid power",
        color = "00ff00", -- green
        transform_rpn = "1,/,24,*"
      },
      power_wind_value = {
        title = "Wind power",
        color = "0000ff", -- blue
        transform_rpn = "1,/,24,*"
      }
    }
  }
}

But thats all from memory, I'd need to play around for myself a little bit to see how it could be best solved. Could you provide me with your *.rrd file by any chance?

sure here a copy of the rrd for wind and energy i placed it in this github directory

I give this a a try above later have go out today on a call

good afternoon jow

well that sort of works but it transforms the min, avg, max which is not necessary they display correctly. it the total that displays incorrectly they display a 6.5 million watt seconds we need to divide that number by 3600 and then that will give us 1800 Wh or 1.8kWh.. is there a way to transform the out put of the total only as that had no effect on the total it still displayed 6.5mWs

@sash99

Thanks for the info. My interest comes from the Telecom sector, specifically TowerCo's where we provide tower and power to operators. Accurate energy monitoring is crucial. Current solutions duplicate HW, processing power and are not so robust, relying on sensors, modbus, multiple interfaces, SNMP etc