-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (66 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
71
72
73
74
75
76
77
package main
import (
"flag"
"fmt"
"os"
"github.com/kobajagi/estats/stats"
)
const HelpString = `estats is a system metrics collection system which polls:
- Load average values
- Derived CPU percentage values
- Network interface statistics (in -n option set)
- Disk partition usage in percent (if -p option set)
- Memory usage in percent`
func main() {
flag.Usage = func() {
if len(os.Args) == 2 && os.Args[1] == "-h" {
fmt.Fprintln(
flag.CommandLine.Output(),
HelpString,
)
}
fmt.Fprintf(
flag.CommandLine.Output(),
"Usage:\n estats [OPTION...]\nOptions:\n",
)
flag.PrintDefaults()
}
interval := flag.Int(
"i",
5,
"interval in seconds at which to poll",
)
path := flag.String(
"p",
"",
"partition to poll",
)
net := flag.String(
"n",
"",
"network interface to poll",
)
flag.Parse()
if *interval <= 0 {
fmt.Fprintf(
os.Stderr,
"invalid value \"%d\" for flag -i: out of scope\n",
*interval,
)
flag.PrintDefaults()
os.Exit(2)
}
providers := []stats.Provider{
stats.LoadAvgProvider(),
stats.CpuUsageProvider(),
stats.MemUsageProvider(),
}
if *net != "" {
providers = append(providers, stats.NetUsageProvider(*net))
}
if *path != "" {
providers = append(providers, stats.DiskUsageProvider(*path))
}
p := NewPoller(providers...)
p.Run(*interval)
}