Giter Club home page Giter Club logo

prometheus-nats-exporter's Introduction

License Build Coverage

The Prometheus NATS Exporter

The Prometheus NATS Exporter consists of both a both a package and 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.

Build

go build

Run

Start the prometheus-nats-exporter executable, and poll the varz metrics endpoints of the NATS server located on localhost configured with a monitor port of 5555.

prometheus-nats-exporter -varz "http://localhost:5555"

Usage

prometheus-nats-exporter <flags> url

Flags must include at least one of: -varz, -connz, -routez, -subz

Usage of prometheus-nats-exporter:
  -D	Enable debug log level.
  -DV   Enable debug and trace log levels.
  -V	Enable trace log level.
  -a string
    	Network host to listen on. (default "0.0.0.0")
  -addr string
    	Network host to listen on. (default "0.0.0.0")
  -connz
    	Get connection metrics.        
  -l string
    	Log file name.
  -log string
    	Log file name.
  -p int
    	Prometheus port to listen on. (default 7777)
  -port int
    	Prometheus port to listen on. (default 7777)
  -r string
    	Remote syslog address to write log statements.
  -remote_syslog string
    	Write log statements to a remote syslog.
  -ri int
    	Interval in seconds to retry NATS Server monitor URLS. (default 30)
  -routez 
        Get route metrics.        
  -s	  Write log statements to the syslog.
  -subz 
        Get subscription metrics.
  -syslog 
        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).  
  -varz
        Get general metrics. 

The URL parameter

The url parameter is a standard url, with an optional tag prefix delimited by a comma. Both http and https (when TLS is configured) is supported.

<tag>,<url>

This adds a tag identified as server-id into the prometheus metrics allowing you to identify the server by a convenient name.

e.g. production-denver-1,http://denver1.foobar.com:8222

Monitoring

The NATS Prometheus exporter exposes metrics through an HTTP interface, and will default to http://0.0.0.0:7777/metrics.

It will return output that is readable by Prometheus.

The returned data looks like this:

# HELP gnatsd_varz_in_bytes in_bytes
# TYPE gnatsd_varz_in_bytes gauge
gnatsd_varz_in_bytes{server_id="production-denver-1"} 0
# HELP gnatsd_varz_in_msgs in_msgs
# TYPE gnatsd_varz_in_msgs gauge
gnatsd_varz_in_msgs{server_id="production-denver-1"} 0
# HELP gnatsd_varz_max_connections max_connections
# TYPE gnatsd_varz_max_connections gauge
gnatsd_varz_max_connections{server_id="production-denver-1"} 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 (
	  "github.com/nats-io/prometheus-nats-exporter/exporter"
	)

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"
	opts.NATSServerTag = "myserver"

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

	// start collecting data
	exp.Start()

	// when done, simply call Stop()
	exp.Stop()

	// For convenience, you can block until the exporter is stopped
	exp.WaitUntilDone()

Monitoring Walkthrough

For further information, refer to the walkthough of monitoring NATS with Prometheus and Grafana.

prometheus-nats-exporter's People

Contributors

laugimethods avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.