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, opts *RecordOptions)
- func RecordStartTime(labelValues map[string]string, start time.Time, opts *RecordOptions)
- func RecordStatus(labelValues map[string]string, statusCode int, opts *RecordOptions)
- type Options
- 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
- type RecordOptions
- type Recorder
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 ¶
func RecordLatency(labelValues map[string]string, latency float64, opts *RecordOptions)
RecordLatency record an operation latency
func RecordStartTime ¶
func RecordStartTime(labelValues map[string]string, start time.Time, opts *RecordOptions)
RecordStartTime record app start time
func RecordStatus ¶
func RecordStatus(labelValues map[string]string, statusCode int, opts *RecordOptions)
RecordStatus record an operation status
Types ¶
type Options ¶
type Options struct {
LabelNames []string //default label names, if RecordOptions LabelNames is nil
EnableGoRuntimeMetrics bool
}
Options define recorder options
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 )
type RecordOptions ¶
type RecordOptions struct {
LabelNames []string // able top custom label names
}
RecordOptions is options for record method
type Recorder ¶
type Recorder interface {
RecordStatus(labelValues map[string]string, status int, opts *RecordOptions)
RecordLatency(labelValues map[string]string, latency float64, opts *RecordOptions)
RecordStartTime(labelValues map[string]string, start time.Time, opts *RecordOptions)
}
Recorder export the metrics into various of system
func NewPromRecorder ¶
NewPromRecorder return a prom recorder