Writing To Prometheus

The following section assumes that you already have Hotrod (possibly deployed on some Bboxes) up and running, for more information related to getting up and running see our Getting Started Guide.

Simple metrics using Node Exporter's Textfile Collector

The Textfile collector merely requires us to put .prom files in Prometheus text format into /var/lib/prometheus/node-exporter. A little care is needed to make sure that this is an atomic operation, since the Node exporter is always watching this directory.

name: temp
input:
    text: '{"value1":6, "value2":8}'
context:
    xnode: /var/lib/prometheus/node-exporter
actions:
- add:
      template-result-field: metric
      template: |
        my_value1 ${value1}
        my_value2 ${value2}
        my_value3{boo="frodo"} ${value1}
        my_value3{boo="bilbo"} ${value2}
output:
    exec:
        no-expand: true
        input-field: metric
        command: |
            cat > /tmp/prom.$$;
            mv /tmp/prom.$$ {{xnode}}/my.prom

add template allows us to create arbitrary documents and pack them into a field, which becomes the input of output exec.

Note that metrics may have custom labels, which assist in querying. A query for a metric with labels will return values for all values of the label.

Some labels are always attached by the exporter, in particular instance.

$ pipeline-cli temp.yml run
 INFO  pipeline_api > building target for "temp"
$ curl -g 'http://localhost:9090/federate?match[]=my_value1'
# TYPE my_value1 untyped
my_value1{instance="localhost:9100",job="node",monitor="example"} 6 1548768197364
$ curl -g 'http://localhost:9090/federate?match[]=my_value3'
# TYPE my_value3 untyped
my_value3{boo="bilbo",instance="localhost:9100",job="node",monitor="example"} 8 1548768212364
my_value3{boo="frodo",instance="localhost:9100",job="node",monitor="example"} 6 1548768212364