Duplicated timeseries in custom exporter

1,201 views
Skip to first unread message

sung...@gmail.com

unread,
Sep 8, 2018, 8:01:10 AM9/8/18
to Prometheus Developers
I have written a custom exporter to parse json output of target urls.

from prometheus_client import start_http_server, Metric, generate_latest, Summary
from prometheus_client.core import SummaryMetricFamily, GaugeMetricFamily, CounterMetricFamily, REGISTRY
import json
import requests
import sys
import time
import flask
from flask import request, jsonify

app = flask.Flask(__name__)
app.config["DEBUG"] = True

class JsonCollector(object):
def __init__(self, endpoint):
self._endpoint = endpoint
def collect(self):
# Fetch the JSON
flag=0
print self._endpoint
response = json.loads(requests.get(self._endpoint).content.decode('UTF-8'))
print response
if(response['status']=='Running'):
flag=1
metric = Metric('status','Flag value is 1 if status is success','summary')
metric.add_sample('status',value=flag, labels={})
yield metric

@app.route('/probe', methods=['GET'])
def api_url():
if 'target' in request.args:
url = request.args['target']
REGISTRY.register(JsonCollector(url))
data=generate_latest(REGISTRY)
return data
else:
return "Error: No target field provided. Please specify target."

app.run(host='0.0.0.0')

Issue:
ValueError: Duplicated timeseries in CollectorRegistry: set([u'status', u'status_sum', u'status_count'])

Brian Brazil

unread,
Sep 8, 2018, 12:06:13 PM9/8/18
to sung...@gmail.com, Prometheus Developers
You only need to call this once, not on every request.

Brian
 
        data=generate_latest(REGISTRY)
        return data
    else:
        return "Error: No target field provided. Please specify target."

app.run(host='0.0.0.0')



Issue:
ValueError: Duplicated timeseries in CollectorRegistry: set([u'status', u'status_sum', u'status_count'])

--
You received this message because you are subscribed to the Google Groups "Prometheus Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-developers+unsub...@googlegroups.com.
To post to this group, send email to prometheus-developers@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-developers/7519f9d4-82ff-44a6-acab-06de2ce564e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

sung...@gmail.com

unread,
Sep 8, 2018, 9:12:29 PM9/8/18
to Prometheus Developers
I call the exporter on every 15s and send an array of target urls. Can you expand your answer?
> To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-devel...@googlegroups.com.
>
> To post to this group, send email to prometheus...@googlegroups.com.

Claudio Saavedra

unread,
Apr 24, 2020, 10:44:24 AM4/24/20
to Prometheus Developers
Hello,
could you solve the probelm?
I have a similar error.
Thanks.
> To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-developers+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages