Tizen_4.0 base
[platform/upstream/docker-engine.git] / vendor / github.com / docker / go-metrics / counter.go
1 package metrics
2
3 import "github.com/prometheus/client_golang/prometheus"
4
5 // Counter is a metrics that can only increment its current count
6 type Counter interface {
7         // Inc adds Sum(vs) to the counter. Sum(vs) must be positive.
8         //
9         // If len(vs) == 0, increments the counter by 1.
10         Inc(vs ...float64)
11 }
12
13 // LabeledCounter is counter that must have labels populated before use.
14 type LabeledCounter interface {
15         WithValues(vs ...string) Counter
16 }
17
18 type labeledCounter struct {
19         pc *prometheus.CounterVec
20 }
21
22 func (lc *labeledCounter) WithValues(vs ...string) Counter {
23         return &counter{pc: lc.pc.WithLabelValues(vs...)}
24 }
25
26 func (lc *labeledCounter) Describe(ch chan<- *prometheus.Desc) {
27         lc.pc.Describe(ch)
28 }
29
30 func (lc *labeledCounter) Collect(ch chan<- prometheus.Metric) {
31         lc.pc.Collect(ch)
32 }
33
34 type counter struct {
35         pc prometheus.Counter
36 }
37
38 func (c *counter) Inc(vs ...float64) {
39         if len(vs) == 0 {
40                 c.pc.Inc()
41         }
42
43         c.pc.Add(sumFloat64(vs...))
44 }
45
46 func (c *counter) Describe(ch chan<- *prometheus.Desc) {
47         c.pc.Describe(ch)
48 }
49
50 func (c *counter) Collect(ch chan<- prometheus.Metric) {
51         c.pc.Collect(ch)
52 }