send-metric-to-prometheus

module
v0.0.0-...-9af6084 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: GPL-3.0

README

send-metric-to-prometheus

send metric to prometheus

  1. prometheus must enable remote write receiver(https://prometheus.io/docs/prometheus/latest/storage/#remote-storage-integrations)
The built-in remote write receiver can be enabled by setting the --web.enable-remote-write-receiver command line flag. When enabled, the remote write receiver endpoint is /api/v1/write.

for example

./prometheus --web.enable-remote-write-receiver
  1. send date to prometheus
package main

import (
	"github.com/AlaxLee/send-metric-to-prometheus/sender"
	"github.com/prometheus/prometheus/prompb"
	"time"
)

func main() {
	url := "http://127.0.0.1:9090/api/v1/write"
	s, err := sender.NewSender(url)
	if err != nil {
		panic(err)
	}

	d := sender.Data{
		Metric: prompb.MetricMetadata{Type: prompb.MetricMetadata_GAUGE, MetricFamilyName: "lalilulelo"},
		Lables: []prompb.Label{
			{Name: "kaka", Value: "keke"},
		},
		Samples: []prompb.Sample{
			{Value: 7, Timestamp: time.Now().UnixMilli()},
		},
	}
	err = s.Send(d)
	if err != nil {
		panic(err)
	}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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