Skip to content

Easily expose preconfigured prometheus metrics to the outside using badges.

Notifications You must be signed in to change notification settings

kashalls/kromgo

Repository files navigation

Kromgo

A simple go project that allows you to expose prometheus metrics "safely" to a public source. Uses the official prometheus go api client. Better than exposing a grafana image rendering instance to the WWW.

It allows you to define your own metric names and your own prometheus queries as long as they return a single value at the end. There is config support to allow you to format the response with strings before and after the value.

You can use shields.io and use either the Dynamic JSON Badge or the Endpoint Badge and add dynamic coloring with ranges you set.

Config Example Configuration Structure

  • Reads configuration file from /kromgo/config.yaml
  • Requires PROMETHEUS_URL be set in ENV.
  • Optional SERVER_PORT to change server port.

Performance

Queries take around 5ms ~ 75ms to complete depending on how many breaks my prometheus server takes. This was running on my home-cluster and runs 3 instances, so depending on the query YMMV.

Example Request

Endpoint Response

This format is provided to support Shield.io's Endpoint Badge endpoint.

HTTP GET localhost:8080/node_cpu_usage

{
    "color": "green",
    "label": "node_cpu_usage",
    "message": "17.5",
    "schemaVersion": 1
}

Raw Response

HTTP GET localhost:8080/node_cpu_usage?format=raw

[
    {
        "metric": {},
        "value": [
            1702664619.78,
            "17.5"
        ]
    }
]

Badge Response

Like the endpoint format but serves an svg badge with label and message

HTTP GET localhost:8080/node_cpu_usage?format=badge

content-type: image/svg+xml
<svg xmlns="http://www.w3.org/2000/svg" ...

🤝 Gratitude and Thanks

Thanks to all of the people at the Home Operations Discord community. Be sure to check it out, its a blast!