Documentation ¶
Overview ¶
Package metrics implements datakit's Prometheus metrics
Index ¶
- func Gather() ([]*dto.MetricFamily, error)
- func GetMetric(mfs []*dto.MetricFamily, name string, idx int) *dto.Metric
- func GetMetricOnLabels(mfs []*dto.MetricFamily, name string, wanted ...string) *dto.Metric
- func HTTPGinHandler(opt promhttp.HandlerOpts) gin.HandlerFunc
- func MetricFamily2Text(mfs []*dto.MetricFamily) string
- func MustAddGolangMetrics()
- func MustGather() []*dto.MetricFamily
- func MustRegister(c ...prometheus.Collector)
- func Register(c prometheus.Collector) error
- func Unregister(c prometheus.Collector) bool
- type MetricServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Gather ¶
func Gather() ([]*dto.MetricFamily, error)
Gather collect all metrics within global registry.
func GetMetricOnLabels ¶
GetMetricOnLabels search mfs with wanted labels. wanted values order must be same as label names.
func HTTPGinHandler ¶
func HTTPGinHandler(opt promhttp.HandlerOpts) gin.HandlerFunc
HTTPGinHandler wrap promhttp handler as gin hander. We can attach url /metrics to a exist gin router like this:
router := gin.New() router.GET("/metrics", HTTPGinHandler(promhttp.HandlerOpts{}))
func MetricFamily2Text ¶
func MetricFamily2Text(mfs []*dto.MetricFamily) string
MetricFamily2Text convert metrics to text format.
func MustAddGolangMetrics ¶
func MustAddGolangMetrics()
MustAddGolangMetrics enable Golang runtime metrics.
func MustGather ¶
func MustGather() []*dto.MetricFamily
MustGather collect all metrics within global registry and panic on any error.
func MustRegister ¶
func MustRegister(c ...prometheus.Collector)
MustRegister add c to global registry and panic on any error.
func Unregister ¶
func Unregister(c prometheus.Collector) bool
Unregister remove c from global registry.
Types ¶
type MetricServer ¶
type MetricServer struct { // Metrics request path. URL string `toml:"url" json:"url"` // HTTP server address, default to localhost:9090. Listen string `toml:"listen" json:"listen"` // Enable or disable the http server. Enable bool `toml:"enable" json:"enable"` // Enable or disable Golang related metrics in metrics URL. DisableGoMetrics bool `toml:"disable_go_metrics" json:"disable_go_metrics"` }
MetricServer used to export metrics via HTTP /metrics request.
func NewMetricServer ¶
func NewMetricServer() *MetricServer
NewMetricServer create default metric server.
func (*MetricServer) Start ¶
func (ms *MetricServer) Start() error
Start create HTTP server to serving /metrics request.