INNER CODE UNIT · Python

pushgateway_url

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

def pushgateway_url(base: str, job: str) -> str:
    return base.rstrip("/") + "/metrics/job/" + urllib.request.quote(job, safe="")


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"},
    )

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…