prometheus

package
v1.0.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2018 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metrics

type Metrics struct{}

Metrics prototypes Example:

Counter      *prometheus.CounterVec
ResponseTime *prometheus.HistogramVec

func NewMetrics

func NewMetrics(version, hash, buildTime string) *Metrics

Method for creation new custom Prometheus metrics Example:

	pm := &Metrics{
		Counter: prometheus.NewCounterVec(
			prometheus.CounterOpts{
				Name:        "servicename_requests_total",
				Help:        "Description",
				ConstLabels: map[string]string{
					"version":   version,
					"hash":      hash,
					"buildTime": buildTime,
				},
			},
			[]string{"endpoint"},
		),
		ResponseTime: prometheus.NewHistogramVec(
			prometheus.HistogramOpts{
				Name:        "servicename_response_time_seconds",
				Help:        "Description",
				ConstLabels: map[string]string{
					"version":   version,
					"hash":      hash,
					"buildTime": buildTime,
				},
			},
			[]string{"endpoint"},
		),
	}
	prometheus.Register(pm.Counter)
 prometheus.Register(pm.ResponseTime)

type MetricsManager

type MetricsManager struct {
	// contains filtered or unexported fields
}

func NewMetricsManager

func NewMetricsManager(version, hash, buildTime string) *MetricsManager

func (*MetricsManager) ServeHTTP

func (pmm *MetricsManager) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Main middleware method to collect metrics for Prometheus. Example:

start := time.Now()
next(rw, r)
Request counter metric
pmm.prometheusMetrics.Counter.WithLabelValues(r.URL.Path).Inc()
Response time metric
pmm.prometheusMetrics.ResponseTime.WithLabelValues(r.URL.Path).Observe(time.Since(start).Seconds())

Jump to

Keyboard shortcuts

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