Skip to content

Commit d499b5c

Browse files
adds active connections
Signed-off-by: Elena Kolevska <elena@kolevska.com>
1 parent 3c4a283 commit d499b5c

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

metrics.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ def _setup_opentelemetry(self):
132132
unit="1"
133133
)
134134

135+
self.otel_active_connections = self.meter.create_gauge(
136+
name="redis_active_connections",
137+
description="Number of active Redis connections",
138+
unit="1"
139+
)
140+
135141

136142

137143
# Note: Using manual instrumentation instead of automatic Redis instrumentation
@@ -290,11 +296,24 @@ def record_reconnection(self, duration: float):
290296

291297
def update_active_connections(self, count: int):
292298
"""Update active connections count."""
293-
# Update OpenTelemetry metrics
299+
# Update OpenTelemetry metrics with proper labels
294300
if self.enable_otel and hasattr(self, 'otel_active_connections'):
295-
self.otel_active_connections.add(count)
301+
labels = {
302+
"app_name": self.app_name,
303+
"instance_id": self.instance_id,
304+
"version": self.version
305+
}
306+
# Use set() for gauge metrics, not add()
307+
self.otel_active_connections.set(count, labels)
296308

297-
# Active connections tracked via OpenTelemetry only
309+
# Update Prometheus metrics with app identification
310+
if self.enable_prometheus and hasattr(self, 'prom_active_connections'):
311+
labels = {
312+
'app_name': self.app_name,
313+
'service_name': self.service_name,
314+
'instance_id': self.instance_id
315+
}
316+
self.prom_active_connections.labels(**labels).set(count)
298317

299318

300319

observability/grafana/provisioning/dashboards/redis-test-dashboard.json

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,68 @@
320320
"pluginVersion": "8.0.0",
321321
"targets": [
322322
{
323-
"expr": "redis_active_connections",
323+
"expr": "redis_connections_total{app_name=~\"$app_name\"}",
324324
"interval": "",
325-
"legendFormat": "Active Connections",
325+
"legendFormat": "{{app_name}} - {{instance_id}}",
326326
"refId": "A"
327327
}
328328
],
329329
"title": "Active Connections",
330330
"type": "stat"
331331
},
332+
{
333+
"datasource": "Prometheus",
334+
"fieldConfig": {
335+
"defaults": {
336+
"color": {
337+
"mode": "palette-classic"
338+
},
339+
"custom": {
340+
"hideFrom": {
341+
"legend": false,
342+
"tooltip": false,
343+
"vis": false
344+
}
345+
},
346+
"mappings": []
347+
},
348+
"overrides": []
349+
},
350+
"gridPos": {
351+
"h": 8,
352+
"w": 12,
353+
"x": 12,
354+
"y": 0
355+
},
356+
"id": 15,
357+
"options": {
358+
"legend": {
359+
"displayMode": "visible",
360+
"placement": "bottom"
361+
},
362+
"pieType": "pie",
363+
"reduceOptions": {
364+
"values": false,
365+
"calcs": [
366+
"lastNotNull"
367+
],
368+
"fields": ""
369+
},
370+
"tooltip": {
371+
"mode": "single"
372+
}
373+
},
374+
"targets": [
375+
{
376+
"expr": "increase(redis_connections_total{app_name=~\"$app_name\"}[5m])",
377+
"interval": "",
378+
"legendFormat": "{{app_name}} - {{status}}",
379+
"refId": "A"
380+
}
381+
],
382+
"title": "Connection Attempts (5m)",
383+
"type": "piechart"
384+
},
332385
{
333386
"datasource": "Prometheus",
334387
"fieldConfig": {

0 commit comments

Comments
 (0)