From 9dc2283d21332edaf800553619f452773ef9e0e5 Mon Sep 17 00:00:00 2001 From: Egor Vasilyev Date: Thu, 28 Apr 2022 16:42:07 +0300 Subject: [PATCH] #4: component entities moved from metric name into label set (#5) component entities moved from metrics names into label set --- README.md | 24 ++++++++++++++---------- handler.py | 2 +- prometheus/rules.yaml | 6 +++--- tests/test_handler.py | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 9627d14..f981156 100644 --- a/README.md +++ b/README.md @@ -62,16 +62,20 @@ You may pass options both via command line arguments or environment variables: Metrics example: ```text -gradle_ingest_queue_pending{url="http://localhost:8081"} 0 -gradle_ingest_queue_requested{url="http://localhost:8081"} 0 -gradle_ingest_queue_ageMins{url="http://localhost:8081"} 0 -gradle_ingest_queue_requestWaitTimeSecs{url="http://localhost:8081"} 0 -gradle_ingest_queue_incomingRate1m{url="http://localhost:8081"} 0.03221981766544038 -gradle_ingest_queue_incomingRate5m{url="http://localhost:8081"} 0.02219163413405735 -gradle_ingest_queue_incomingRate15m{url="http://localhost:8081"} 0.021373141599789678 -gradle_ingest_queue_processingRate1m{url="http://localhost:8081"} 0.03399783025186821 -gradle_ingest_queue_processingRate5m{url="http://localhost:8081"} 0.022374841163558885 -gradle_ingest_queue_processingRate15m{url="http://localhost:8081"} 0.021459615070953553 +gradle_ingest_queue{entity="pending",url="http://localhost:8081/info/ingest-queue"} 0 +gradle_ingest_queue{entity="requested",url="http://localhost:8081/info/ingest-queue"} 0 +gradle_ingest_queue{entity="ageMins",url="http://localhost:8081/info/ingest-queue"} 0 +gradle_ingest_queue{entity="requestWaitTimeSecs",url="http://localhost:8081/info/ingest-queue"} 0 +gradle_ingest_queue{entity="incomingRate1m",url="http://localhost:8081/info/ingest-queue"} 0 +gradle_ingest_queue{entity="incomingRate5m",url="http://localhost:8081/info/ingest-queue"} 0 +gradle_ingest_queue{entity="incomingRate15m",url="http://localhost:8081/info/ingest-queue"} 0 +gradle_ingest_queue{entity="processingRate1m",url="http://localhost:8081/info/ingest-queue"} 0 +gradle_ingest_queue{entity="processingRate5m",url="http://localhost:8081/info/ingest-queue"} 0 +gradle_ingest_queue{entity="processingRate15m",url="http://localhost:8081/info/ingest-queue"} 0 +gradle_ready{entity="build_cache_node",url="http://localhost:8081/ready"} 1 +gradle_ready{entity="test_distribution",url="http://localhost:8081/ready"} 1 +gradle_ready{entity="enterprise_app",url="http://localhost:8081/ready"} 1 +gradle_ready{entity="keycloak",url="http://localhost:8081/ready"} 1 ``` diff --git a/handler.py b/handler.py index fe85785..c758ae8 100644 --- a/handler.py +++ b/handler.py @@ -65,7 +65,7 @@ def generate_metrics(json_data, url): for k, v in json_data.items(): # convert bool values into 0/1 representation to put into metric value v = 1 if re.search('true', str(v), re.IGNORECASE) else 0 - metrics_str += f'gradle_{last_item}_{k}{{url="{url}"}} {v}\n' + metrics_str += f'gradle_{last_item}{{entity="{k}",url="{url}"}} {v}\n' return metrics_str diff --git a/prometheus/rules.yaml b/prometheus/rules.yaml index 6a4358c..def1455 100644 --- a/prometheus/rules.yaml +++ b/prometheus/rules.yaml @@ -2,7 +2,7 @@ groups: - name: gradle-server-exporter rules: - alert: GradlePendingRequests - expr: gradle_ingest_queue_pending > 1000 + expr: gradle_ingest_queue{entity="pending} > 1000 for: 10m labels: severity: warning @@ -10,10 +10,10 @@ groups: summary: More than 1000 ({{$value}}) pending requests in the queue - alert: GradleComponentReady - expr: count({__name__=~"gradle_ready_.*"} == 0) by(url) + expr: gradle_ready == 0 for: 10m labels: severity: critical annotations: - summary: "{{$value}}% component(s) of Gradle server is(are) not in ready state" + summary: "{{$labels.entity}}% component is not in ready state" runbook: Check {{$labels.url}} for more details diff --git a/tests/test_handler.py b/tests/test_handler.py index 99d4590..6376b87 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -120,7 +120,7 @@ def test_generate_metrics(): } result = generate_metrics(json_data=json_data, url=fake_url_str) - assert result == f'gradle_ingest_queue_pending{{url="{fake_url_str}"}} 0\ngradle_ingest_queue_requested{{url="{fake_url_str}"}} 0\n' + assert result == f'gradle_ingest_queue{{entity="pending",url="{fake_url_str}"}} 0\ngradle_ingest_queue{{entity="requested",url="{fake_url_str}"}} 0\n' json_data = json.loads('{}') result = generate_metrics(json_data=json_data,