Rudziankoŭ
Rudziankoŭ

Reputation: 11251

Send custom data to Prometheus

I am new to Prometheus and I would like to send some custom metrics to Prometheus. I am using this client lib.

from prometheus_client import make_wsgi_app
from wsgiref.simple_server import make_server

def prometheus_config():
    app = make_wsgi_app()
    httpd = make_server('', 1618, app)
    httpd.serve_forever()


def start_prometheus_server():
    threading.Thread(target=prometheus_config).start()enter code here

I have started service for Prometheus.

  1. How could I now up /custom endpoint?
  2. How can I send there my custom data?

Upvotes: 1

Views: 3044

Answers (1)

Rudziankoŭ
Rudziankoŭ

Reputation: 11251

Register in registry custom collector class:

class CustomCollector(object):
    def collect(self):
        yield GaugeMetricFamily('my_gauge', 'Help text', value=7)
        c = CounterMetricFamily('my_counter_total', 'Help text', labels=['foo'])
        c.add_metric(['bar'], 1.7)
        c.add_metric(['baz'], 3.8)
        yield c

REGISTRY.register(CustomCollector())

Then use this registry when start the server:

app = make_wsgi_app(REGISTRY)
httpd = make_server('', 1618, app)

Upvotes: 2

Related Questions