Documentation ¶
Overview ¶
Package metrics implements datakit's Prometheus metrics
Index ¶
- Variables
- func AddLastErr(source, msg string)
- func Gather() ([]*dto.MetricFamily, error)
- func GatherPoints() ([]*point.Point, 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 ResetLastErrors()
- func Unregister(c prometheus.Collector) bool
- type MetricServer
Constants ¶
This section is empty.
Variables ¶
var (
MaxLastErrorCount = int64(128)
)
Functions ¶
func AddLastErr ¶
func AddLastErr(source, msg string)
AddLastErr add error msg to datakit's metric server.
func Gather ¶
func Gather() ([]*dto.MetricFamily, error)
Gather collect all metrics within global registry.
func GatherPoints ¶
GatherPoints gather all metrics in global registry, but convert these metrics to point.Point.
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 ResetLastErrors ¶
func ResetLastErrors()
ResetLastErrors cleanup all metrics within last errors.
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.