-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.go
103 lines (87 loc) · 2.32 KB
/
agent.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package agent
import (
"sync"
"time"
"github.com/sirupsen/logrus"
"github.com/toni-moreno/oracle_collector/pkg/agent/oracle"
"github.com/toni-moreno/oracle_collector/pkg/agent/output"
"github.com/toni-moreno/oracle_collector/pkg/agent/selfmon"
"github.com/toni-moreno/oracle_collector/pkg/config"
)
var (
// Version is the app X.Y.Z version
Version string
// Commit is the git commit sha1
Commit string
// Branch is the git branch
Branch string
// BuildStamp is the build timestamp
BuildStamp string
)
// RInfo contains the agent's release and version information.
type RInfo struct {
InstanceID string
Version string
Commit string
Branch string
BuildStamp string
}
// GetRInfo returns the agent release information.
func GetRInfo() *RInfo {
info := &RInfo{
InstanceID: MainConfig.General.InstanceID,
Version: Version,
Commit: Commit,
Branch: Branch,
BuildStamp: BuildStamp,
}
return info
}
var (
// MainConfig contains the global configuration
MainConfig config.Config
log *logrus.Logger
// reloadMutex guards the reloadProcess flag
reloadMutex sync.Mutex
reloadProcess bool
// mutex guards the runtime devices map access
mutex sync.RWMutex
gatherWg sync.WaitGroup
// processWg sync.WaitGroup
)
// SetLogger sets the current log output.
func SetLogger(l *logrus.Logger) {
log = l
}
// End stops all devices polling.
func End() (time.Duration, error) {
start := time.Now()
// nothing to do
return time.Since(start), nil
}
func Start() {
done := make(chan bool)
// init SelfMonitoring
selfmon.Init(MainConfig.Selfmon)
// init Output Sync process
output.Init(MainConfig.Output)
// init discovery process
oracle.InitDiscovery(MainConfig.Discovery, done)
// init SystemMonitor Process
cfg := MainConfig.OraMon
chains := make([]chan bool, len(cfg.MetricGroup))
for i, group := range cfg.MetricGroup {
chains[i] = make(chan bool)
log.Infof("[COLLECTOR] Begin [%d] Collecting data from Group [%s]", i, group.Name)
processor := InitGroupProcessor(group, oracle.OraList)
processor.StartCollection(chains[i], &gatherWg)
}
// init OracleMonitor Process
gatherWg.Wait()
}
// ReloadConf stops the polling, reloads all configuration and restart the polling.
func ReloadConf() (time.Duration, error) {
start := time.Now()
// nothing to do yet
return time.Since(start), nil
}