Documentation ¶
Overview ¶
Package monitoring is a monitor "provider" that provides a way for monitoring. It uses influxdb monitor by default.
Index ¶
- func Context(c context.Context, m Monitor) context.Context
- func WithMonitor(m Monitor) func(h http.Handler) http.Handler
- type InfluxMonitorConfig
- type Monitor
- func ForceContext(ctx context.Context) Monitor
- func NewInfluxdbMonitor(config InfluxMonitorConfig, logger log.Logger) (Monitor, func(), error)
- func NewInfluxdbMonitorWithClient(config InfluxMonitorConfig, logger log.Logger, client influxdb.Client) (Monitor, func(), error)
- func NewLogMonitor(l log.Logger) Monitor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type InfluxMonitorConfig ¶
type InfluxMonitorConfig string
InfluxMonitorConfig type for configuration of Monitor that sinks to InfluxDB
type Monitor ¶
type Monitor interface { InsertRecord(measurement string, value interface{}, tags map[string]string, fields map[string]interface{}, time time.Time) Count(measurement string, value float64, tags map[string]string, fields map[string]interface{}) CountError(measurement string, value float64, err error) CountSimple(measurement string, value float64) }
Monitor defines an interface for inserting record.
func ForceContext ¶
ForceContext extracts a Monitor from a (possibly nil) context, or returns a NewLogMonitor using a log from the context or log.Default()
func NewInfluxdbMonitor ¶
func NewInfluxdbMonitor(config InfluxMonitorConfig, logger log.Logger) (Monitor, func(), error)
NewInfluxdbMonitor creates new monitoring influxdb client. config URL syntax is `https://<username>:<password>@<influxDB host>/<database>?batch-write-interval=timeDuration&buffer-size=number&max-buffer-size=number&service-name=name` batch-write-interval is optional, default is 60s, valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
exec batch write when we haven't sent data since batch-write-interval ago
buffer-size is optional, default is 5000.
if buffered size reach buffer size then exec batch write.
max-buffer-size is optional, default is 10000, it must > buffer-size,
if the batch write fails and buffered size reach max-buffer-size then clean up the buffer (mean the data is lost).
service-name is optional
if set then all points will add tag service=service-name.
The second return value is a function that will cause the batching goroutine to write buffered points, then terminate. This function will block until one attempt to flush the buffer completes (either success or failure).
The third return value will be non-nil if monitorURL is invalid or not absolute.
This function will not return error if InfluxDB is unavailable, but the returned Monitor will log errors if it cannot push metrics into InfluxDB.
func NewLogMonitor ¶
NewLogMonitor creates Monitor that logs metrics to passed log.Logger