Prometheus (om_prometheus)
This module exposes Prometheus-compatible metrics via an HTTP endpoint. It supports counters and gauges extracted from structured records.
Output data format
The module converts incoming records into a set of Prometheus-compatible key-value pairs. It processes events according to the specified mapping. It supports:
-
Counters — Values that accumulate over time.
-
Gauges — Values that represent the current state.
The module treats any numeric field without a corresponding mapping as a Gauge.
The module exposes metrics over HTTP in standard Prometheus exposition format. The following endpoints are available:
/metrics
-
Returns the current set of metrics in Prometheus format
/healthy
-
Always returns HTTP 200. Used for checking the probe health.
/ready
-
Always returns HTTP 200. Used for checking the probe readiness.
Nested structures in incoming records are automatically flattened using _ as the delimiter.
For example, { "system": { "cpu": { "usage": 42.5 }}} becomes system_cpu_usage .
The name and labels fields in the MappingFile are sanitized as well and must match the fully flattened keys.
|
Consider the behavior of floating-point number representation—Incoming integer numbers greater than 2^53 will lose precision, and their output will be in scientific format. |
Configuration
The om_prometheus module accepts the following directives in addition to the common module directives.
HTTPS directives
The path of the certificate authority (CA) certificate that will be used to verify the certificate presented by the remote host. A remote host’s self-signed certificate (which is not signed by a CA) can be trusted by specifying the remote host certificate itself. In the case of certificates signed by an intermediate CA, the certificate specified must contain the complete certificate chain (certificate bundle). |
|
The path of the certificate file that will be presented to the remote host during the HTTPS handshake. |
|
The path of the private key file that was used to generate the certificate specified by the HTTPSCertFile directive. This is used for the HTTPS handshake. The key must be in PKCS#8 format.
Outdated PKCS#1 RSA keys, for example, those starting with |
Optional directives
The IP address and port that the module will bind to and accept connections on.
The default is |
|||
The path to a JSON schema file specifying how to interpret fields.
This file should define a
The module treats fields in log records without a corresponding mapping as gauges.
|
|||
Prometheus allows only The default is
When For more information about Prometheus naming requirements, refer to the Prometheus naming guidelines.
|
Examples
This configuration processes JSON records and exports them as metrics for Prometheus scraping. See the Prometheus <scrape_config> documentation for information on scraping targets.
<Output prometheus_export>
Module om_prometheus
ListenAddr 0.0.0.0:9464
MappingFile /opt/nxlog/etc/prometheus-mapping.json
</Output>
The following mapping defines a counter and several gauge fields and their labels.
{
"metrics": {
"counter": [
{
"name": "http_request_count",
"labels": ["method", "region"]
}
],
"gauge": [
{
"name": "cpu_usage",
"labels": ["host", "region"]
},
{
"name": "memory_usage",
"labels": ["host", "region"]
},
{
"name": "disk_io",
"labels": ["host", "region"]
}
]
}
}
{"cpu_usage": 38.6, "memory_usage": 65.0, "disk_io": 78, "host": "server3", "region": "eu-central"}
{"cpu_usage": 38.7, "http_request_count": 33, "disk_io": 110, "new_parameter": 333.33, "method": "SET", "region": "eu-central"}
The following is a sample response to a request to http://localhost:9464/metrics
.
# TYPE cpu_usage gauge
cpu_usage{region="eu-central"} 38.7
# TYPE disk_io gauge
disk_io{region="eu-central"} 110
# TYPE http_request_count counter
http_request_count{method="SET",region="eu-central"} 33
# TYPE memory_usage gauge
memory_usage{host="server3",region="eu-central"} 65
# TYPE new_parameter gauge
new_parameter{region="eu-central"} 333.33