Example #1
0
// prometheusPushClient pushs metrics to Prometheus Pushgateway.
func prometheusPushClient(job, addr string, interval time.Duration) {
	for {
		err := push.FromGatherer(
			job, push.HostnameGroupingKey(),
			addr,
			prometheus.DefaultGatherer,
		)
		if err != nil {
			log.Errorf("could not push metrics to Prometheus Pushgateway: %v", err)
		}

		time.Sleep(interval)
	}
}
Example #2
0
// PrometheusPushClient pushs metrics to Prometheus Pushgateway.
func prometheusPushClient(addr string, interval time.Duration) {
	// TODO: TiDB do not have uniq name, so we use host+port to compose a name.
	job := "tidb"
	for {
		err := push.FromGatherer(
			job, push.HostnameGroupingKey(),
			addr,
			prometheus.DefaultGatherer,
		)
		if err != nil {
			log.Errorf("could not push metrics to Prometheus Pushgateway: %v", err)
		}
		time.Sleep(interval)
	}
}
Example #3
0
func ExampleRegistry() {
	registry := prometheus.NewRegistry()

	completionTime := prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "db_backup_last_completion_timestamp_seconds",
		Help: "The timestamp of the last succesful completion of a DB backup.",
	})
	registry.MustRegister(completionTime)

	completionTime.Set(float64(time.Now().Unix()))
	if err := push.FromGatherer(
		"db_backup", push.HostnameGroupingKey(),
		"http://pushgateway:9091",
		registry,
	); err != nil {
		fmt.Println("Could not push completion time to Pushgateway:", err)
	}
}