Documentation
¶
Index ¶
Constants ¶
const Namespace = "inventory"
Namespace is the namespace component of the fully qualified metric name
Variables ¶
var ( // TaskSuccessfulTotal is a metric, which gets incremented each time a // task has been successfully executed. TaskSuccessfulTotal = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, Name: "task_successful_total", Help: "Total number of times a task has been successfully executed", }, []string{"task_name", "task_queue"}, ) // TaskFailedTotal is a metric, which gets incremented each time a task // has failed. TaskFailedTotal = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, Name: "task_failed_total", Help: "Total number of times a task has failed", }, []string{"task_name", "task_queue"}, ) // TaskSkippedTotal is a metric, which gets incremented each time a task // has failed and will be skipped from being retried. TaskSkippedTotal = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, Name: "task_skipped_total", Help: "Total number of times a task has been skipped from being retried", }, []string{"task_name", "task_queue"}, ) // TaskDurationSeconds is a metric, which tracks the duration of task // execution in seconds. TaskDurationSeconds = prometheus.NewHistogramVec( prometheus.HistogramOpts{ Namespace: Namespace, Name: "task_duration_seconds", Help: "Duration of task execution in seconds", Buckets: []float64{1.0, 10.0, 30.0, 60.0, 120.0}, }, []string{"task_name", "task_queue"}, ) )
var DefaultCollector = NewCollector()
DefaultCollector is the default Collector for metrics.
var DefaultRegistry = prometheus.NewPedanticRegistry()
DefaultRegistry is the default prometheus.Registry for metrics.
Functions ¶
func Key ¶
Key is a utility function, which derives a key from the given items. The derived key can be used as an `idempotency key' for metrics when adding them via Collector.AddMetric.
func NewServer ¶
NewServer returns a new http.Server which can serve the metrics from DefaultRegistry on the specified network address and HTTP path. Callers are responsible for starting up and shutting down the HTTP server.
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector is an implementation of the prometheus.Collector interface.
This custom collector addresses some shortcomings of the upstream prometheus.GaugeVec collector. Check the documentation below for more details.
The upstream prometheus.GaugeVec is not suitable for metrics reported by Inventory tasks such as reporting number of collected resources, primarily because prometheus.GaugeVec "remembers" any previously emitted metrics.
Suppose we have a task which reports the number of collected AWS EC2 instances, partitioned by VPC. Such a task would represent the metric as a gauge, because the number of EC2 instances may go up and down.
Example metrics might look like this when exposed:
# HELP aws_vpc_instances Number of EC2 instances in VPC.
# TYPE aws_vpc_instances gauge
aws_vpc_instances{vpc_name="vpc-1"} 42.0
aws_vpc_instances{vpc_name="vpc-2"} 10.0
When using prometheus.GaugeVec these metrics will be retained and reported indefinitely, even if we never collect any instances from the above AWS VPCs, e.g. VPCs are no longer existing, because we have deleted them.
In other words the prometheus.GaugeVec represents the last-known value of the metric, as opposed to the latest value.
This property makes prometheus.GaugeVec not suitable for some of the Inventory tasks, which collect resources, because we want our metric to represent the latest value.
func (*Collector) AddDesc ¶
func (c *Collector) AddDesc(items ...*prometheus.Desc)
AddDesc adds the given prometheus.Desc to the Collector.
func (*Collector) AddMetric ¶
func (c *Collector) AddMetric(key string, metric prometheus.Metric)
AddMetric adds the given prometheus.Metric to the Collector. The metric will then be exposed by the Collector during scraping.
The `key' is an `idempotency key', which associates a given metric and its label values with the internal Collector registry.
It is up to the caller to use the same `idempotency key' for the same metric and label values, so that duplicate metrics are not reported by the collector.
func (*Collector) Collect ¶
func (c *Collector) Collect(ch chan<- prometheus.Metric)
Collect implements the prometheus.Collector interface.
func (*Collector) Describe ¶
func (c *Collector) Describe(ch chan<- *prometheus.Desc)
Describe implements the prometheus.Collector interface.