Documentation ¶
Overview ¶
Package metrics is a system-independent module it consider metrics key as first-class citizen each function is for recording one kind of metrics key and value it expose standard API to record runtime metrics for a service use prom as default metrics system
Index ¶
- Constants
- Variables
- func Init() error
- func RecordLatency(labelValues map[string]string, latency float64)
- func RecordStartTime(labelValues map[string]string, start time.Time)
- func RecordStatus(labelValues map[string]string, statusCode int)
- type Options
- type PromRecorder
- type PrometheusExporter
- func (s *PrometheusExporter) Count(name string, labelNames []string, labels prometheus.Labels)
- func (s *PrometheusExporter) Gauge(name string, val float64, labelNames []string, labels prometheus.Labels)
- func (s *PrometheusExporter) Summary(name string, val float64, labelNames []string, labels prometheus.Labels)
- type PrometheusMesherSinker
Constants ¶
const ( LTotalRequest = "requests_total" LTotalSuccess = "successes_total" LTotalFailures = "failures_total" LRequestLatencySeconds = "request_latency_seconds" LError4XX = "status_4xx" LError5XX = "status_5xx" LServiceName = "service_name" LApp = "app" LVersion = "version" LStartTime = "start_time_seconds" )
Constants with attributes for metrics data Label start with word "L"
Variables ¶
var ( //LabelNames is a fixed list with service name, appID, version LabelNames = []string{LServiceName, LApp, LVersion} )
Functions ¶
func RecordLatency ¶
RecordLatency record an operation latency
func RecordStartTime ¶
RecordStartTime record mesher start time
func RecordStatus ¶
RecordStatus record an operation status
Types ¶
type Options ¶
type Options struct {
LabelNames []string //default label names, if RecordOptions LabelNames is nil
}
Options define recorder options
type PromRecorder ¶ added in v1.7.0
type PromRecorder struct {
LabelNames []string
}
PromRecorder record metrics
func NewPromRecorder ¶
func NewPromRecorder(opts *Options) (*PromRecorder, error)
NewPromRecorder return a prom recorder
func (*PromRecorder) RecordLatency ¶ added in v1.7.0
func (e *PromRecorder) RecordLatency(LabelValues map[string]string, latency float64)
RecordLatency record operation latency
func (*PromRecorder) RecordStartTime ¶ added in v1.7.0
func (e *PromRecorder) RecordStartTime(LabelValues map[string]string, start time.Time)
RecordStartTime save start time
func (*PromRecorder) RecordStatus ¶ added in v1.7.0
func (e *PromRecorder) RecordStatus(LabelValues map[string]string, statusCode int)
RecordStatus record different metrics based on status
type PrometheusExporter ¶
type PrometheusExporter struct {
// contains filtered or unexported fields
}
PrometheusExporter struct has attributes for prometheus data
func GetPrometheusExporter ¶
func GetPrometheusExporter() *PrometheusExporter
GetPrometheusExporter returns default prometheus exporter
func (*PrometheusExporter) Count ¶
func (s *PrometheusExporter) Count(name string, labelNames []string, labels prometheus.Labels)
Count function returns count
func (*PrometheusExporter) Gauge ¶
func (s *PrometheusExporter) Gauge(name string, val float64, labelNames []string, labels prometheus.Labels)
Gauge function
func (*PrometheusExporter) Summary ¶
func (s *PrometheusExporter) Summary(name string, val float64, labelNames []string, labels prometheus.Labels)
Summary function
type PrometheusMesherSinker ¶
type PrometheusMesherSinker struct {
PromRegistry prometheus.Registerer //Prometheus registry
}
PrometheusMesherSinker is the struct for prometheus configuration parameters
var ( //DefaultPrometheusExporter stores value of default prometheus exporter type DefaultPrometheusExporter = GetPrometheusExporter() //DefaultPrometheusSinker stores value of default prometheus exporter type DefaultPrometheusSinker *PrometheusMesherSinker )