Thats what i tried:
*g = GaugeMetricFamily("cardTemperature", "Temperature of the installed
card", labels=["card"])*
*class TL1Collector(object):*
* def __init__(self, endpoint):*
* self._endpoint = endpoint*
* def collect(self):*
* g.add_metric(self._endpoint, 2)*
* yield g*
*@app.route("/temperature")*
*def handle_get():*
* if "target" in request.args:*
* target = request.args.get('target')*
* REGISTRY.register(TL1Collector(target))*
* return generate_latest(REGISTRY)*
* else:*
* return "Error: No target field provided. Please specify target.*"
I'm probably wrong the line "*REGISTRY.register(TL1Collector(target))"
*because
i register the collector every time i call the endpoint and it is already
registered from the http call before that one.
But i don't know where to register the custom collector to prevent that,
because i need the target variable to be passed through.
If i only trigger it once at the start with a boolean it works serveral
times and i dont get that error anymore but in only adds another metric to
the output an keeps the old data from a different target parameter aswell.
[email protected] schrieb am Dienstag, 22. September 2020 um 11:31:43 UTC+2:
> You probably need to use the Custom Collector. This is similar to the
> "Const" metrics in the Go code.
>
> https://github.com/prometheus/client_python#custom-collectors
>
> On Tue, Sep 22, 2020 at 11:03 AM Sebastian Halter <[email protected]>
> wrote:
>
>> Hello everyone,
>>
>> i am trying to collect some data via TL1 (basically telnet) because the
>> manufacturer doesn't provide the temperature of the installed cards via
>> SNMP.
>>
>> I would like to recreate something like the SNMP-Exporter where i can
>> specify my target in the URL it scrapes. Currently i am facing the issue,
>> that my exporter runs once and then it runs into an error on every other
>> request ("ValueError: Duplicated timeseriers in CollectorRegistry").
>>
>> Does anyone have a basic example of a multi-target python exporter?
>> I found in the documentation that python, go und java are the only client
>> libraries that supports this approch but couldn't find any example of this
>> on the python-client github site.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Prometheus Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/prometheus-users/2f7dd7e7-ac2e-4cee-8f55-68390051efd9n%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/prometheus-users/2f7dd7e7-ac2e-4cee-8f55-68390051efd9n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/prometheus-users/f2fa5473-3fdd-408f-9089-0e75d927207an%40googlegroups.com.