prometheus

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

README

Prometheus Metrics

This is a go-os/metrics plugin for prometheus. It pushes metrics on a flush interval to the pushgateway. It operates in the same manner as other metrics plugins.

Usage

package main

import (
	"fmt"
	"time"

	"github.com/micro/go-os/metrics"
	"github.com/micro/go-plugins/metrics/prometheus"
)

func main() {
	// create new metrics
	m := prometheus.NewMetrics(
		metrics.Namespace("io_micro"),
		metrics.WithFields(metrics.Fields{
			"region":  "eu-west-1",
			"service": "foo",
		}),
		metrics.Collectors(
			// pushgateway url
			"http://127.0.0.1:9090",
		),
	)

	defer m.Close()

	c := m.Counter("example_counters_foo")
	g := m.Gauge("example_gauges_foo")
	h := m.Histogram("example_histograms_foo")

	for i := 0; i < 100; i++ {
		fmt.Println(time.Now().String(), "Sending metrics")
		c.Incr(uint64(i))
		g.Set(int64(i))
		h.Record(time.Now().Unix() * 1e3)
		time.Sleep(time.Second)
	}

	time.Sleep(time.Second * 5)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMetrics

func NewMetrics(opts ...metrics.Option) metrics.Metrics

Types

This section is empty.

Jump to

Keyboard shortcuts

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