prometheus-universal-exporter

command module
v0.0.0-...-6a31fc4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

prometheus-universal-exporter

prometheus-universal-exporter

CI Artifact Hub Exporter release Chart release Go License

Turn a source that was never meant for Prometheus — an HTTP API, a gRPC service, a Graphite server, a file on this or another host or in an S3 bucket, a SQL database, a Redis server, a service that speaks a text protocol over TCP, an LDAP directory, a command run on another host, a DNS name, a TLS certificate, an NTP server, a host answering a ping, an SNMP agent, a Kubernetes object, or, built on request, a mail server, a Modbus device, an MQTT broker, a WebSocket endpoint, an FTP server or a mailbox of a mail account, over IMAP or POP3 — into a Prometheus target, without writing an exporter for it.

The exporter can collect metrics from almost any source: HTTP services returning JSON, NDJSON, YAML, TOML, INI, XML, CSV, HTML, logfmt, plain text, or Prometheus exposition; gRPC services; Graphite servers; local files such as .prom files generated by batch jobs; the same files on another host, read over SSH; the output of a command run on another host over SSH; objects in Amazon S3 or a store that speaks its API; SQL databases such as MySQL, PostgreSQL, and SQL Server; the INFO and read-only commands of Redis and Valkey servers; the statistics of services that answer a line sent over TCP, such as memcached, ZooKeeper and HAProxy's runtime API, or a datagram over UDP, and whether a host's ports take a connection; searches of LDAP directories, such as OpenLDAP and Active Directory; the DNS records of a name; the TLS certificates a server presents, with their expiry; the clock of an NTP server, its offset from the exporter's and its stratum; the echo replies of a host pinged over ICMP; the objects and tables of SNMP agents, such as switches, routers and UPSes, v1, v2c or v3; or Kubernetes objects of any kind, built in or custom, listed from the API server. A build that asks for them adds mail servers over SMTP, Modbus TCP devices, the topics of an MQTT broker, WebSocket endpoints, files on an FTP server, the mailboxes of a mail account over IMAP and a mailbox over POP3. Collectors define how to query, parse, transform, and publish the data as Prometheus metrics. Because everything is configuration-driven, collection rules can be changed without writing code, rebuilding the exporter, or redeploying it.

Try it

From a checkout, with Go installed, run one of the examples under examples/:

make run EXAMPLE=open-meteo PORT=9115

It builds bin/prometheus-universal-exporter and runs it on 127.0.0.1:9115 with the example's configuration and static targets. Open http://127.0.0.1:9115/ for the landing page and http://127.0.0.1:9115/static-targets/status for the targets' last scrapes and the recent probes; every example has the status page, and the command also prints a probe URL when the example's configuration gives one whose target a local run can reach (a hint with <your target> for a placeholder). make run alone lists the examples; make build builds into bin/ too.

How it works

Targets are never written into the configuration. Prometheus discovers the real service and passes it to the exporter as target; the collector parameter picks which server-side configuration reads it:

/probe?target=http%3A%2F%2Flegacy.example%3A8080&collector=legacy_text

One exporter therefore serves many services and many response shapes, and a collector is reusable across every target that answers the same way.

For a fixed list of targets there is a second way in: list them as static targets, which the exporter scrapes itself on their own intervals and serves together on one endpoint, /static-targets, for Prometheus to scrape like any other exporter, and, one by one, over OTLP.

Quick start

Describe a collector:

collectors:
  - name: app_json
    metrics_prefix: myapp   # optional; exports myapp_application_requests_total
    request:
      type: http
      path: /status
    transform:
      type: jq
    metrics:
      - name: application_requests_total
        description: Total application requests
        type: counter
        expression: .requests

metrics_prefix is optional: when set, it is joined with _ to the front of every metric the collector exports. See Prefixing a collector's metrics. For a list of things — servers, rows, components — give a metric items and write its value and labels against one item at a time; see Metrics per item. A paged API is read page by page into one answer; see Pagination. Collectors can also live in files of their own, listed under collector_files — one per team or per ConfigMap key; a collector name must be unique across all of them. See Collector files.

Your editor can check the file as you type: start it with

# yaml-language-server: $schema=https://raw.githubusercontent.com/eenchev/prometheus-universal-exporter/main/configs/config.schema.json

and the YAML language server completes keys and flags mistakes against configs/config.schema.json. Every expression is also compiled when the exporter starts, so a typo stops it with a message naming the collector and metric, rather than failing each scrape.

Run the exporter and probe a target through it:

go run . --config.file=configs/config.example.yaml

curl 'http://localhost:8080/probe?target=http://127.0.0.1:9000&collector=app_json'

