Introduction
In this post I will show you how to push metrics programmatically to Pushgateway. There are two types of puffed out metrics:
- Text
- Protocol buffer
In this post we will cover Protocol buffer
Library for languages
There is a library for each language, although it is a little blind spot because the metric push method to Push gateway is implemented in the client library of Prometheus. Normally, it is better to use the following library.
Prometheus Client Data Specifications
The following documentation describes the format of Prometheus Client Data.
32-Bit Varint-Encoded Record Length-Delimited need to be applied
It seems good to add the Length of the entire byte string of Protocol buffer to the beginning of the byte string.
The proto file metrics.proto is published in the following repository
By the way, the structure definition metrics.pb.go for Go language is also prepared, so if you want to implement it in Go language, just go get and get it. Just in case, you should use the same version as client_model of the dependent module of Push Gateway of your version .
The value of the header Content-Type
is application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited
Example Implementation
dump
Is an unnecessary process for pushing metrics, and is a code written for byte string comparison.