forked from Azure/acs-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
39 lines (35 loc) · 877 Bytes
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package metrics
import (
"fmt"
"github.com/Azure/acs-engine/pkg/helpers"
"github.com/alexcesaro/statsd"
)
type mdmBucket struct {
Namespace string `json:"Namespace"`
Metric string `json:"Metric"`
Dims map[string]string `json:"Dims"`
}
// AddMetric adds the defined metric to a list of metrics to send to MDM
func AddMetric(endpoint, namespace, metric string, count int64, dims map[string]string) error {
bucket := mdmBucket{
Namespace: namespace,
Metric: metric,
Dims: dims}
data, err := helpers.JSONMarshal(bucket, false)
if err != nil {
return err
}
client, err := statsd.New(
statsd.Address(endpoint),
statsd.Network("udp"),
statsd.ErrorHandler(
func(err error) {
fmt.Println(err.Error())
}))
if err != nil {
return err
}
defer client.Close()
client.Count(string(data), count)
return nil
}