goframe_prometheus

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 10 Imported by: 0

README

goframe-prometheus

Prometheus metrics exporter for goframe.

该版本基于ginprom,适用于goframe框架

📝 Usage
package main

import (
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/prometheus/client_golang/prometheus/promhttp"
	goframePrometheus "github.com/qiuyier/goframe-prometheus"
)

func main() {
	s := g.Server()

	// 注册metrics路由
	s.BindHandler("/metrics", goframePrometheus.PromAdapter(promhttp.Handler()))

	s.Group("/", func(group *ghttp.RouterGroup) {
		// 注册中间件,收集信息
		group.Middleware(goframePrometheus.PromMiddleWare)

		group.ALL("/hello", func(r *ghttp.Request) {
			r.Response.Write("hello, world!")
		})
	})

	s.SetPort(8000)
	s.Run()

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PromAdapter

func PromAdapter(handler http.Handler) ghttp.HandlerFunc

PromAdapter wrappers the standard http.Handler to ghttp.HandlerFunc

func PromMiddleWare

func PromMiddleWare(r *ghttp.Request)

PromMiddleWare a middleware for exporting some Web metrics

Types

type PromOpts

type PromOpts struct {
	ExcludeRegexStatus     string
	ExcludeRegexEndpoint   string
	ExcludeRegexMethod     string
	EndpointLabelMappingFn RequestLabelMappingFn
}

PromOpts represents the Prometheus middleware Options. It is used for filtering labels by regex.

func NewDefaultOpts

func NewDefaultOpts() *PromOpts

NewDefaultOpts return the default ProOpts

type RequestLabelMappingFn

type RequestLabelMappingFn func(c *ghttp.Request) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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