Start investigating cloudwatch metrics.
Cameron Stitt
7 years ago
0 | package cloudwatch | |
1 | ||
2 | import ( | |
3 | "sync" | |
4 | ||
5 | "github.com/aws/aws-sdk-go/service/cloudwatch" | |
6 | "github.com/go-kit/kit/log" | |
7 | "github.com/go-kit/kit/metrics" | |
8 | "github.com/go-kit/kit/metrics/generic" | |
9 | ) | |
10 | ||
11 | // CloudWatch ... | |
12 | type CloudWatch struct { | |
13 | mtx sync.RWMutex | |
14 | prefix string | |
15 | svc *cloudwatch.CloudWatch | |
16 | counters map[string]*Counter | |
17 | //gauges map[string]*Gauge | |
18 | //histograms map[string]*Histogram | |
19 | logger log.Logger | |
20 | } | |
21 | ||
22 | func New(prefix string, logger log.Logger, svc *cloudwatch.CloudWatch) *CloudWatch { | |
23 | return &CloudWatch{ | |
24 | prefix: prefix, | |
25 | svc: svc, | |
26 | counters: map[string]*Counter{}, | |
27 | logger: logger, | |
28 | } | |
29 | } | |
30 | ||
31 | func (cw *CloudWatch) NewCounter(name string) *Counter { | |
32 | c := NewCounter(cw.prefix, name) | |
33 | cw.mtx.Lock() | |
34 | cw.counters[cw.prefix+name] = c | |
35 | cw.mtx.Unlock() | |
36 | return c | |
37 | } | |
38 | ||
39 | // Counter is a Graphite counter metric. | |
40 | type Counter struct { | |
41 | namespace string | |
42 | c *generic.Counter | |
43 | } | |
44 | ||
45 | // NewCounter returns a new usable counter metric. | |
46 | func NewCounter(namespace, name string) *Counter { | |
47 | return &Counter{ | |
48 | namespace: namespace, | |
49 | c: generic.NewCounter(name), | |
50 | } | |
51 | } | |
52 | ||
53 | // With is a no-op. | |
54 | func (c *Counter) With(labelValues ...string) metrics.Counter { | |
55 | return c.c.With(labelValues...) | |
56 | } | |
57 | ||
58 | // Add implements counter. | |
59 | func (c *Counter) Add(delta float64) { | |
60 | c.c.Add(delta) | |
61 | } |