Skip to content

Instantly share code, notes, and snippets.

@sergiobuj
Last active July 6, 2024 09:19
Show Gist options
  • Save sergiobuj/7d415a3341397c4b20d5c7ca9183ca05 to your computer and use it in GitHub Desktop.
Save sergiobuj/7d415a3341397c4b20d5c7ca9183ca05 to your computer and use it in GitHub Desktop.
Prom PG test setup
services:
prom:
image: prom/prometheus
ports:
- 9090:9090
volumes:
- ./prom.yml:/prom.yml
command:
- '--config.file=/prom.yml'
pushgateway:
image: prom/pushgateway
ports:
- 9091:9091
grafana:
image: grafana/grafana
ports:
- 3000:3000
environment:
- GF_SECURITY_ADMIN_PASSWORD=veryverysecure
depends_on:
- prom
#!/usr/bin/env python3
# pip install prometheus_client
from prometheus_client import (
Summary,
Counter,
push_to_gateway,
CollectorRegistry,
Gauge,
Info,
)
registry = CollectorRegistry()
request_time = Summary(
"request_processing_seconds",
"Time spent",
["animal", "color"], # Labels
registry=registry,
)
execution_counter = Counter(
"executions",
"Number of executions",
["animal", "color"], # Labels
registry=registry,
)
last_success = Gauge(
"job_last_success_unixtime",
"Last time a batch job successfully finished",
registry=registry,
)
data_type_info = Info("data_type", "Datatype for execution", registry=registry)
with request_time.labels(instance="localhost:123", color="blue", animal="fish").time():
data_type_info.info({"animal": "fish", "color": "blue"})
execution_counter.labels(instance="localhost:123", animal="fish", color="blue").inc()
last_success.set_to_current_time()
push_to_gateway("localhost:9091", job="cli_execution", registry=registry, timeout=1)
global:
evaluation_interval: 15s
scrape_interval: 15s
scrape_timeout: 15s
scrape_configs:
- job_name: scrape_pushgateway
honor_labels: true
metrics_path: /metrics
scheme: http
static_configs:
- targets: ["pushgateway:9091"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment