prometheus

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

README

HTTPServer Prometheus Observability 包

httpserver/observability/prometheus 提供请求计数与延迟统计能力,并通过显式注册的 /metrics 路由暴露指标。

设计约束

  • 不向 httpserver core 自动注册 /metrics
  • 中间件和 metrics 路由可以共享同一个 Collector
  • 默认提供包级 Collector,适合快速接入

快速开始

public := srv.Group("")
srv.Use(prometheus.Middleware())
prometheus.Register(public, prometheus.Config{
	Path: "/metrics",
})

Documentation

Overview

Package prometheus 提供 HTTP 指标中间件与 metrics 路由注册能力。

该包默认不向 httpserver core 注入任何路由;调用方需要显式调用 Register 挂载 metrics 端点。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware() gin.HandlerFunc

Middleware 返回默认 collector 的指标中间件。

func Register

func Register(r gin.IRoutes, config Config)

Register 显式注册 metrics 路由。

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector 保存 HTTP 指标。

func NewCollector

func NewCollector() *Collector

NewCollector 创建新的指标收集器。

func (*Collector) Middleware

func (c *Collector) Middleware() gin.HandlerFunc

Middleware 返回 collector 自身的指标中间件。

type Config

type Config struct {
	Path      string
	Collector *Collector
}

Config 描述 metrics 路由注册配置。

Jump to

Keyboard shortcuts

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