github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/core/raftlease/metrics.go (about) 1 // Copyright 2018 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package raftlease 5 6 import ( 7 "github.com/prometheus/client_golang/prometheus" 8 ) 9 10 const ( 11 metricsNamespace = "juju_raftlease" 12 ) 13 14 // metricsCollector is a prometheus.Collector that collects metrics 15 // about lease store operations. 16 type metricsCollector struct { 17 requests *prometheus.SummaryVec 18 } 19 20 func newMetricsCollector() *metricsCollector { 21 return &metricsCollector{ 22 requests: prometheus.NewSummaryVec(prometheus.SummaryOpts{ 23 Namespace: "juju_raftlease", 24 Name: "request", 25 Help: "Request times for lease store operations in ms", 26 Objectives: map[float64]float64{ 27 0.5: 0.05, 28 0.9: 0.01, 29 0.99: 0.001, 30 }, 31 }, []string{ 32 "operation", // claim, extend, pin, unpin or settime 33 "result", // success, failure, timeout or error 34 }), 35 } 36 } 37 38 // Describe is part of prometheus.Collector. 39 func (c *metricsCollector) Describe(ch chan<- *prometheus.Desc) { 40 c.requests.Describe(ch) 41 } 42 43 // Collect is part of prometheus.Collector. 44 func (c *metricsCollector) Collect(ch chan<- prometheus.Metric) { 45 c.requests.Collect(ch) 46 }