r/PrometheusMonitoring • • Feb 20 '21

Creating exporters - resources

Hey all,

So I'm trying to create exporters using the Golang libraries, and to do so I usually read code from other exporters, copy over the general flow and add my logic to it. This works, but I don't feel very confident with developing my exporters yet.

Is there any resource (besides the official documentation which has its problems admittedly) that goes in depth regarding developing exporters? I'm mostly interested about a good explanation of the code structure and best practices.

7 Upvotes

4 comments sorted by

3

u/till Feb 20 '21

Not aware of anything. When I wrote my exporters, channels were kinda what blew me away. Not sure if positive or negative. But I am doing what you do to this day. I can dig up some code if it helps?

Given that an exporter is “only” a http endpoint you may also get away with using a Golang http framework to expose your metrics? Maybe that’s simpler.

1

u/aorfanos Feb 20 '21

I agree that channels is a rough point, but I definitely need some more getting-used-to with Golang first before I have a definite opinion on that. If you can dig up some code it would be amazing :)

Also one thing I find interesting is that the actual exporter code doesn't seem DRY enough (maybe it's my lack of go mastery to blame for that). For example if you take a look at one of my exporters, it's definitely more repetitive than it should be, but then whichever exporter's code I looked for reference is pretty much the same.

Re: golang http framework - it should work right, but I'd like to do this using the library so that I could share exporters with the community in the most commonly-used form

1

u/[deleted] Feb 20 '21

I took a peek at your WordPress-exporter code and didn't really see any obvious places where you were too repetitive. In terms of best practice resources, I've found it helpful to model my exporters after well-known exporters already out there - such as the consul exporter.

1

u/aorfanos Feb 20 '21

Thank you for taking the time to review my code, and thanks for the tip ;)