json export from prometheus

195 views
Skip to first unread message

dya...@gmail.com

unread,
Jan 14, 2017, 3:08:42 PM1/14/17
to Prometheus Users
Quick question,
Is there anyway to periodically export data from prometheus to json so I can build the status table as required? Ideally it would be the inverse of a scrape, and available via a rest type service.

Thanks,
David
  

Brian Brazil

unread,
Jan 14, 2017, 3:23:42 PM1/14/17
to dya...@gmail.com, Prometheus Users
On 14 January 2017 at 20:08, <dya...@gmail.com> wrote:
Quick question,
Is there anyway to periodically export data from prometheus to json so I can build the status table as required? Ideally it would be the inverse of a scrape, and available via a rest type service.

If there's particular data you want you can use the /query endpoint to pull it out.

If you want everything you can use the Go or Python parsers with the /federation endpoint however you may run into scaling issues as the /federation endpoint isn't intended for grabbing everything.
 
--

dya...@gmail.com

unread,
Jan 14, 2017, 4:06:54 PM1/14/17
to Prometheus Users, dya...@gmail.com


On Saturday, January 14, 2017 at 2:23:42 PM UTC-6, Brian Brazil wrote:
On 14 January 2017 at 20:08, <dya...@gmail.com> wrote:
Quick question,
Is there anyway to periodically export data from prometheus to json so I can build the status table as required? Ideally it would be the inverse of a scrape, and available via a rest type service.

If there's particular data you want you can use the /query endpoint to pull it out.

Damn, never even thought of that... it works beautifully. I was able to put the data, and push it into elasticsearch.

 
If you want everything you can use the Go or Python parsers with the /federation endpoint however you may run into scaling issues as the /federation endpoint isn't intended for grabbing everything.

Scaling isn't an issue, as there are under 25 servers for the trial. Production will not be too much larger.
 
 
--
 
Now to figure out if I can generate the table I need right out of grafana, without exporting to elasticsearch first!

Stefano Doni

unread,
Jan 15, 2017, 2:26:38 AM1/15/17
to Prometheus Users
Hi David,

I have similar needs, I have found grafana tables a bit limited.

Can you describe how did you push the data into elasticsearch?

I know how to extract out of prometheus, but I'm not familiar with elasticsearch documents format and how to best represent metrics and labels.

Thanks!

dya...@gmail.com

unread,
Jan 15, 2017, 8:47:59 AM1/15/17
to Prometheus Users
The purpose of the table is to show how a clustered application is running. In production nagios is used with a ton of custom probes. 

As part of some work to modernize the alarming, I decided to explore prometheus. Initially, building the table was a 2 step process, now it's down to one step. Unfortunately, I can't post the code as it is specific to work, written during work time, etc...

The initial process used a perl script to pull  data out of prometheus by screen scraping the metrics using PromQL. Once gathered the metrics are written to a stats.json file. A second cronjob runs after the perl script. Since the data is pulled from prometheus once every 10 minutes, there is ample time to run the second cronjob.

The second cronjob is one command: curl -XPOST 'http://yourelasticsearchhost:9200/test/test/1' -d @stats.json

After that, it was just a matter of following the grafana instructions to build the table from the json data in elasticsearch.

A new version being developed is in python, using API queries to grab the data. Once we have the data gathered, the data is converted to json, and POSTed into elasticsearch. As the python code is finished, it will be daemonized. No more cronjobs.

Stefano Doni

unread,
Jan 15, 2017, 9:53:50 AM1/15/17
to dya...@gmail.com, Prometheus Users
Thanks for the description!

How do you map prometheus metrics and labels in the stats.json file?



--
You received this message because you are subscribed to a topic in the Google Groups "Prometheus Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/prometheus-users/jescPNRdArI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/3f45a6ed-0567-4a9f-bb70-90e82e6c738f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages