コード例 #1
0
ファイル: metricutil.go プロジェクト: pingcap/tidb
// 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)
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: jmptrader/tidb
// 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)
	}
}
コード例 #3
0
ファイル: examples_test.go プロジェクト: Griesbacher/nagflux
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)
	}
}