prometheus

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2017 License: MIT Imports: 8 Imported by: 0

README

Example Usage

main.go:

package main

import (
  "fmt"
  "math/rand"
  "net/http"
  "time"

  "github.com/uber-go/tally"
  "github.com/uber-go/tally/prometheus"
)

func main() {
  r := prometheus.NewReporter(nil)
  // note the "_" separator. Prometheus doesnt like metrics with "." in them.
  scope, finisher := tally.NewRootScope("prefix", map[string]string{}, r, 1*time.Second, "_")
  defer finisher.Close()

  counter := scope.Counter("test_counter")
  gauge := scope.Gauge("test_gauge")
  histogram := scope.Timer("test_histogram")

  go func() {
    for {
      counter.Inc(1)
      time.Sleep(1000000)
    }
  }()

  go func() {
    for {
      gauge.Update(rand.Float64() * 1000)
      time.Sleep(1000000)
    }
  }()

  go func() {
    for {
      sw := histogram.Start()
      time.Sleep(time.Duration(rand.Float64() * 1000 * 1000))
      sw.Stop()
      time.Sleep(1000000)
    }
  }()

  http.Handle("/metrics", r.HTTPHandler())
  fmt.Printf("Serving :8080/metrics\n")
  fmt.Printf("%v\n", http.ListenAndServe(":8080", nil))
  select {}

}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefaultHistogramObjectives is the default objectives used when creating a new Summary histogram
	// in the prometheus registry.
	// See https://godoc.org/github.com/prometheus/client_golang/prometheus#SummaryOpts
	DefaultHistogramObjectives = map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001, 0.999: 0.0001}
)

Functions

This section is empty.

Types

type Reporter

type Reporter interface {
	tally.StatsReporter
	HTTPHandler() http.Handler
}

Reporter is a prometheus backed tally reporter

func NewReporter

func NewReporter(objectives map[float64]float64) Reporter

NewReporter returns a new Reporter for Prometheus client backed metrics objectives is the objectives used when creating a new Summary histogram for Timers. See https://godoc.org/github.com/prometheus/client_golang/prometheus#SummaryOpts for more details

Jump to

Keyboard shortcuts

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