Skip to content

Bash library to save metrics to Prometheus format. Output can be used with the node-exporter textfile collector.

License

Notifications You must be signed in to change notification settings

fabricat/bash_prometheus_metrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

bash_prometheus_metrics

This Bash library helps you to save metrics to Prometheus format.

The produced output can be used with the node_exporter textfile collector.

Usage guide

The following global variables can be used:

  • metrics_prefix (string, optional, default: empty prefix)
    If present, will be prefixed to all metric names ("_" is implicit).
    Example: metrics_prefix="my"
  • metrics_array (array, optional, default: empty array)
    The metrics will be appended to this initial array.
    Example: metrics_array=('my_counter{path="root"} 93' 'my_counter{path="home"} 42')

exporter_add_metric input parameters:

  • $1: Metric name (string)
    Example: "storage_bytes"
  • $2: Metric type ("gauge" or "counter")
    Example: "gauge"
  • $3: Metric description (string)
    Example: "Number of numbers of something"
  • $4: Metric value (int or float)
    Example: 1.488
  • $5: Metric labels (string, optional, default: no labels)
    String pairs with ":" as key/value separator and ";" separator between multiple pairs.
    Example: "label_one_name:label_one_value;label_two_name:label_two_value"
    Important: whitespaces are not allowed in label keys nor values!
  • $6: Additional metric value (int or float, optional)
    Identical to $4 but, if present, must be followed by $7.
  • $7: Labels for the additional value (string, optional)
    Identical to $5.

Note: $6 and $7 can be repeated several times (each with a unique label set).

Usage example

# import function definitions
source ./exporter_lib.sh

# (optional) define a prefix for all your metrics
export metrics_prefix=node

# add as many metrics as you have
exporter_add_metric \
  apr_entries \
  gauge \
  "ARP entries by device" \
  12.0 "device:eth0" \
  1.0 "device:eth1" \
  3.0 "device:eth2"

# output all the metrics to a textfile
exporter_show_metrics > /var/lib/node_exporter/my_metrics.prom

Notes

Take always into account the best practices about metric and label naming.

About

Bash library to save metrics to Prometheus format. Output can be used with the node-exporter textfile collector.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages