Get Sensor Data into your Custom Panel
The following material will be easier to follow with sample code. The sample panel attached here allows a user to choose a metric to plot over time from the metrics defined in the system in the panels editor. The panels view then makes a data api call to ruban's time series database and plots the result using d3.js.
All sensor data gathered in RuBAN are accessible through the timeseries data API call which you can invoke by calling the url /api/v1/timeseriesData. Below is an example timeseries api call (just make sure you are sending the HTTP header Content-Type: application/json, otherwise it will not work):
{ "metrics": [ { "name": "36283_101", "group_by": [ { "name": "tag", "tags": [ "36283_146" ] } ], "tags": { "deviceId": ["290"]}, "aggregators": [ { "name": "avg", "align_sampling": true, "sampling": { "value": "1", "unit": "minutes" } } ] } ], "start_relative": { "value": "1", "unit": "hours" } }
An explanation of all of the fields can be found here. The documentation for the RuBAN REST API can be found here: http://dev.davranetworks.com/api/v1/index.html
The rather obscure numbers used for metric name are derived from the IPFIX enterprise numbers and element ids for the fields defined in RuBAN. For a primer on this aspect of RuBAN read /wiki/spaces/KT/pages/22085915
The above query requests the metric "RSSI" (enterpriseNumber 36283 and elementId 101) broken out by Tunnel Interface (ent. Number 36283 and element Id 146) for the deviceId 290. The data is to be aggregated into buckets of 1 minute with the average being calculated as the aggregate over data points which fall into the buckets. The data points must fall within the last hour. The result of this query looks like this:
{ "queries": [ { "sample_size": 3483, "results": [ { "name": "36283_101", "group_by": [ { "name": "tag", "tags": [ "36283_146" ], "group": { "36283_146": "dialer.0" } } ], "tags": { "36283_146": [ "dialer.0" ], "deviceId": [ "283", "284", "285", "286", "287" ] }, "values": [ [ 1443537030000, -49.5 ], [ 1443537060000, -54.03448275862069 ], [ 1443537090000, -56 ] . . . ] }, { "name": "36283_101", "group_by": [ { "name": "tag", "tags": [ "36283_146" ], "group": { "36283_146": "dialer.3" } } ], "tags": { "36283_146": [ "dialer.3" ], "deviceId": [ "283", "284", "285", "286", "287" ] }, "values": [ [ 1443537030000, -51 ], [ 1443537060000, -50.733333333333334 ], [ 1443537090000, -56.13793103448276 ], . . . ] }, { "name": "36283_101", "group_by": [ { "name": "tag", "tags": [ "36283_146" ], "group": { "36283_146": "dialer.1" } } ], "tags": { "36283_146": [ "dialer.1" ], "deviceId": [ "283", "284", "285", "286", "287" ] }, "values": [ [ 1443537030000, -71 ], [ 1443537060000, -64.1 ], [ 1443537090000, -64.58620689655173 ] . . . ] }, { "name": "36283_101", "group_by": [ { "name": "tag", "tags": [ "36283_146" ], "group": { "36283_146": "dialer.4" } } ], "tags": { "36283_146": [ "dialer.4" ], "deviceId": [ "285", "286", "287" ] }, "values": [ [ 1443537030000, -103 ], [ 1443537060000, -67.44444444444444 ], [ 1443537090000, -63 ], . . . ] } ], "labelData": { "groups": [ { "36283_146": "dialer.0" }, { "36283_146": "dialer.3" }, { "36283_146": "dialer.1" }, { "36283_146": "dialer.4" } ], "labelGroups": [ { "36283_146": { "label": "Verizon Card 1", "typeName": "Tunnel" } }, { "36283_146": { "label": "Verizon Card 2", "typeName": "Tunnel" } }, { "36283_146": { "label": "T-Mobile Card 1", "typeName": "Tunnel" } }, { "36283_146": { "label": "T-Mobile Card 2", "typeName": "Tunnel" } } ] } } ] }
Meta-Data
Some custom panels are required to present the user with a choice of metrics and group fields. In this case it would be very undesirable for users to have to choose between obscure metric enterprise ids and element ids. The meta-data api in RuBAN provides the names, descriptions units, data types etc for all fields defined on the system:
HTTP GET /eem/api/v1/metrics
{ "status": "success", "totalRecords": 21, "records": [ { "elementId": "59", "dataType": "float64", "status": "current", "description": "The speed is measured by a sensor connected to this edge device", "name": "Speed", "fdn": "5555_59", "enterpriseId": "5555", "applicability": "all", "group": "smartTransport", "units": "m/s", "dataTypeSemantics": "quantity" }, . . ] }
HTTP GET /tagmeta
{ "fields": [ { "name": "NetworkInterface", "dataType": "unsigned32", "dataTypeSemantics": "identifier", "elementId": "1", "enterpriseId": "43040", "units": "", "group": "lilee", "description": "The unique identifier of the network interface on network device. ", "tagscope": "PER_DEVICE" }, . . . ] }