Skip to content

Commit

Permalink
Merge pull request #12 from darox/fix-metrics
Browse files Browse the repository at this point in the history
Prometheus: Fix metrics in dashboard and code
  • Loading branch information
darox authored Nov 29, 2023
2 parents 71d6917 + 37e5bfb commit 9da0ec0
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 38 deletions.
Binary file modified assets/grafana.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
215 changes: 180 additions & 35 deletions dashboard/twampy.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"description": "Upper values is loss and second value is average latency in ms.",
"gridPos": {
"h": 13,
"h": 16,
"w": 18,
"x": 0,
"y": 1
Expand All @@ -65,7 +65,7 @@
},
"editorMode": "code",
"exemplar": false,
"expr": "twampy_latency_avg_edge",
"expr": "twampy_edge",
"format": "table",
"instant": true,
"interval": "",
Expand Down Expand Up @@ -103,13 +103,14 @@
"color": {
"mode": "thresholds"
},
"decimals": 0,
"mappings": [],
"noValue": "0",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "super-light-blue",
"color": "green",
"value": null
}
]
Expand All @@ -119,7 +120,7 @@
"overrides": []
},
"gridPos": {
"h": 6,
"h": 4,
"w": 6,
"x": 18,
"y": 1
Expand All @@ -128,16 +129,16 @@
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"justifyMode": "center",
"orientation": "horizontal",
"reduceOptions": {
"calcs": [
"last"
"lastNotNull"
],
"fields": "",
"values": false
},
"textMode": "value_and_name"
"textMode": "value"
},
"pluginVersion": "10.1.5",
"targets": [
Expand All @@ -148,55 +149,199 @@
},
"editorMode": "code",
"exemplar": false,
"expr": "sum_over_time(twampy_result{twampy_result=\"ok\"}[$__range])",
"expr": "sum(increase(twampy_result_total{result=\"ok\"}[$__range]))",
"format": "table",
"instant": true,
"legendFormat": "ok",
"range": false,
"instant": false,
"legendFormat": "__auto",
"range": true,
"refId": "A"
}
],
"title": "Successul Measurements",
"transformations": [
{
"id": "renameByRegex",
"options": {
"regex": "Value #B",
"renamePattern": "err"
}
}
],
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"decimals": 0,
"mappings": [],
"noValue": "0",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
}
]
},
"unit": "none"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 18,
"y": 5
},
"id": 19,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"orientation": "horizontal",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"textMode": "value"
},
"pluginVersion": "10.1.5",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"editorMode": "code",
"exemplar": false,
"expr": "sum_over_time(twampy_result{twampy_result=\"err\"}[$__range])",
"expr": "sum(increase(twampy_result_total{result=\"err\"}[$__range]))",
"format": "table",
"hide": false,
"instant": true,
"legendFormat": "err",
"range": false,
"refId": "B"
"instant": false,
"legendFormat": "__auto",
"range": true,
"refId": "A"
}
],
"title": "Measurement Results",
"title": "Failed Measurements",
"transformations": [
{
"id": "renameByRegex",
"options": {
"regex": "Value #A",
"renamePattern": "ok"
"regex": "Value #B",
"renamePattern": "err"
}
}
],
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"custom": {
"align": "auto",
"cellOptions": {
"type": "auto"
},
"inspect": false
},
"decimals": 0,
"mappings": [],
"noValue": "0",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
}
]
},
"unit": "none"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 6,
"x": 18,
"y": 9
},
"id": 20,
"options": {
"cellHeight": "sm",
"footer": {
"countRows": false,
"fields": "",
"reducer": [
"sum"
],
"show": false
},
"showHeader": true
},
"pluginVersion": "10.1.5",
"targets": [
{
"id": "renameByRegex",
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"editorMode": "code",
"exemplar": false,
"expr": "increase(twampy_result_total{result=\"err\"}[$__range]) > 0",
"format": "table",
"instant": false,
"legendFormat": "__auto",
"range": true,
"refId": "A"
}
],
"title": " Last Unsuccessful Measurements",
"transformations": [
{
"id": "organize",
"options": {
"regex": "Value #B",
"renamePattern": "err"
"excludeByName": {
"Value": true,
"container": true,
"endpoint": true,
"job": true,
"source": true
},
"indexByName": {},
"renameByName": {
"instance": "Node"
}
}
}
],
"type": "stat"
"type": "table"
},
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 14
"y": 17
},
"id": 6,
"panels": [],
Expand Down Expand Up @@ -224,10 +369,10 @@
"overrides": []
},
"gridPos": {
"h": 8,
"h": 11,
"w": 6,
"x": 0,
"y": 15
"y": 18
},
"id": 15,
"options": {
Expand Down Expand Up @@ -307,10 +452,10 @@
"overrides": []
},
"gridPos": {
"h": 8,
"h": 11,
"w": 6,
"x": 6,
"y": 15
"y": 18
},
"id": 16,
"options": {
Expand Down Expand Up @@ -390,10 +535,10 @@
"overrides": []
},
"gridPos": {
"h": 8,
"h": 11,
"w": 6,
"x": 12,
"y": 15
"y": 18
},
"id": 17,
"options": {
Expand Down Expand Up @@ -473,10 +618,10 @@
"overrides": []
},
"gridPos": {
"h": 8,
"h": 11,
"w": 6,
"x": 18,
"y": 15
"y": 18
},
"id": 18,
"options": {
Expand Down Expand Up @@ -544,13 +689,13 @@
"list": []
},
"time": {
"from": "now-30m",
"from": "now-1h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Twampy",
"uid": "ed1ae615-c347-43ef-8448-e907209c5f81",
"version": 13,
"version": 18,
"weekStart": ""
}
7 changes: 4 additions & 3 deletions twampy.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
import signal
import select
import json
from prometheus_client import start_http_server, Histogram, Gauge, Enum
from prometheus_client import start_http_server, Gauge, Counter

#############################################################################

Expand Down Expand Up @@ -310,14 +310,15 @@ def update_metrics(self, total):
SenderJitter.labels('inbound').set(round(self.jitterIB,2))
SenderJitter.labels('roundtrip').set(round(self.jitterRT,2))

SenderResult.state('ok')
SenderResult.labels('ok').inc(1)

if args.nodegraph:
avgLatency = round(self.sumRT / self.count, 2)
loss = round(100 * float(self.lossRT) / self.count, 2)
SenderEdge.labels("{0}-{1}".format(hostname, sip), hostname, sip, loss, avgLatency).set(1)
else:
SenderEdge.labels("{0}-{1}".format(hostname, sip), hostname, sip, -1, -1).set(0)
SenderResult.labels('err').inc(1)


def dump(self, total):
Expand Down Expand Up @@ -882,7 +883,7 @@ def dscpTable():
SenderLatencyMax = Gauge('twampy_latency_max', 'TWAMP max latency in ms', ['direction'])
SenderJitter = Gauge('twampy_jitter', 'TWAMP jitter in ms', ['direction'])
SenderLoss = Gauge('twampy_loss', 'TWAMP loss in percent', ['direction'])
SenderResult = Enum('twampy_result', 'TWAMP result', states=['ok', 'error'])
SenderResult = Counter('twampy_result', 'If the measurement has succedded or not', ['result'])


start_http_server(port)
Expand Down

0 comments on commit 9da0ec0

Please sign in to comment.