The response is ordinary Prometheus exposition, which is what Prometheus scrapes. configs/config.example.yaml is a complete working document with JSON, text, CSV and Prometheus collectors, over HTTP and local files; the other decoders have their examples under examples/ and in Configuration.

Or run the published image:

docker run -p 8080:8080 \
  -v "$PWD/config.yaml:/etc/prometheus-universal-exporter/config.yaml:ro" \
  ghcr.io/eenchev/prometheus-universal-exporter:latest

Install with Helm

The chart is published to GitHub Container Registry as an OCI artifact. It is public, so no registry login is needed. Prometheus Operator CRDs are not installed by this chart.

helm install exporter \
  oci://ghcr.io/eenchev/charts/prometheus-universal-exporter \
  --version 2.1.0 \
  --set-file 'config.data.config\.yaml=configs/config.example.yaml'

Omitting --version takes the newest published chart; pin it for anything you deploy more than once. To install from a checkout instead:

helm install exporter charts/prometheus-universal-exporter \
  --set-file 'config.data.config\.yaml=configs/config.example.yaml'

The chart creates the Deployment, Service, ConfigMap and, on request, ServiceMonitor or PodMonitor resources with the relabeling the probe pattern needs. With allocator.enabled it also runs the target allocator, which shares the targets out across exporter replicas so collection scales horizontally. See the chart README for its values.

Endpoints and flags

/probe scrapes a target through a collector, /self-metrics serves the exporter's own metrics and /static-targets the latest results of the static targets. / is a landing page, /collectors probes a target from the browser, and /health and /ready are for Kubernetes; /-/reload and /debug are served when their flags ask for them. Endpoints has what each one takes and answers, and Command-line flags every flag, which --help prints too.

Documentation

New here? Getting started takes you from nothing to Prometheus scraping your first metric in about 15 minutes, and How do I… finds the page for a task: a JSON API, a login, a CSV over SSH, a certificate's expiry.

