Skip to content

Commit

Permalink
chore: prefix metrics (#2889)
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren authored Dec 24, 2024
1 parent 3396be8 commit 4f769f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions keep/api/core/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,45 @@
PROMETHEUS_MULTIPROC_DIR = os.environ.get("PROMETHEUS_MULTIPROC_DIR", "/tmp/prometheus")
os.makedirs(PROMETHEUS_MULTIPROC_DIR, exist_ok=True)

METRIC_PREFIX = "keep_"

# Create a single registry for all metrics
registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry, path=PROMETHEUS_MULTIPROC_DIR)

# Process event metrics
events_in_counter = Counter(
"events_in_total", "Total number of events received", registry=registry
f"{METRIC_PREFIX}events_in_total",
"Total number of events received",
registry=registry,
)
events_out_counter = Counter(
"events_out_total", "Total number of events processed", registry=registry
f"{METRIC_PREFIX}events_processed_total",
"Total number of events processed",
registry=registry,
)
events_error_counter = Counter(
"events_error_total", "Total number of events with error", registry=registry
f"{METRIC_PREFIX}events_error_total",
"Total number of events with error",
registry=registry,
)
processing_time_summary = Summary(
"processing_time_seconds", "Average time spent processing events", registry=registry
f"{METRIC_PREFIX}processing_time_seconds",
"Average time spent processing events",
registry=registry,
)

# Running tasks metrics
running_tasks_gauge = Gauge(
"running_tasks_current",
f"{METRIC_PREFIX}running_tasks_current",
"Current number of running tasks",
registry=registry,
multiprocess_mode="livesum",
)

# Per-process running tasks metrics
running_tasks_by_process_gauge = Gauge(
"running_tasks_by_process",
f"{METRIC_PREFIX}running_tasks_by_process",
"Current number of running tasks per process",
labelnames=["pid"],
registry=registry,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "keep"
version = "0.32.6"
version = "0.32.7"
description = "Alerting. for developers, by developers."
authors = ["Keep Alerting LTD"]
packages = [{include = "keep"}]
Expand Down

0 comments on commit 4f769f0

Please sign in to comment.