All Projects → MindFlavor → prometheus_exporter_base

MindFlavor / prometheus_exporter_base

Licence: MIT license
Base library for Rust Prometheus exporters

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to prometheus exporter base

Krita Batch Exporter
A Free Krita plugin to batch export layers and groups with maximum flexibility. Scale, trim, export multiple copies of your layers...
Stars: ✭ 201 (+570%)
Mutual labels:  exporter
prometheus-fastapi-instrumentator
Instrument your FastAPI app
Stars: ✭ 511 (+1603.33%)
Mutual labels:  exporter
ox-ssh
SSH config export for org-mode
Stars: ✭ 33 (+10%)
Mutual labels:  exporter
Awesome Prometheus Alerts
🚨 Collection of Prometheus alerting rules
Stars: ✭ 3,323 (+10976.67%)
Mutual labels:  exporter
query2metric
A tool to run queries in defined frequency and expose the count as prometheus metrics. Supports MongoDB and SQL
Stars: ✭ 21 (-30%)
Mutual labels:  exporter
xenstats exporter
Prometheus exporter for xen (Storage, Host CPUs, Memory usage)
Stars: ✭ 20 (-33.33%)
Mutual labels:  exporter
Blender niftools addon
The Blender Niftools Addon is a Blender add-on to enable import and export of NetImmese File Formats including .nif, .kf, .egm.
Stars: ✭ 191 (+536.67%)
Mutual labels:  exporter
genshin-audio-exporter
Export audio files from Genshin Impact game data into different audio formats.
Stars: ✭ 83 (+176.67%)
Mutual labels:  exporter
expresso
Expresso! Exporter is a Photoshop extension aimed at improving the texturing workflow for 3D Artists. It automatically exports textures to common file formats (TGA, PNG, etc.) out of PSDs containing multiple maps.
Stars: ✭ 57 (+90%)
Mutual labels:  exporter
shelly-plug-prometheus
Shelly Plug Prometheus exporter.
Stars: ✭ 40 (+33.33%)
Mutual labels:  exporter
Github Exporter
Prometheus exporter for github metrics
Stars: ✭ 231 (+670%)
Mutual labels:  exporter
mac-notes-exporter
Your last straw to save your data from Notes.app.
Stars: ✭ 32 (+6.67%)
Mutual labels:  exporter
speedtest-exporter
Speedtest Exporter made in python using the official speedtest bin
Stars: ✭ 118 (+293.33%)
Mutual labels:  exporter
Maya2gltf
Maya to glTF 2.0 exporter
Stars: ✭ 203 (+576.67%)
Mutual labels:  exporter
blendmaxwell
Maxwell Render exporter for Blender
Stars: ✭ 23 (-23.33%)
Mutual labels:  exporter
Clickhouse exporter
This is a simple server that periodically scrapes ClickHouse stats and exports them via HTTP for Prometheus(https://prometheus.io/) consumption.
Stars: ✭ 193 (+543.33%)
Mutual labels:  exporter
lustre exporter
Prometheus exporter for use with the Lustre parallel filesystem
Stars: ✭ 25 (-16.67%)
Mutual labels:  exporter
draftjs exporter
Library to convert Draft.js ContentState to HTML
Stars: ✭ 77 (+156.67%)
Mutual labels:  exporter
network exporter
ICMP & MTR & TCP Port & HTTP Get - Network Prometheus exporter
Stars: ✭ 162 (+440%)
Mutual labels:  exporter
yarn-prometheus-exporter
Export Hadoop YARN (resource-manager) metrics in prometheus format
Stars: ✭ 44 (+46.67%)
Mutual labels:  exporter

Rust Prometheus exporter base

Rust base library for Prometheus exporters

Rust

legal

release commitssince

Crate cratedown cratelastdown

Goal

This crate is meant to make writing a proper Prometheus exporter with a minimal effort. It gives you two things.

  1. A Rust-y, fluent way to create Prometheus compliant outputs:
PrometheusMetric::build()
     .with_name("folder_size")
     .with_metric_type(MetricType::Counter)
     .with_help("Size of the folder")
     .build()
     .render_and_append_instance(
         &PrometheusInstance::new()
             .with_label("folder", "/var/log")
             .with_value(total_size_log)
             .with_current_timestamp()
             .expect("error getting the UNIX epoch"),
     )
     .render()
  1. It optionally gives you a boilerplate-free Hyper server for exposing your Prometheus metrics. It handles most mundane tasks, such as setting up an Hyper server and doing some basic checks (such as rejecting anything but GET and responding only to the /metrics suffix) so all you have to do is supply a Boxed future that will handle your logic (remember to specify the hyper_server feature flag in your Cargo.toml as well).

I use it on these crates: prometheus_wireguard_exporter and prometheus_iota_exporter so please refer to these crates if you want to see a real-world example. More simple examples are available in the examples folder.

Usage

PrometheusMetric

The PrometheusMetric struct is used by instantiating it and then "rendering" the header and values - optionally specifying labels. This is an example taken from the documentation:

PrometheusMetric::build()
     .with_name("folder_size")
     .with_metric_type(MetricType::Counter)
     .with_help("Size of the folder")
     .build()
     .render_and_append_instance(
         &PrometheusInstance::new()
             .with_label("folder", "/var/log")
             .with_value(total_size_log)
             .with_current_timestamp()
             .expect("error getting the UNIX epoch"),
     )
     .render()

This will give you something like this:

For a more complete example please refer to the examples folder.

Hyper server

To use Hyper server all you have to do is specify the hyper_server feature flag and call the render_prometheus function. This function requests you to pass:

  1. The address/port to listen to. For example ([0, 0, 0, 0], 32221).into() listens on every interface on port 32221.
  2. The authorization type. Right now is either allow every connection or authenticate with Basic auth (password).
  3. An arbitrary struct to be passed back to your code (useful for command line arguments). If you don't need it, pass an empty struct.
  4. The code your exporter is supposed to do. This takes the form of a closure returning a boxed future. The closure itself will receive the http request data along with the aforementioned struct (point 2). The output is expected to be a string.

For example:

let addr: SocketAddr = ([0, 0, 0, 0], 32221).into();
let password = "SimplePassword".to_owned();

let server_options = ServerOptions {
    addr,
    authorization: Authorization::Basic(password),
};

render_prometheus(server_options, MyOptions::default(), |request, options| {
    async {
    	Ok("it works!".to_owned())
    }
}).await;

As you can see, in order to keep things simple, the Hyper server does not enforce anything to the output. It's up to you to return a meaningful string by using the above mentioned structs.

Testing

Once running, test your exporter with any GET enabled tool (such as a browser) at http://127.0.0.1:<your_exporter_port>/metrics.

Changelog

  • Starting from version 1.4.0 the hyper server supports basic authentication. If you enable it, make sure to configure prometheus accordingly by specifying basic_auth with either password or password_file. Also note that the authorization header always include the username (which is unused here) so if you pass it manually prepend the colon char to your password before encoding it in base 64. Prometheus does that automatically, you don't have to do anything for it to work. Lastly, basic auth does not encrypt the password so make sure to use TLS if you need secrecy.

License

Please see the LICENSE file (spoiler alert: it's MIT).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].