Not sure which request type reads what you want? Which request type? has a table of what each one is for.

  • Configuration — collectors, decoders, transforms, metric rules, caching and serving the last good result while a target is down, environment variables, reloading.
  • Endpoints and command-line flags — what each endpoint takes and answers, and every flag of the exporter.
  • Target requests — the request URL and the Host header, redirects, HTTP/2, retries, accepted statuses, a request's timings, TLS connection and final URL, pagination, restricting targets, TLS, proxies, per-scrape overrides, and dates and times in a request.
  • Uptime probes — whether HTTP and HTTPS sites are up, their status, the phases of the request, the redirects and the certificate's expiry, as blackbox_exporter's http prober reports them, from one collector, configs/config.uptime.example.yaml.
  • Local files — the localfile request type: reading metrics and status files from disk, one file or a whole directory.
  • Graphite — the graphite request type: Graphite series from a render API, or carbon lines from a file, as Prometheus metrics.
  • gRPC — the grpc request type: a unary or server streaming gRPC method called with a JSON message, its answer mapped as JSON, with message types from server reflection, a descriptor set or .proto files.
  • Files over SSH — the sshfile request type: metrics and status files read from another host over SFTP, one file or a whole directory, on a kept connection with the host's key always verified.
  • Commands over SSH — the sshexec request type: one fixed command run on another host over SSH, such as df or a script of its own, its output handed to any transform as a body, each word quoted for the host's shell.
  • Objects in S3 — the s3file request type: objects of Amazon S3, MinIO, Ceph, R2 or GCS read as files, one object or every matching one under a prefix.
  • Databases over SQL — the sql request type: read-only statements, one or several in order, on PostgreSQL, MySQL, SQL Server and, built on request, Oracle, ClickHouse, Snowflake or Vertica, its rows read by column, on pooled connections.
  • Redis and Valkey — the redis request type: a server's INFO and the replies of read-only commands, such as a queue's length, as a JSON document, over plaintext or TLS, of a server named or the primary a Sentinel names.
  • Text protocols over TCP — the tcp request type: a line such as memcached's stats, a conversation of several, or binary bytes, sent over a TCP or TLS connection, a Unix socket or UDP, and the answer read until a terminator, a length or the close, handed to any transform as a body; or whether a port, or several of a host, take a connection.
  • LDAP directories — the ldap request type: searches of an LDAP directory, such as OpenLDAP's cn=Monitor counters or the disabled accounts of Active Directory, their entries or their count, as a JSON document, over plaintext, StartTLS or LDAPS.
  • DNS — the dns request type: the A, AAAA, CNAME, MX, NS, TXT, SRV, PTR, SOA, CAA, DNSKEY or RRSIG records of a name, with their TTLs and the answer's response code, from the system's resolvers or a named server, over UDP, TCP or TLS, as a JSON document.
  • TLS certificates — the tlscert request type: the certificates a server presents in a TLS handshake, from the start or after STARTTLS on a mail or FTP server, their names, issuers and expiry, and whether the chain verifies.
  • NTP — the ntp request type: SNTP requests to an NTP server, or several compared, the clock's offset from it, the round trip's delay and the jitter, and the server's stratum, leap indicator and reference, as a JSON document.
  • Ping over ICMP — the icmp request type: echo requests to a host, as ping sends them, on an unprivileged socket, and how many replies came and how long each took, as a JSON document.
  • SNMP agents — the snmp request type: objects read with Get and tables walked with GetBulk or GetNext from an SNMP agent, v1, v2c or v3 with authentication and encryption, by numeric identifiers the collector names, as a JSON document.
  • Kubernetes objects — the kubernetes request type: the objects of one resource, built in or custom, or their metadata alone, listed from the API server with the exporter's service account, as a JSON document, for metrics such as kube-state-metrics gives from configuration alone; and the nodes' kubelets' statistics, each pod's ephemeral storage, CPU and memory.
  • SMTP — the smtp request type, in a build that asks for it: a mail server's greeting, its extensions, STARTTLS, a login with PLAIN, LOGIN or XOAUTH2, and its answers to MAIL FROM and RCPT TO, with nothing sent, as a JSON document.
  • IMAP — the imap request type, in a build that asks for it: the messages, unread messages and size of the mailboxes of a mail account, by name or by pattern, its quota, and how many messages match a search, read with a login and no message fetched, as a JSON document.
  • POP3 — the pop3 request type, in a build that asks for it: how many messages a mailbox holds and their size, read with a login by any of the mechanisms POP3 servers take and no message fetched, as a JSON document.
  • Modbus — the modbus request type, in a build that asks for it: holding and input registers, coils and discrete inputs of a PLC, an inverter or a meter over Modbus TCP, read as numbers of the type and byte order the collector names, as a JSON document.
  • MQTT — the mqtt request type, in a build that asks for it: the retained messages of the topics a collector subscribes to, and those published within a window, a session the broker keeps or a connection the exporter keeps, as a JSON document.
  • WebSocket — the websocket request type, in a build that asks for it: a WebSocket endpoint sent one message, or none, and the message it answers handed to any transform as a body, or several as a JSON list.
  • Files over FTP — the ftp request type, in a build that asks for it: one file of an FTP server, over plaintext, explicit TLS or FTPS, read as a local file is.
  • Authentication — credentials for the target, logging in to it, and credentials for the exporter itself.
  • Prometheus Operator — ServiceMonitor and PodMonitor.
  • Helm chart — every chart value.
  • Python — the transform and pre-script API.
  • Self-metrics — what the exporter reports about itself.
  • Static targets — targets the exporter scrapes itself on their own intervals and serves on one endpoint.
  • Target allocator — pue-allocator, which serves several exporter replicas their configuration and each its share of the static targets, and Prometheus the probe targets already pointed at a replica.
  • OTLP — OTLP export, its retries and compression.
  • Logging — the log format.
  • Exporter specification — the implementation specification for the exporter.
  • Chart specification — the implementation specification for the Helm chart.
  • The request types' specifications, each type's section of the exporter's: dns, ftp, graphite, grpc, icmp, imap, kubernetes, ldap, localfile, modbus, mqtt, ntp, pop3, redis, s3file, smtp, snmp, sql, sshexec, sshfile, tcp, tlscert, websocket.

For contributors: development, dependencies and releasing.

License

See LICENSE.

Documentation

Overview

Command prometheus-universal-exporter turns HTTP endpoints and files that were never meant for Prometheus into Prometheus targets, as configured by collectors. See README.md and docs/.

The command line and the process lifecycle are here, the --dry-run report in check.go and --healthcheck in healthcheck.go; everything else is under internal/.

Directories

