Prometheus exporter framework
Lets you create a powerful exporter in two minutes.
This framework is extracted from node_exporter's node_exporter.go and collector.go. You can use all the features of node_exporter with this framework:
- Enable & Disable collectors
- Include & Exclude flags
- Filtering enabled collectors
- Useful metrics
collector_duration_secondsandcollector_success - ...
There is an example in _example.
Creating your exporter is very easy:
- Create some collectors implement
github.com/rea1shane/exporter/collector.Collectorand callgithub.com/rea1shane/exporter/collector.RegisterCollectorin theirinitfunction. - Call the
github.com/rea1shane/exporter.Runfunction to start the exporter.
Now, everything is done!
- Same as
node_exporter, the framework useslog/slogas the logger andgithub.com/alecthomas/kingpin/v2as the command line argument parser. github.com/rea1shane/exporter/collector.ErrNoDataindicates the collector found no data to collect, but had no other error. If necessary, return it in thegithub.com/rea1shane/exporter/collector.Collector'sUpdatemethod.github.com/rea1shane/exporter/metric.TypedDescmakes easier to create metrics.- If you are not using
github.com/rea1shane/exporter/metric.TypedDescto create metrics, you can usegithub.com/rea1shane/exporter/util.AnyToFloat64function to convert the data tofloat64.
Add _ "net/http/pprof" to imports to enable PProf statistics:
package main
import (
_ "net/http/pprof"
)See prometheus/exporter-toolkit#196 for more information.
You can using Prometheus's Makefile.common file to building or running an exporter that uses this framework just like node_exporter. All you need is:
- Copy prometheus/node_exporter/Makefile.common to your repository root path.
- Create
.promu.ymllike prometheus/node_exporter/.promu.yml. - Create
Makefilelike prometheus/node_exporter/Makefile. - Create
VERSIONlike prometheus/node_exporter/VERSION.
Now your repository will looks like this:
your_exporter
├── .promu.yml
├── Makefile.common
├── Makefile
├── VERSION
└── ...
Then you can execute everything that has been defined in Makefile.common. Some examples:
- Run
- Local build
- Building with Docker (Note: You need a
Dockerfilelike this)
If you want to build in a simple way, see example's Makefile. (Note: Also need a VERSION file and may missing tags info)