Need help with prometheus-nats-exporter?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

197 Stars 69 Forks Apache License 2.0 206 Commits 30 Opened issues


A Prometheus exporter for NATS metrics

Services available


Need anything else?

Contributors list

License Build Coverage

The Prometheus NATS Exporter

The Prometheus NATS Exporter consists of both a package and an application that exports NATS server metrics to Prometheus for monitoring. The exporter aggregates metrics from the server monitoring endpoints you choose (varz, connz, subsz, routez) from a NATS server into a single Prometheus exporter endpoint.


make build

If you want to run tests, you can do this.

make install-tools
make test
make lint

If you want to see the coverage locally, then run this.

make test-cover


Start the prometheus-nats-exporter executable, and poll the

metrics endpoints of the NATS server located on
configured with a monitor port of
prometheus-nats-exporter -varz "http://localhost:5555"

To run with docker, you can use the following image:

docker run natsio/prometheus-nats-exporter:latest


prometheus-nats-exporter  url
  -D    Enable debug log level.
        Enable debug and trace log levels.
  -V    Enable trace log level.
  -a string
        Network host to listen on. (default "")
  -addr string
        Network host to listen on. (default "")
        Get streaming channel metrics.
        Get connection metrics.
        Get gateway metrics.
        Get leaf metrics.
  -http_pass string
        Set the password for HTTP scrapes. NATS bcrypt supported.
  -http_user string
        Enable basic auth and set user name for HTTP scrapes.
  -jsz string
        Select JetStream metrics to filter (e.g streams, accounts, consumers, all)
  -l string
        Log file name.
  -log string
        Log file name.
  -p int
        Port to listen on. (default 7777)
  -path string
        URL path from which to serve scrapes. (default "/metrics")
  -port int
        Port to listen on. (default 7777)
  -prefix string
        Replace the default prefix for all the metrics.
  -r string
        Remote syslog address to write log statements.
  -remote_syslog string
        Write log statements to a remote syslog.
        Get replicator general metrics.
  -ri int
        Interval in seconds to retry NATS Server monitor URL. (default 30)
        Get route metrics.
  -s    Write log statements to the syslog.
        Get streaming server metrics.
        Get subscription metrics.
        Write log statements to the syslog.
  -tlscacert string
        Client certificate CA for verification (used with HTTPS).
  -tlscert string
        Server certificate file (Enables HTTPS).
  -tlskey string
        Private key for server certificate (used with HTTPS).
        Enables using ServerID from /varz
        Get general metrics.
        Show exporter version and exit.

The URL parameter

The url parameter is a standard url. Both

(when TLS is configured) is supported.



The NATS Prometheus exporter exposes metrics through an HTTP interface, and will default to:


is used, you will need to set the username password in prometheus. See
in the prometheus configuration documentation. If using a bcrypted password use a very low cost as scrapes occur frequently.

It will return output that is readable by Prometheus.

The returned data looks like this: ```text

HELP gnatsdvarzinbytes inbytes

TYPE gnatsdvarzin_bytes gauge

gnatsdvarzinbytes{serverid="http://localhost:8222"} 0

HELP gnatsdvarzinmsgs inmsgs

TYPE gnatsdvarzin_msgs gauge

gnatsdvarzinmsgs{serverid="http://localhost:8222"} 0

HELP gnatsdvarzmaxconnections maxconnections

TYPE gnatsdvarzmax_connections gauge

gnatsdvarzmaxconnections{serverid="http://localhost:8222"} 65536 ```

The NATS Prometheus Exporter API

The NATS prometheus exporter also provides a simple and easy to use API that allows it to run embedded in your code.

Import the exporter package

    // import the API like this
    import (

API Usage

In just a few lines of code, configure and launch an instance of the exporter.

    // Get the default options, and set what you need to.  The listen address and port
    // is how prometheus can poll for collected data.
    opts := exporter.GetDefaultExporterOptions()
    opts.ListenAddress = "localhost"
    opts.ListenPort = 8888
    opts.GetVarz = true
    opts.NATSServerURL = "http://localhost:8222"

// create an exporter instance, ready to be launched.
exp := exporter.NewExporter(opts)

// start collecting data

// when done, simply call Stop()

// For convenience, you can block until the exporter is stopped

Monitoring Walkthrough

For additional information, refer to the walkthrough of monitoring NATS with Prometheus and Grafana. The NATS Prometheus Exporter can be used to monitor NATS Streaming as well. Refer to the walkthrough/streaming documentation.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.