-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsynerex-server_linux.go
More file actions
41 lines (37 loc) · 990 Bytes
/
synerex-server_linux.go
File metadata and controls
41 lines (37 loc) · 990 Bytes
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
package main
import (
"log/syslog"
"time"
"log"
"github.com/rcrowley/go-metrics"
)
func periodicLog(r metrics.Registry, freq time.Duration) {
for _ = range time.Tick(freq) {
var total, receive, send int64
r.Each(func(name string, i interface{}) {
switch metric := i.(type) {
case metrics.Counter:
// l.Printf("counter %s count:\t %9d\n", name, metric.Count())
if name == "messages.total" {
total = metric.Count()
}
if name == "messages.receive" {
receive = metric.Count()
}
if name == "messages.send" {
send = metric.Count()
}
}
})
log.Printf("metric total: %7d :send: %7d :recv: %7d", total, send, receive)
}
}
func InitMetricsLog() {
w, err := syslog.Dial("unixgram", "/dev/log", syslog.LOG_INFO, "synerex_metrics")
if err != nil {
log.Print("Error with syslog metric:", err)
go periodicLog(metrics.DefaultRegistry, 60*time.Second)
}else{
go metrics.Syslog(metrics.DefaultRegistry, 60*time.Second, w)
}
}