Documentation ¶
Overview ¶
Package prometheus provides a prometheus surfacer for Cloudprober. Prometheus surfacer exports incoming metrics over a web interface in a format that prometheus understands (http://prometheus.io).
This surfacer processes each incoming EventMetrics and holds the latest value and timestamp for each metric in memory. These metrics are made available through a web URL (default: /metrics), which Prometheus scrapes at a regular interval.
Example /metrics page: #TYPE sent counter sent{ptype="dns",probe="vm-to-public-dns",dst="8.8.8.8"} 181299 1497330037000 sent{ptype="ping",probe="vm-to-public-dns",dst="8.8.4.4"} 362600 1497330037000 #TYPE rcvd counter rcvd{ptype="dns",probe="vm-to-public-dns",dst="8.8.8.8"} 181234 1497330037000 rcvd{ptype="ping",probe="vm-to-public-dns",dst="8.8.4.4"} 362600 1497330037000
Index ¶
Constants ¶
const ( ValidMetricNameRegex = "^[a-zA-Z_:]([a-zA-Z0-9_:])*$" ValidLabelNameRegex = "^[a-zA-Z_]([a-zA-Z0-9_])*$" )
Prometheus metric and label names should match the following regular expressions. Since, "-" is commonly used in metric and label names, we replace it by "_". If a name still doesn't match the regular expression, we ignore it with a warning log message.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PromSurfacer ¶
type PromSurfacer struct {
// contains filtered or unexported fields
}
PromSurfacer implements a prometheus surfacer for Cloudprober. PromSurfacer organizes metrics into a two-level data structure:
- Metric name -> PromMetric data structure dict.
- A PromMetric organizes data associated with a metric in a Data key -> Data point map, where data point consists of a value and timestamp.
Data key represents a unique combination of metric name and labels.
func New ¶
func New(config *configpb.SurfacerConf, l *logger.Logger) (*PromSurfacer, error)
New returns a prometheus surfacer based on the config provided. It sets up a goroutine to process both the incoming EventMetrics and the web requests for the URL handler /metrics.
func (*PromSurfacer) Write ¶
func (ps *PromSurfacer) Write(_ context.Context, em *metrics.EventMetrics)
Write queues the incoming data into a channel. This channel is watched by a goroutine that actually processes the data and updates the in-memory database.