Skip to content

push_to_gateway function uses PUT method, which is rejected by WSGI server #1072

Closed
@mallika-mur

Description

@mallika-mur

Hello, I'm still a newbie, so maybe I am misinterpreting something, but it appears as if there's an issue with the push_to_gateway() function defined in exposition.py.

Since v0.21 has been released, I cannot get my custom collector to expose its metrics over HTTP. It appears that even though the WSGI server when start_http_server() only supports OPTION and GET as methods, push_to_gateway() uses PUT, which gives me a "405 Method Not Allowed" error. Since my little program runs flawlessly with v0.20, I'm inclined to believe this may be a bug.

Here's what works in v0.20:

import prometheus_client
from prometheus_client.core import GaugeMetricFamily
import requests
import time


class MyCollector(object):
    def __init__(self):
        pass

    def collect(self):
        datajson = requests.get('https://api.example.com/foo)
        rawdata = datajson.json()

        registry = prometheus_client.CollectorRegistry()
        g = GaugeMetricFamily('mymetric', 'My Gauge Metric', value=rawdata['meta']['total'])
        yield g


if __name__ == '__main__':
    prometheus_client.start_http_server(8000)
    R = prometheus_client.REGISTRY.register(MyCollector())
    while True: 
        prometheus_client.push_to_gateway('localhost:8000', job='gaugemetricvalues', registry=R)
        time.sleep(3600)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions