fix(ops): alert on stale gitea actions jobs
Some checks failed
CD Pipeline / tests (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
Code Review / ai-code-review (push) Has been cancelled
Deploy Alert Rules / Deploy Prometheus Alert Rules (push) Has been cancelled
Some checks failed
CD Pipeline / tests (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
Code Review / ai-code-review (push) Has been cancelled
Deploy Alert Rules / Deploy Prometheus Alert Rules (push) Has been cancelled
This commit is contained in:
@@ -15,6 +15,7 @@ import os
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@@ -67,6 +68,17 @@ def _memory_bytes(value: str) -> float:
|
||||
return float(number) * scale
|
||||
|
||||
|
||||
def _started_at_seconds(value: str) -> float:
|
||||
if not value:
|
||||
return 0.0
|
||||
try:
|
||||
normalized = re.sub(r"\.(\d{6})\d+(Z|[+-]\d\d:\d\d)$", r".\1\2", value)
|
||||
normalized = normalized.replace("Z", "+00:00")
|
||||
return datetime.fromisoformat(normalized).astimezone(timezone.utc).timestamp()
|
||||
except ValueError:
|
||||
return 0.0
|
||||
|
||||
|
||||
def collect() -> str:
|
||||
stats = _run_json_lines([
|
||||
"docker",
|
||||
@@ -102,6 +114,8 @@ def collect() -> str:
|
||||
"# TYPE docker_container_inspect_restart_count gauge",
|
||||
"# HELP docker_container_info Docker container inventory exposed by the textfile exporter.",
|
||||
"# TYPE docker_container_info gauge",
|
||||
"# HELP docker_container_started_seconds Docker container start timestamp from Docker inspect.",
|
||||
"# TYPE docker_container_started_seconds gauge",
|
||||
]
|
||||
|
||||
for row in stats:
|
||||
@@ -114,6 +128,7 @@ def collect() -> str:
|
||||
nano_cpus = float(host_config.get("NanoCpus") or 0)
|
||||
memory_limit = float(host_config.get("Memory") or 0)
|
||||
restart_count = int(inspected.get("RestartCount") or 0)
|
||||
started_seconds = _started_at_seconds(state.get("StartedAt", ""))
|
||||
labels = f'host="{_escape_label(HOST_LABEL)}",container_name="{_escape_label(name)}"'
|
||||
mem_current = (row.get("MemUsage") or "0 B / 0 B").split("/", 1)[0].strip()
|
||||
pids = row.get("PIDs") or "0"
|
||||
@@ -123,6 +138,7 @@ def collect() -> str:
|
||||
lines.append(f"docker_container_memory_limit_bytes{{{labels}}} {memory_limit:.0f}")
|
||||
lines.append(f"docker_container_pids{{{labels}}} {int(float(pids))}")
|
||||
lines.append(f"docker_container_inspect_restart_count{{{labels}}} {restart_count}")
|
||||
lines.append(f"docker_container_started_seconds{{{labels}}} {started_seconds:.6f}")
|
||||
lines.append(
|
||||
f'docker_container_info{{{labels},status="{_escape_label(state.get("Status", ""))}"}} 1'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user