push

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package push provides functions to push metrics to a Pushgateway. The metrics to push are either collected from a provided registry, or from explicitly listed collectors.

See the documentation of the Pushgateway to understand the meaning of the grouping parameters and the differences between push.Registry and push.Collectors on the one hand and push.AddRegistry and push.AddCollectors on the other hand: https://github.com/prometheus/pushgateway

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCollectors

func AddCollectors(job string, grouping map[string]string, url string, collectors ...prometheus.Collector) error

AddCollectors works like AddFromGatherer, but it does not use a Gatherer. Instead, it collects from the provided collectors directly. It is a convenient way to push only a few metrics.

func AddFromGatherer

func AddFromGatherer(job string, grouping map[string]string, url string, g prometheus.Gatherer) error

AddFromGatherer works like FromGatherer, but only previously pushed metrics with the same name (and the same job and other grouping labels) will be replaced. (It uses HTTP method 'POST' to push to the Pushgateway.)

func Collectors

func Collectors(job string, grouping map[string]string, url string, collectors ...prometheus.Collector) error

Collectors works like FromGatherer, but it does not use a Gatherer. Instead, it collects from the provided collectors directly. It is a convenient way to push only a few metrics.

Example
package main

import (
	"fmt"
	"time"

	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/push"
)

func main() {
	completionTime := prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "db_backup_last_completion_timestamp_seconds",
		Help: "The timestamp of the last succesful completion of a DB backup.",
	})
	completionTime.Set(float64(time.Now().Unix()))
	if err := push.Collectors(
		"db_backup", push.HostnameGroupingKey(),
		"http://pushgateway:9091",
		completionTime,
	); err != nil {
		fmt.Println("Could not push completion time to Pushgateway:", err)
	}
}
Output:

func FromGatherer

func FromGatherer(job string, grouping map[string]string, url string, g prometheus.Gatherer) error

FromGatherer triggers a metric collection by the provided Gatherer (which is usually implemented by a prometheus.Registry) and pushes all gathered metrics to the Pushgateway specified by url, using the provided job name and the (optional) further grouping labels (the grouping map may be nil). See the Pushgateway documentation for detailed implications of the job and other grouping labels. Neither the job name nor any grouping label value may contain a "/". The metrics pushed must not contain a job label of their own nor any of the grouping labels.

You can use just host:port or ip:port as url, in which case 'http://' is added automatically. You can also include the schema in the URL. However, do not include the '/metrics/jobs/...' part.

Note that all previously pushed metrics with the same job and other grouping labels will be replaced with the metrics pushed by this call. (It uses HTTP method 'PUT' to push to the Pushgateway.)

func HostnameGroupingKey

func HostnameGroupingKey() map[string]string

HostnameGroupingKey returns a label map with the only entry {instance="<hostname>"}. This can be conveniently used as the grouping parameter if metrics should be pushed with the hostname as label. The returned map is created upon each call so that the caller is free to add more labels to the map.

Types

This section is empty.

Jump to

Keyboard shortcuts

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