INNER CODE UNIT · Python

push

VersusControl/versus-incident · scripts/generate_fake_metrics.py:185

def push(base: str, job: str, body: str) -> None:
    """PUT the full exposition to the pushgateway group (replaces the group).

    Using PUT (not POST) means each push fully replaces the job's metrics, so
    the cumulative counters we send are exactly what Prometheus scrapes. The
    pushgateway must be scraped with `honor_labels: true` so the `service` /
    `code` / `le` labels in the body are preserved.
    """
    req = urllib.request.Request(
        pushgateway_url(base, job),
        data=body.encode("utf-8"),
        method="PUT",
        headers={"Content-Type": "text/plain; version=0.0.4"},
    )
    with urllib.request.urlopen(req, timeout=10) as resp:
        if resp.status >= 300:
            raise RuntimeError("pushgateway returned %d" % resp.status)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…