Path Synopsis
cmd
pue-allocator command
Command pue-allocator is the target allocator of prometheus-universal-exporter: it serves every exporter replica run with --allocator.url its configuration and its share of the static targets, and Prometheus the probe targets, each already pointed at a replica, through HTTP service discovery.
Command pue-allocator is the target allocator of prometheus-universal-exporter: it serves every exporter replica run with --allocator.url its configuration and its share of the static targets, and Prometheus the probe targets, each already pointed at a replica, through HTTP service discovery.
internal
allocapi
Package allocapi is what the target allocator (cmd/pue-allocator) and an exporter in allocator mode say to each other: the heartbeat a replica sends, the bundle of configuration files it is served, the paths they travel on, and the rendezvous hash that decides which replica owns a target.
Package allocapi is what the target allocator (cmd/pue-allocator) and an exporter in allocator mode say to each other: the heartbeat a replica sends, the bundle of configuration files it is served, the paths they travel on, and the rendezvous hash that decides which replica owns a target.
allocator
Package allocator is the target allocator, cmd/pue-allocator: it serves every exporter replica in allocator mode its configuration and its share of the static targets as one bundle, and Prometheus the probe targets already pointed at a replica, through HTTP service discovery.
Package allocator is the target allocator, cmd/pue-allocator: it serves every exporter replica in allocator mode its configuration and its share of the static targets as one bundle, and Prometheus the probe targets already pointed at a replica, through HTTP service discovery.
allocclient
Package allocclient is the exporter's side of the target allocator (internal/allocapi): in allocator mode (--allocator.url) it heartbeats to every instance of the allocator, long-polls the allocator for its bundle, writes a new bundle into the cache directory where the configuration manager loads it, and has the manager reload it.
Package allocclient is the exporter's side of the target allocator (internal/allocapi): in allocator mode (--allocator.url) it heartbeats to every instance of the allocator, long-polls the allocator for its bundle, writes a new bundle into the cache directory where the configuration manager loads it, and has the manager reload it.
config
Package config loads and validates the configuration file, its collector files and the static target file, reloads them when they change, and describes them with JSON Schemas.
Package config loads and validates the configuration file, its collector files and the static target file, reloads them when they change, and describes them with JSON Schemas.
decode
Package decode turns fetched bytes into data a transform can read: JSON, YAML, XML, CSV, HTML, the Prometheus text format and plain text, after converting the body to UTF-8 from the charset it declares.
Package decode turns fetched bytes into data a transform can read: JSON, YAML, XML, CSV, HTML, the Prometheus text format and plain text, after converting the body to UTF-8 from the charset it declares.
exporter
Package exporter serves the exporter's HTTP endpoints — /probe, the self-metrics, /health, /ready and /-/reload — and runs the probe pipeline behind them: fetch, decode, transform and validate, with the response cache, shared in-flight probes and concurrency limits.
Package exporter serves the exporter's HTTP endpoints — /probe, the self-metrics, /health, /ready and /-/reload — and runs the probe pipeline behind them: fetch, decode, transform and validate, with the response cache, shared in-flight probes and concurrency limits.
expr
Package expr compiles the expressions metric rules are written in — jq, regular expressions, CSS selectors and XPath — and keeps each compiled program in a bounded cache, so a rule is compiled once rather than on every scrape.
Package expr compiles the expressions metric rules are written in — jq, regular expressions, CSS selectors and XPath — and keeps each compiled program in a bounded cache, so a rule is compiled once rather than on every scrape.
fetch
Package fetch gets a collector's raw data.
Package fetch gets a collector's raw data.
grpctest
Package grpctest runs an in-process gRPC server for the tests of the grpc request type: a queue service defined by .proto sources compiled at run time, so the tests need neither protoc nor generated code, with the health service and, as a test asks, reflection v1, v1alpha or none, over plaintext or TLS.
Package grpctest runs an in-process gRPC server for the tests of the grpc request type: a queue service defined by .proto sources compiled at run time, so the tests need neither protoc nor generated code, with the health service and, as a test asks, reflection v1, v1alpha or none, over plaintext or TLS.
kubeapi
Package kubeapi lists objects from a Kubernetes API server over its REST API, with nothing but the standard library: the target allocator's kubernetes discovery lists EndpointSlices with it, and the exporter's kubernetes request type lists objects of any kind.
Package kubeapi lists objects from a Kubernetes API server over its REST API, with nothing but the standard library: the target allocator's kubernetes discovery lists EndpointSlices with it, and the exporter's kubernetes request type lists objects of any kind.
kubetest
Package kubetest is a stand-in Kubernetes API server for the tests of internal/kubeapi and of the kubernetes request type: an HTTPS server that answers a listing of the objects a test gave it at a path, a page at a time as the limit asks with a continue token for the rest, refuses a request without the token in its service account directory, or the one it was told to require, with 401, answers 403 and 404 as the API server does, 429 as its priority and fairness does, 410 Expired for a continue token it was told to have lost, a listing of the objects' metadata alone when it is asked for that, can be slow to answer, and records every request it was sent.
Package kubetest is a stand-in Kubernetes API server for the tests of internal/kubeapi and of the kubernetes request type: an HTTPS server that answers a listing of the objects a test gave it at a path, a page at a time as the limit asks with a continue token for the rest, refuses a request without the token in its service account directory, or the one it was told to require, with 401, answers 403 and 404 as the API server does, 429 as its priority and fairness does, 410 Expired for a continue token it was told to have lost, a listing of the objects' metadata alone when it is asked for that, can be slow to answer, and records every request it was sent.
ldaptest
Package ldaptest is a stand-in LDAP server for the tests of the ldap request type: a TCP server, or a TLS one for ldaps://, with a self-signed certificate whose file it writes, that answers LDAPv3 messages in BER as a directory server does.
Package ldaptest is a stand-in LDAP server for the tests of the ldap request type: a TCP server, or a TLS one for ldaps://, with a self-signed certificate whose file it writes, that answers LDAPv3 messages in BER as a directory server does.
model
Package model holds the data the other packages share: the configuration as it is written (Config, Collector and the types under them), the static target file, and the metrics a probe produces (MetricSet).
Package model holds the data the other packages share: the configuration as it is written (Config, Collector and the types under them), the static target file, and the metrics a probe produces (MetricSet).
pagekit
Package pagekit is what the HTML pages of the exporter and of the target allocator share, so the two look and behave alike: the stylesheet and its light and dark colours, the theme picker and the script that applies the theme chosen before a page is first drawn, the project's logo as the browser-tab icon, the pages' Content-Security-Policy, the controls of a page that refreshes itself, and how a page writes a duration.
Package pagekit is what the HTML pages of the exporter and of the target allocator share, so the two look and behave alike: the stylesheet and its light and dark colours, the theme picker and the script that applies the theme chosen before a page is first drawn, the project's logo as the browser-tab icon, the pages' Content-Security-Policy, the controls of a page that refreshes itself, and how a page writes a duration.
redistest
Package redistest is a stand-in Redis server for the tests of the redis request type: a TCP server, or a TLS one with a self-signed certificate whose file it writes, that answers RESP2 commands as Redis and Valkey do.
Package redistest is a stand-in Redis server for the tests of the redis request type: a TCP server, or a TLS one with a self-signed certificate whose file it writes, that answers RESP2 commands as Redis and Valkey do.
sqltest
Package sqltest is a stand-in database for the tests of the sql request type: a database/sql/driver implementation that answers each statement with the rows a test gave it, and records what the exporter asked of it — the transactions it began and how, the statements it ran before the query, the values it bound, the connections it opened and closed, the pings.
Package sqltest is a stand-in database for the tests of the sql request type: a database/sql/driver implementation that answers each statement with the rows a test gave it, and records what the exporter asked of it — the transactions it began and how, the statements it ran before the query, the values it bound, the connections it opened and closed, the pings.
sshtest
Package sshtest is an in-process SSH server with an SFTP subsystem, for the sshfile request type's tests, which runs commands too, for the sshexec type's: it serves the exporter's own filesystem, so a test writes files to a temporary directory and reads them over SFTP by their absolute paths, and it hands each command to the test's Options.Exec, which writes its output and says its exit status.
Package sshtest is an in-process SSH server with an SFTP subsystem, for the sshfile request type's tests, which runs commands too, for the sshexec type's: it serves the exporter's own filesystem, so a test writes files to a temporary directory and reads them over SFTP by their absolute paths, and it hands each command to the test's Options.Exec, which writes its output and says its exit status.
testutil
Package testutil holds the helpers the tests of several packages share: temporary files, a minimal collector and configuration, captured logs and polling.
Package testutil holds the helpers the tests of several packages share: temporary files, a minimal collector and configuration, captured logs and polling.
testutil/alloctest
Package alloctest measures what a function allocates, for the tests that bound it or compare it with what another function allocates.
Package alloctest measures what a function allocates, for the tests that bound it or compare it with what another function allocates.
testutil/tier
Package tier splits the tests into two tiers: the quick one, which `make test-quick` runs (go test -short) while a change is being written, and the whole suite, which `make test` and CI run.
Package tier splits the tests into two tiers: the quick one, which `make test-quick` runs (go test -short) while a change is being written, and the whole suite, which `make test` and CI run.
transform
Package transform turns decoded data into metrics with a collector's metric rules — jq, yq, XPath, CSS, CSV, regex and Prometheus pass-through — or with a Python script, run in a pool of worker processes.
Package transform turns decoded data into metrics with a collector's metric rules — jq, yq, XPath, CSS, CSV, regex and Prometheus pass-through — or with a Python script, run in a pool of worker processes.
tools
depupdate command
Command depupdate proposes updates for the versions the Dockerfile pins.
Command depupdate proposes updates for the versions the Dockerfile pins.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL