This relates to opCharts version 4 |
Each TopN table is really just a component in a dashboard, components are defined in json documents. opCharts ships the Default components in omk/lib/json/opCharts/components.d/. User defined components are loaded from omk/conf/components.d, and are loaded last so default components are overridden, if desired, by creating new versions in the User defined folder.
opCharts 4 takes several steps to generate TopN data and display it (these are different and simpler than with opCharts3). Understanding these steps will make the process of adding a new TopN table make more sense.
Below is the definition for CPU Load TopN. Note this is looking for a Statistic named cpuLoad and it looks for it in the derived_data section of the node's MongoDB database entry. This means to have this TopN work for your node there must be a PRINT line in Common-stats.nmis which returns "cpuLoad" calculated / normalised from that nodes CPU statistics. See next section for more information on calculating.
// VERSION=2.46.0 { "name": "TopN CPU Load", "tags": [ "topn" ], "ep_template_file": "charts/topn/topn_table_component", "ep_configuration_file" : "charts/topn/topn_table_component_configuration", "options": { "titleText": "TopN CPU Load", "limit" : 10, "show_element": 0, "show_sparkline": 0, "show_value": 1 }, "order": 1, "parameters": { "topn_key": "cpuLoad", "data_section": "derived_data", }, "type": "ep_template" } |
If you have written a new device model or a current model does not show in one of the current TopN categories you may need to update Common-stats.nmis to include the metrics you collect as a Normalised metric. Also, if you wanted to create a new TopN Metric you would need to make sure this new metric type appears in Common-stats.nmis
First find the name of the normalised metric from the relevant component as abive. If this is a new TopN then select a name for the new TopN metric type.
The document we saw in the previous section was fro cpuLoad. Some examples of how cpuLoad is calculated for different Models with propriertary cpu statistics are here:
Net-SNMP (hr resources MIB)
'hrsmpcpu' => [
'DEF:hrCpuLoad=$database:hrCpuLoad:MAX',
'PRINT:hrCpuLoad:AVERAGE:hrCpuLoad=%1.2lf',
'PRINT:hrCpuLoad:AVERAGE:cpuLoad=%1.2lf'
],
Some Types of Cisco Router
'cpuUtil' => [
'DEF:cpuUtil=$database:cpuUtil:AVERAGE',
'PRINT:cpuUtil:AVERAGE:cpuUtil=%1.2lf',
'PRINT:cpuUtil:AVERAGE:cpuLoad=%1.2lf',
],
or with a calculation before hand to convert some other metric style to a normalised value. This shows converting Idle CPU seconds into a percentage busy over 5 minutes and then using that provide cpuLoad.
'CDEF:avgBusy5= 300,idleSecs,-,300/,100,*',
'PRINT:avgBusy5:AVERAGE:cpuLoad=%1.2lf',
CPU "cpuLoad", |
The easiest way to get started is to copy an existing topn component file from omk/lib/json/opCharts/components.d/topn_* into omk/conf/components.d (and rename the file).
Next open the new file and modify it to suite your new TopN data, the changes required are fairly straight forward and are outlined below:
{ "name": "TopN NEW THING", # set a new name here "tags": [ "topn" ], # leave this "ep_template_file": "charts/topn/topn_table_component", #leave this "ep_configuration_file" : "charts/topn/topn_table_component_configuration", # leave this "options": { "titleText": "TopN NEW THING", # set the component title here "limit" : 10, # set how many to show here "show_element": 0, "show_sparkline": 1 , # 0 for no sparkline, 1 for sparkline "show_value": 1, # 0 to not show the value, 1 to show the value }, "order": 1, # order the new TopN table will appear in the TopN list, see the others to get a total ordering "parameters": { "topn_key": "someNewThing", # The variable or Print statement return from Common-stats.nmis "data_section": "derived_data", # derived_data if the key comes from PRINT or data if the key comes from DEF or CDEF. }, "type": "ep_template" # leave this } |
The new TopN table should now appear in opCharts TopN page and also as an option when adding a component to a dashboard under the opCharts data source.