prometheus

package module
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package prometheus 提供 metricsx 的 Prometheus 后端: 通过 WithPrometheus 注入 metricsx.New,懒创建 CounterVec / HistogramVec / GaugeVec,统一命名与标签。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Gather

func Gather(m *metricsx.Metrics) ([]*dto.MetricFamily, error)

Gather 返回后端注册表全部指标快照。

func HTTPHandler added in v1.6.3

func HTTPHandler(m *metricsx.Metrics) http.Handler

HTTPHandler 返回导出 Prometheus 文本格式的 http.Handler。 后端不是 Prometheus 时返回 500 错误处理器,避免业务侧直接依赖 prometheus/client_golang。

func Registry

func Registry(m *metricsx.Metrics) (prometheus.Registerer, bool)

Registry 返回后端注册表;后端不是 Prometheus 时返回 false。

func WithPrometheus

func WithPrometheus(opts ...Option) metricsx.Option

WithPrometheus 返回注入 Prometheus 后端的 metricsx 选项。

Types

type Option

type Option func(*sinkConfig)

Option 修改 Prometheus 后端配置。

func WithBuckets

func WithBuckets(buckets []float64) Option

WithBuckets 设置 ObserveDuration 的直方图分桶,空串表示使用默认。

func WithNamespace

func WithNamespace(ns string) Option

WithNamespace 设置指标命名空间前缀(如 "myapp"),空串表示无前缀。

func WithRegistry

func WithRegistry(r prometheus.Registerer) Option

WithRegistry 注入注册表,默认 prometheus.DefaultRegisterer。

Jump to

Keyboard shortcuts

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