forked from akrennmair/dyndnscd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (58 loc) · 1.32 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"flag"
"fmt"
"github.com/akrennmair/goconf"
"os"
"runtime"
"time"
)
func main() {
var configfile *string = flag.String("f", "", "configuration file")
flag.Parse()
if *configfile == "" {
fmt.Println("usage: dyndnscd -f <configfile>")
flag.PrintDefaults()
os.Exit(1)
}
c, err := conf.ReadConfigFile(*configfile)
if err != nil {
fmt.Printf("reading configuration file failed: %v\n", err)
os.Exit(1)
}
logchan := make(chan LogMsg)
go Logger(c, logchan)
SpawnPollers(c, logchan)
go func() {
for {
time.Sleep(120 * time.Second)
logchan <- NewLogMsg(INFO, "memory: "+MemoryStatistics())
}
}()
done := make(chan int)
<-done
}
func MemoryStatistics() string {
var p []runtime.MemProfileRecord
n, ok := runtime.MemProfile(nil, false)
for {
p = make([]runtime.MemProfileRecord, n+50)
n, ok = runtime.MemProfile(p, false)
if ok {
p = p[0:n]
break
}
}
var total runtime.MemProfileRecord
for i := range p {
r := &p[i]
total.AllocBytes += r.AllocBytes
total.AllocObjects += r.AllocObjects
total.FreeBytes += r.FreeBytes
total.FreeObjects += r.FreeObjects
}
var m runtime.MemStats
runtime.ReadMemStats(&m)
return fmt.Sprintf("%d in use objects (%d in use bytes) | Alloc: %d TotalAlloc: %d",
total.InUseObjects(), total.InUseBytes(), m.Alloc, m.TotalAlloc)
}