monitor

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PromGinHandler

func PromGinHandler() gin.HandlerFunc

PromGinHandler returns prometheus gin handler

func PromHTTPHandler

func PromHTTPHandler() http.Handler

PromHTTPHandler returns prometheus http handler

Types

type Config

type Config struct {
	Namespace      string
	MetricEndpoint string
}

Config describes monitor configuration

type DBHandler

type DBHandler interface {
	//Init(namespace string)
	BeforeExecution(scope *gorm.Scope)
	AfterExecution(scope *gorm.Scope)
}

A DBHandler is a interface used by a Monitor to handle database monitoring handler

type DefaultDBHandler

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

DefaultDBHandler describes a default db monitoring handler

func NewDefaultDBHandler

func NewDefaultDBHandler(namespace string) *DefaultDBHandler

NewDefaultDBHandler new default db handler

func (*DefaultDBHandler) AfterExecution

func (m *DefaultDBHandler) AfterExecution(scope *gorm.Scope)

AfterExecution calculates the execution details

func (*DefaultDBHandler) BeforeExecution

func (m *DefaultDBHandler) BeforeExecution(scope *gorm.Scope)

BeforeExecution is before callback, prepares some useful data for monitoring system

func (*DefaultDBHandler) Init

func (m *DefaultDBHandler) Init(namespace string)

Init inits default db handler

type DefaultHTTPClientHandler

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

DefaultHTTPClientHandler describes a default http client monitoring handler

func NewDefaultHTTPClientHandler

func NewDefaultHTTPClientHandler(namespace string) *DefaultHTTPClientHandler

NewDefaultHTTPClientHandler new default http client handler

func (*DefaultHTTPClientHandler) HandleLatency

func (m *DefaultHTTPClientHandler) HandleLatency(r *http.Response, latency float64)

HandleLatency handles request latency monitoring

func (*DefaultHTTPClientHandler) HandleRequest

func (m *DefaultHTTPClientHandler) HandleRequest(r *http.Request)

HandleRequest handles request monitoring

func (*DefaultHTTPClientHandler) HandleResponse

func (m *DefaultHTTPClientHandler) HandleResponse(r *http.Response)

HandleResponse handles response monitoring

func (*DefaultHTTPClientHandler) Init

func (m *DefaultHTTPClientHandler) Init(namespace string)

Init inits default http client monitor

type DefaultHTTPServerHandler

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

DefaultHTTPServerHandler describes a default http server monitor handler.

func NewDefaultHTTPServerHandler

func NewDefaultHTTPServerHandler(namespace string, metricEndpoint string) *DefaultHTTPServerHandler

NewDefaultHTTPServerHandler new default http server handler

func (*DefaultHTTPServerHandler) HandleLatency

func (m *DefaultHTTPServerHandler) HandleLatency(wi *ResponseWriterInterceptor, latency float64)

HandleLatency handles request latency monitoring

func (*DefaultHTTPServerHandler) HandleRequest

func (m *DefaultHTTPServerHandler) HandleRequest(r *http.Request)

HandleRequest handles request monitoring

func (*DefaultHTTPServerHandler) HandleResponse

func (m *DefaultHTTPServerHandler) HandleResponse(wi *ResponseWriterInterceptor)

HandleResponse handles response monitoring

func (*DefaultHTTPServerHandler) Init

func (m *DefaultHTTPServerHandler) Init(namespace string, metricEndpoint string)

Init inits default http server monitor

type HTTPClientHandler

type HTTPClientHandler interface {
	//	Init(namespace string)
	HandleRequest(r *http.Request)
	HandleResponse(r *http.Response)
	HandleLatency(r *http.Response, latency float64)
}

A HTTPClientHandler is a interface used by a Monitor to handle http client monitoring handler

type HTTPServerHandler

type HTTPServerHandler interface {
	//	Init(namespace string, metricEndpoint string)
	HandleRequest(r *http.Request)
	HandleResponse(r *ResponseWriterInterceptor)
	HandleLatency(r *ResponseWriterInterceptor, latency float64)
}

A HTTPServerHandler is a interface used by a Monitor to handle http server monitoring handler.

type Monitor

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

Monitor describes a monitor based on prometheus

func New

func New(cfg *Config) *Monitor

New new a monitor

func (*Monitor) HTTPHandler

func (m *Monitor) HTTPHandler() http.Handler

HTTPHandler returns an http.Handler for the prometheus Gatherer

func (*Monitor) Handler

func (m *Monitor) Handler() http.Handler

Handler returns an http.Handler for monitoring.

func (*Monitor) ListenAndServe

func (m *Monitor) ListenAndServe(addr string) error

ListenAndServe start a http server that expose metrics endpoint

func (*Monitor) MustRegister

func (m *Monitor) MustRegister(cs ...prometheus.Collector)

MustRegister registers the provided Collectors and panics if any error occurs.

func (*Monitor) NamedCollector

func (m *Monitor) NamedCollector(name string) prometheus.Collector

NamedCollector returns collector with specified name

func (*Monitor) Register

func (m *Monitor) Register(c prometheus.Collector) error

Register registers the provided Collector

func (*Monitor) RegisterWithName

func (m *Monitor) RegisterWithName(name string, c prometheus.Collector) error

RegisterWithName registers the provided Collector with specified name

func (*Monitor) SetDBHandler

func (m *Monitor) SetDBHandler(handler DBHandler)

SetDBHandler sets db monitoring handler

func (*Monitor) SetHTTPClientHandler

func (m *Monitor) SetHTTPClientHandler(handler HTTPClientHandler)

SetHTTPClientHandler sets http client monitoring handler

func (*Monitor) SetHTTPServerHandler

func (m *Monitor) SetHTTPServerHandler(handler HTTPServerHandler)

SetHTTPServerHandler sets http server monitoring handler

func (*Monitor) WrapAndServeDB

func (m *Monitor) WrapAndServeDB(conn *gorm.DB)

WrapAndServeDB warps db connection to get execution statistics

func (*Monitor) WrapAndServeHTTPClient

func (m *Monitor) WrapAndServeHTTPClient(client *http.Client)

WrapAndServeHTTPClient wraps http client transport with monitoring transport.

func (*Monitor) WrapAndServeHTTPServer

func (m *Monitor) WrapAndServeHTTPServer(srv *http.Server)

WrapAndServeHTTPServer wraps http server with promethues collectors

type ResponseWriterInterceptor

type ResponseWriterInterceptor struct {
	http.ResponseWriter

	URL    *url.URL
	Method string
	Body   []byte
	// contains filtered or unexported fields
}

ResponseWriterInterceptor wraps ResponseWriter to get response data

func (*ResponseWriterInterceptor) Write

func (w *ResponseWriterInterceptor) Write(body []byte) (int, error)

func (*ResponseWriterInterceptor) WriteHeader

func (w *ResponseWriterInterceptor) WriteHeader(statusCode int)

WriteHeader overrides ResponseWriter.WriteHeader function to collect status code

type RoundTripWrapper

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

RoundTripWrapper round trip wrapper

func (*RoundTripWrapper) RoundTrip

func (m *RoundTripWrapper) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction, returning a Response for the provided Request. It is used by HTTP client monitor.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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