Skip to content

Commit

Permalink
examples: interface counter rates sum per interface list per device
Browse files Browse the repository at this point in the history
Change-Id: Ic9d2251582c4360947b5fae44d6ce3899f42a306
  • Loading branch information
noredistribution committed Nov 6, 2023
1 parent 5a25e5a commit 3e01629
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
1 change: 1 addition & 0 deletions docsrc/examples/interface_states/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Interface States Examples

.. include:: port_utilization.rst

.. include:: intf_counter_rate_sum_per_dev.rst
14 changes: 14 additions & 0 deletions docsrc/examples/interface_states/intf_counter_rate_sum_per_dev.aql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Get the 1 minute aggregate rate counters for the selected device
let data = `analytics:/Devices/<_device>/versioned-data/interfaces/data/*/aggregate/rates/1m`[_timeWindowStart:_timeWindowEnd]

# Filter out the rate counters to only contain the inOctets and outOctets key in two separate objects
let intfRatesInFiltered = data | map(_value | field("inOctets") | field("avg")) | where(dictHasKey(_interfaces, _key))
let intfRatesOutFiltered = data | map(_value | field("outOctets") | field("avg")) | where(dictHasKey(_interfaces, _key))

# Sum up the aggregates
let sumInOctets = aggregate(intfRatesInFiltered, "sum")
let sumOutOctets = aggregate(intfRatesOutFiltered, "sum")

# Add the result into a dictionary of timeseries for horizon graphs
# and divide the sum by 125000 to show the value in Mbps
newDict() | setFields(_device + " inOctets rates", sumInOctets/125000, _device + " outOctets rates", sumOutOctets/125000)
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"dashboards": [
{
"key": "a064e1b3-8158-4a3e-b7d5-5d2789eb6320",
"createdAt": [
781166221,
1581
],
"createdBy": "tamas",
"metaData": {
"schemaVersion": "3",
"legacyKey": "",
"legacyVersion": "",
"fromPackage": ""
},
"name": "Interface counters per interface list per device (aql)",
"description": "",
"widgets": [
{
"id": "c8042099-a939-4f4d-b5af-8c8bfea7b4bf",
"name": "Total In BW",
"position": {
"x": 0,
"y": 0
},
"dimensions": {
"width": 14,
"height": 13
},
"type": "aql-query-widget",
"inputs": {
"expression": "let intfRatesIn =`analytics:/Devices/<_device>/versioned-data/interfaces/data/*/aggregate/rates/1m`[_timeWindowStart:_timeWindowEnd] | map(_value | field(\"inOctets\") | field(\"avg\"))\nlet intfRatesOut =`analytics:/Devices/<_device>/versioned-data/interfaces/data/*/aggregate/rates/1m`[_timeWindowStart:_timeWindowEnd] | map(_value | field(\"outOctets\") | field(\"avg\"))\nlet intfRatesInFiltered = newDict()\nlet intfRatesOutFiltered = newDict()\nlet res = newDict()\n\nfor intfKey, intfVal in intfRatesIn{\n if dictHasKey(_interfaces, intfKey){\n intfRatesInFiltered[intfKey] = intfVal\n }\n}\n\nfor intfKey, intfVal in intfRatesOut{\n if dictHasKey(_interfaces, intfKey){\n intfRatesOutFiltered[intfKey] = intfVal\n }\n}\n\nlet sumInOctets = aggregate(intfRatesInFiltered | map(_value | resample(10s)), \"sum\")\nlet sumOutOctets = aggregate(intfRatesOutFiltered | map(_value | resample(10s)), \"sum\")\nnewDict() | setFields(_device + \" inOctets rates\", sumInOctets/125000, _device + \" outOctets rates\", sumOutOctets/125000) \n",
"graphConfig": {
"mapToHostname": true
},
"visualization": "horizonGraph"
},
"location": "main"
},
{
"id": "dfc6c06d-9588-4d50-8dc0-a4ed71cb9f26",
"name": "",
"position": {
"x": 0,
"y": 0
},
"dimensions": {
"width": 4,
"height": 2
},
"type": "input-widget",
"inputs": {
"defaultValue": "0123F2E4462997EB155B7C50EC148767",
"inputName": "device",
"inputSource": "devices",
"inputWidgetId": "dfc6c06d-9588-4d50-8dc0-a4ed71cb9f26",
"tagLabel": "device"
},
"location": "inputs"
},
{
"id": "7fd6da21-f0ab-4e02-be44-bf1068f291a4",
"name": "",
"position": {
"x": 4,
"y": 0
},
"dimensions": {
"width": 6,
"height": 2
},
"type": "variable-widget",
"inputs": {
"defaultValue": [
"Ethernet1",
"Ethernet2"
],
"inputName": "interfaces",
"inputType": "MultiSelect",
"selectData": {
"manualOptions": [
"let data ="
],
"createOptionsUsingAql": true,
"query": "let data = `analytics:/Devices/<_device>/versioned-data/interfaces/data/*`\ndata"
},
"variableType": "String"
},
"location": "inputs"
}
],
"lastUpdated": 1698367019518,
"lastUpdatedBy": "tamas"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions docsrc/examples/interface_states/intf_counter_rate_sum_per_dev.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Interface counters sum per interface list per device
-----------------------------------------------------

.. note::
Note that `aggregate()` function requires AQL revision 4+ to work.

.. literalinclude:: intf_counter_rate_sum_per_dev.aql
:language: aql

.. image:: intf_coutner_rate_sum_per_dev.png
:width: 600
:alt: Interface counters per interface list per device

:download:`Download the Dashboard JSON here <intf_counter_rate_sum_per_dev.json>`

0 comments on commit 3e01629

Please sign in to comment.