pure

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Author SunJun <i@sjis.me>

Author SunJun <i@sjis.me>

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultMetricPath = "/metrics"
)

Functions

This section is empty.

Types

type AutumnMetric

type AutumnMetric interface {
	// Get the metrics object id
	GetName() string
	// Get the metrics indicator value
	GetValue(...string) float64
	// Get the metrics parameter set
	GetLabels() []string
	// Get the corresponding values ​​of different parameters of metrics
	GetLabelValues() []*LabelValue
	Set(float64, ...string) error
	Incr(...string) error
	Add(float64, ...string) error
}

Metrics object interface, providing metrics metric data operations and obtaining metrics basic information

type CollectorPure

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

func NewPureCollector

func NewPureCollector(subsystem string, path ...string) *CollectorPure

func (*CollectorPure) GetAllMetrics

func (cp *CollectorPure) GetAllMetrics() map[string]AutumnMetric

func (*CollectorPure) GetMetric

func (cp *CollectorPure) GetMetric(id string) (AutumnMetric, bool)

func (*CollectorPure) Handler

func (cp *CollectorPure) Handler() http.HandlerFunc

Complete metrics processor with default metrics in the prometheus library

func (*CollectorPure) ListenAndServe

func (cp *CollectorPure) ListenAndServe(addr string, h func(http.ResponseWriter, *http.Request)) error

start with server

func (*CollectorPure) MetricsHandler

func (cp *CollectorPure) MetricsHandler() http.HandlerFunc

Complete metrics processor with default metrics in the prometheus library

func (*CollectorPure) NewLocalPureMetric

func (cp *CollectorPure) NewLocalPureMetric(name string, labels ...string) *LocalPureMetric

func (*CollectorPure) NewMetric

func (cp *CollectorPure) NewMetric(name string, metricType MetricType, labels ...string) prometheus.Collector

NewMetric associates prometheus.Collector based on Metric.Type

func (*CollectorPure) Register

func (cp *CollectorPure) Register(ams ...AutumnMetric)

func (*CollectorPure) RegisterPrometheus

func (cp *CollectorPure) RegisterPrometheus(pmc ...prometheus.Collector)

func (*CollectorPure) Unregister

func (cp *CollectorPure) Unregister(ids ...string)

func (*CollectorPure) Use

func (cp *CollectorPure) Use(next http.Handler) http.Handler

Middleware handler

func (*CollectorPure) UseAfterHandlerHook

func (cp *CollectorPure) UseAfterHandlerHook(h ...HandlerFunc)

func (*CollectorPure) UseBeforeHandlerHook

func (cp *CollectorPure) UseBeforeHandlerHook(h ...HandlerFunc)

type Context

type Context struct {
	Request        *http.Request
	ResponseWriter *ResponseWriter
	Keys           map[string]interface{}
	// contains filtered or unexported fields
}

func (*Context) Abort

func (c *Context) Abort()

func (*Context) Get

func (c *Context) Get(key string) (value interface{}, exists bool)

Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)

func (*Context) GetBool

func (c *Context) GetBool(key string) (b bool)

GetBool returns the value associated with the key as a boolean.

func (*Context) GetDuration

func (c *Context) GetDuration(key string) (d time.Duration)

GetDuration returns the value associated with the key as a duration.

func (*Context) GetFloat64

func (c *Context) GetFloat64(key string) (f64 float64)

GetFloat64 returns the value associated with the key as a float64.

func (*Context) GetInt

func (c *Context) GetInt(key string) (i int)

GetInt returns the value associated with the key as an integer.

func (*Context) GetInt64

func (c *Context) GetInt64(key string) (i64 int64)

GetInt64 returns the value associated with the key as an integer.

func (*Context) GetString

func (c *Context) GetString(key string) (s string)

GetString returns the value associated with the key as a string.

func (*Context) GetStringMap

func (c *Context) GetStringMap(key string) (sm map[string]interface{})

GetStringMap returns the value associated with the key as a map of interfaces.

func (*Context) GetStringMapString

func (c *Context) GetStringMapString(key string) (sms map[string]string)

GetStringMapString returns the value associated with the key as a map of strings.

func (*Context) GetStringMapStringSlice

func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string)

GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.

func (*Context) GetStringSlice

func (c *Context) GetStringSlice(key string) (ss []string)

GetStringSlice returns the value associated with the key as a slice of strings.

func (*Context) GetTime

func (c *Context) GetTime(key string) (t time.Time)

GetTime returns the value associated with the key as time.

func (*Context) MustGet

func (c *Context) MustGet(key string) interface{}

MustGet returns the value for the given key if it exists, otherwise it panics.

func (*Context) Next

func (c *Context) Next()

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Set is used to store a new key/value pair exclusively for this context. It also lazy initializes c.Keys if it was not used previously.

type HandlerFunc

type HandlerFunc func(*Context)

type HandlerType

type HandlerType int

type LabelValue

type LabelValue struct {
	Value       float64
	LabelsValue []string
}

Metrics labels correspond to different combinations of value values

type LocalPureMetric

type LocalPureMetric struct {
	Name        string
	Type        MetricType
	Labels      []string
	LabelValues map[string]*LabelValue
	// contains filtered or unexported fields
}

func (*LocalPureMetric) Add

func (arm *LocalPureMetric) Add(value float64, labelValues ...string) error

func (*LocalPureMetric) GetLabelValues

func (arm *LocalPureMetric) GetLabelValues() []*LabelValue

func (*LocalPureMetric) GetLabels

func (arm *LocalPureMetric) GetLabels() []string

func (*LocalPureMetric) GetName

func (arm *LocalPureMetric) GetName() string

func (*LocalPureMetric) GetValue

func (arm *LocalPureMetric) GetValue(labelValues ...string) float64

func (*LocalPureMetric) Incr

func (arm *LocalPureMetric) Incr(labelValues ...string) error

func (*LocalPureMetric) Set

func (arm *LocalPureMetric) Set(value float64, labelValues ...string) error

type MetricCollection

type MetricCollection interface {
	// Register metrics
	Register(...AutumnMetric)
	// Register Prometheus native metrics collector
	RegisterPrometheus(...prometheus.Collector)
	// Unregister metrics
	Unregister(...string)
	// Http middleware, Used to collect http indicator information
	Use(http.Handler) http.Handler
	// Get a metrics object
	GetMetric(string) (AutumnMetric, bool)
	// Full metrics interface, return full metrics metrics
	MetricsHandler() http.HandlerFunc
	// Full metrics interface, return full metrics metrics
	Handler() http.HandlerFunc
	// Start the http service and provide the metrics interface
	ListenAndServe(string, func(http.ResponseWriter, *http.Request)) error
	// Add http middleware handler pre hook
	UseBeforeHandlerHook(...HandlerFunc)
	// Add http middleware handler after hook
	UseAfterHandlerHook(...HandlerFunc)
}

Metrics collection interface for registering metrics objects, providing metrics interfaces and services

type MetricType

type MetricType int
const (
	CounterVec MetricType = iota
	Counter
	GaugeVec
	Gauge
	HistogramVec
	Histogram
	SummaryVec
	Summary
)

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func (*ResponseWriter) Size

func (w *ResponseWriter) Size() int

func (*ResponseWriter) Status

func (w *ResponseWriter) Status() int

func (*ResponseWriter) Write

func (w *ResponseWriter) Write(data []byte) (n int, err error)

func (*ResponseWriter) WriteHeader

func (w *ResponseWriter) WriteHeader(statusCode int)

Jump to

Keyboard shortcuts

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