metrics

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 7 Imported by: 0

README

metrics

gin metrics library, collect five metrics, uptime, http_request_count_total, http_request_duration_seconds, http_request_size_bytes, http_response_size_bytes.


Example of use

	import "gitee.com/the_sun_light/common_pkg/gin/middleware/metrics"

	r := gin.Default()

	r.Use(metrics.Metrics(
		r,
		//metrics.WithMetricsPath("/demo/metrics"), // default is /metrics
		metrics.WithIgnoreStatusCodes(http.StatusNotFound), // ignore status codes
		//metrics.WithIgnoreRequestMethods(http.MethodHead),  // ignore request methods
		//metrics.WithIgnoreRequestPaths("/ping", "/health"), // ignore request paths
	))

Metrics

Details about exposed Prometheus metrics.

Name Type Exposed Information
gin_uptime Counter HTTP service uptime.
gin_http_request_count_total Counter Total number of HTTP requests made.
gin_http_request_duration_seconds Histogram HTTP request latencies in seconds.
gin_http_request_size_bytes Summary HTTP request sizes in bytes.
gin_http_response_size_bytes Summary HTTP response sizes in bytes.

Grafana charts

import gin_grafana.json to your grafana, datasource name is Prometheus, change the name of the datasource according to your actual datasource.

metrics

Documentation

Overview

Package metrics is gin metrics library, collect five metrics, "uptime", "http_request_count_total", "http_request_duration_seconds", "http_request_size_bytes", "http_response_size_bytes".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Metrics

func Metrics(r *gin.Engine, opts ...Option) gin.HandlerFunc

Metrics returns a gin.HandlerFunc for exporting some Web metrics

Types

type Option

type Option func(*options)

Option set the metrics options.

func WithIgnoreRequestMethods

func WithIgnoreRequestMethods(methods ...string) Option

WithIgnoreRequestMethods ignore request methods

func WithIgnoreRequestPaths

func WithIgnoreRequestPaths(paths ...string) Option

WithIgnoreRequestPaths ignore request paths

func WithIgnoreStatusCodes

func WithIgnoreStatusCodes(statusCodes ...int) Option

WithIgnoreStatusCodes ignore status codes

func WithMetricsPath

func WithMetricsPath(metricsPath string) Option

WithMetricsPath set metrics path

Jump to

Keyboard shortcuts

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