-
Notifications
You must be signed in to change notification settings - Fork 9
/
syslog-ng_stats.go
54 lines (47 loc) · 1.07 KB
/
syslog-ng_stats.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
47
48
49
50
51
52
53
54
package shh
import (
"bufio"
"net"
"time"
)
const (
STATS_COMMAND = "STATS\n"
HEADER = "SourceName;SourceId;SourceInstance;State;Type;Number"
FOOTER = "."
)
type SyslogngStats struct {
measurements chan<- Measurement
Socket string
}
func NewSyslogngStatsPoller(measurements chan<- Measurement, config Config) SyslogngStats {
return SyslogngStats{
measurements: measurements,
Socket: config.SyslogngSocket,
}
}
func (poller SyslogngStats) Poll(tick time.Time) {
conn, err := net.Dial("unix", poller.Socket)
if err != nil {
panic(err)
}
conn.Write([]byte(STATS_COMMAND))
scanner := bufio.NewScanner(conn)
for scanner.Scan() {
line := scanner.Text()
if line == FOOTER {
break
} else {
if line == HEADER {
continue
} else {
fields := Fields(line)
poller.measurements <- CounterMeasurement{tick, poller.Name(), fields[:len(fields)-1], Atouint64(fields[len(fields)-1]), Empty}
}
}
}
conn.Close()
}
func (poller SyslogngStats) Name() string {
return "syslog-ng-stats"
}
func (poller SyslogngStats) Exit() {}