-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
46 lines (41 loc) · 990 Bytes
/
main.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
40
41
42
43
44
45
46
package main
import (
"encoding/json"
"flag"
"net"
"github.com/sirupsen/logrus"
)
var (
csmPort = flag.Int("csm-port", 1234, "AWS CSM port number")
csmHost = flag.String("csm-host", "localhost", "AWS CSM host")
servePort = flag.Int("serve-port", 8080, "Port to serve metrics")
)
func listenForPackets() {
addr := net.UDPAddr{
Port: *csmPort,
IP: net.ParseIP(*csmHost),
}
connection, err := net.ListenUDP("udp", &addr)
if err != nil {
logrus.Infof("Error listening to CSM address: %v", err)
}
logrus.Infof("Listening on %s:%d", *csmHost, *csmPort)
var buf [1024]byte
for {
size, _, err := connection.ReadFromUDP(buf[:])
if err != nil {
logrus.Errorf("Error receiving packet: %v", err)
} else {
logrus.Infof("Received Packet: %s", buf[0:size])
data := &AWSMetricsData{}
json.Unmarshal(buf[0:size], data)
recordMetric(data)
}
}
}
func main() {
flag.Parse()
registerPrometheusMetrics()
go listenForPackets()
serveMetrics(servePort)
}