A Prometheus /metrics endpoint bridging data from a gRPC service,
for when you cannot host gRPC and HTTP at the same time.
When running the service using Docker, provide the GRPC_SERVER_CONNECT_ADDRESS
environment variable with the host and port combination of the gRPC server to addess:
docker run --rm \
--env GRPC_SERVER_CONNECT_ADDRESS="example:11000" \
--publish 80:80 \
nyris/prometheus-grpc-bridge:0.1.0You can optionally provide GRPC_SERVER_CONNECT_SCHEME as well, this defaults to http.
The server supports both HTTP/1.1 and HTTP/2 transparently without requiring a secure connection to perform ALPN.
For a complete example, see docker-compose.yml. You can start
both the bridge and an example server by running:
docker compose upTo host the service locally, run e.g.
cargo run -- --serve 0.0.0.0:8080Afterwards, you can fetch metrics using e.g. curl (HTTP/1.1) or nghttp (HTTP/2 prior knowledge):
curl http://localhost:8080/metrics
nghttp http://localhost:8080/metricsThe server's log output can be controlled using the RUST_LOG environment variable.
To switch between plain and JSON log output, provide the --log simple or
--log json argument respectively:
cargo run -- --serve 0.0.0.0:8080 --log jsonNote that logging of debug level and below is disabled in release builds.
The gRPC protocol is kept simple and assumes the metrics can already
be provided in Prometheus text format as described in the Exposition formats
section. See the prometheus.proto file for the protocol:
syntax = "proto3";
package prometheus;
service PrometheusMetrics {
rpc Metrics(PrometheusMetricsRequest) returns (PrometheusMetricsResponse) {}
}
message PrometheusMetricsRequest {
}
message PrometheusMetricsResponse {
// The metrics as a string in Prometheus text format.
string text = 1;
}This project comes with a Rust example server based on Tonic.
To run the server defined in examples/grpc_server.rs, execute
cargo run --example grpc_serverIt provides a simple instance metric and a gauge that increments with every request. To quickly poll the server using the default settings, run:
cargo run
Similarly, you can inspect the gRPC call using grpcurl:
grpcurl -plaintext localhost:11000 prometheus.PrometheusMetrics/MetricsIf not mentioned otherwise in a file, the content provided is licensed under the EUPL v1.2, a copy of which can be found in LICENSE.md.