Skip to content

Commit 7f0b914

Browse files
authored
Merge pull request #318 from wangzhen127/log
Print monitor config path in the logs
2 parents 239913c + 182a945 commit 7f0b914

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

pkg/custompluginmonitor/custom_plugin_monitor.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func init() {
4343
}
4444

4545
type customPluginMonitor struct {
46+
configPath string
4647
config cpmtypes.CustomPluginConfig
4748
conditions []types.Condition
4849
plugin *plugin.Plugin
@@ -54,7 +55,8 @@ type customPluginMonitor struct {
5455
// NewCustomPluginMonitorOrDie create a new customPluginMonitor, panic if error occurs.
5556
func NewCustomPluginMonitorOrDie(configPath string) types.Monitor {
5657
c := &customPluginMonitor{
57-
tomb: tomb.NewTomb(),
58+
configPath: configPath,
59+
tomb: tomb.NewTomb(),
5860
}
5961
f, err := ioutil.ReadFile(configPath)
6062
if err != nil {
@@ -76,7 +78,7 @@ func NewCustomPluginMonitorOrDie(configPath string) types.Monitor {
7678
glog.Fatalf("Failed to validate custom plugin config %+v: %v", c.config, err)
7779
}
7880

79-
glog.Infof("Finish parsing custom plugin monitor config file: %+v", c.config)
81+
glog.Infof("Finish parsing custom plugin monitor config file %s: %+v", c.configPath, c.config)
8082

8183
c.plugin = plugin.NewPlugin(c.config)
8284
// A 1000 size channel should be big enough.
@@ -107,14 +109,14 @@ func initializeProblemMetricsOrDie(rules []*cpmtypes.CustomRule) {
107109
}
108110

109111
func (c *customPluginMonitor) Start() (<-chan *types.Status, error) {
110-
glog.Info("Start custom plugin monitor")
112+
glog.Infof("Start custom plugin monitor %s", c.configPath)
111113
go c.plugin.Run()
112114
go c.monitorLoop()
113115
return c.statusChan, nil
114116
}
115117

116118
func (c *customPluginMonitor) Stop() {
117-
glog.Info("Stop custom plugin monitor")
119+
glog.Infof("Stop custom plugin monitor %s", c.configPath)
118120
c.tomb.Stop()
119121
}
120122

@@ -127,13 +129,13 @@ func (c *customPluginMonitor) monitorLoop() {
127129
for {
128130
select {
129131
case result := <-resultChan:
130-
glog.V(3).Infof("Receive new plugin result: %+v", result)
132+
glog.V(3).Infof("Receive new plugin result for %s: %+v", c.configPath, result)
131133
status := c.generateStatus(result)
132134
glog.Infof("New status generated: %+v", status)
133135
c.statusChan <- status
134136
case <-c.tomb.Stopping():
135137
c.plugin.Stop()
136-
glog.Infof("Custom plugin monitor stopped")
138+
glog.Infof("Custom plugin monitor stopped: %s", c.configPath)
137139
c.tomb.Done()
138140
break
139141
}

pkg/systemlogmonitor/log_monitor.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func init() {
4545
}
4646

4747
type logMonitor struct {
48+
configPath string
4849
watcher watchertypes.LogWatcher
4950
buffer LogBuffer
5051
config MonitorConfig
@@ -56,7 +57,10 @@ type logMonitor struct {
5657

5758
// NewLogMonitorOrDie create a new LogMonitor, panic if error occurs.
5859
func NewLogMonitorOrDie(configPath string) types.Monitor {
59-
l := &logMonitor{tomb: tomb.NewTomb()}
60+
l := &logMonitor{
61+
configPath: configPath,
62+
tomb: tomb.NewTomb(),
63+
}
6064

6165
f, err := ioutil.ReadFile(configPath)
6266
if err != nil {
@@ -70,9 +74,9 @@ func NewLogMonitorOrDie(configPath string) types.Monitor {
7074
(&l.config).ApplyDefaultConfiguration()
7175
err = l.config.ValidateRules()
7276
if err != nil {
73-
glog.Fatalf("Failed to validate matching rules %+v: %v", l.config.Rules, err)
77+
glog.Fatalf("Failed to validate %s matching rules %+v: %v", l.configPath, l.config.Rules, err)
7478
}
75-
glog.Infof("Finish parsing log monitor config file: %+v", l.config)
79+
glog.Infof("Finish parsing log monitor config file %s: %+v", l.configPath, l.config)
7680

7781
l.watcher = logwatchers.GetLogWatcherOrDie(l.config.WatcherConfig)
7882
l.buffer = NewLogBuffer(l.config.BufferSize)
@@ -104,7 +108,7 @@ func initializeProblemMetricsOrDie(rules []systemlogtypes.Rule) {
104108
}
105109

106110
func (l *logMonitor) Start() (<-chan *types.Status, error) {
107-
glog.Info("Start log monitor")
111+
glog.Infof("Start log monitor %s", l.configPath)
108112
var err error
109113
l.logCh, err = l.watcher.Watch()
110114
if err != nil {
@@ -115,7 +119,7 @@ func (l *logMonitor) Start() (<-chan *types.Status, error) {
115119
}
116120

117121
func (l *logMonitor) Stop() {
118-
glog.Info("Stop log monitor")
122+
glog.Infof("Stop log monitor %s", l.configPath)
119123
l.tomb.Stop()
120124
}
121125

@@ -129,7 +133,7 @@ func (l *logMonitor) monitorLoop() {
129133
l.parseLog(log)
130134
case <-l.tomb.Stopping():
131135
l.watcher.Stop()
132-
glog.Infof("Log monitor stopped")
136+
glog.Infof("Log monitor stopped: %s", l.configPath)
133137
return
134138
}
135139
}

pkg/systemstatsmonitor/system_stats_monitor.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func init() {
3838
}
3939

4040
type systemStatsMonitor struct {
41+
configPath string
4142
config ssmtypes.SystemStatsConfig
4243
diskCollector *diskCollector
4344
hostCollector *hostCollector
@@ -47,7 +48,8 @@ type systemStatsMonitor struct {
4748
// NewSystemStatsMonitorOrDie creates a system stats monitor.
4849
func NewSystemStatsMonitorOrDie(configPath string) types.Monitor {
4950
ssm := systemStatsMonitor{
50-
tomb: tomb.NewTomb(),
51+
configPath: configPath,
52+
tomb: tomb.NewTomb(),
5153
}
5254

5355
// Apply configurations.
@@ -67,7 +69,7 @@ func NewSystemStatsMonitorOrDie(configPath string) types.Monitor {
6769

6870
err = ssm.config.Validate()
6971
if err != nil {
70-
glog.Fatalf("Failed to validate configuration %+v: %v", ssm.config, err)
72+
glog.Fatalf("Failed to validate %s configuration %+v: %v", ssm.configPath, ssm.config, err)
7173
}
7274

7375
if len(ssm.config.DiskConfig.MetricsConfigs) > 0 {
@@ -80,7 +82,7 @@ func NewSystemStatsMonitorOrDie(configPath string) types.Monitor {
8082
}
8183

8284
func (ssm *systemStatsMonitor) Start() (<-chan *types.Status, error) {
83-
glog.Info("Start system stats monitor")
85+
glog.Infof("Start system stats monitor %s", ssm.configPath)
8486
go ssm.monitorLoop()
8587
return nil, nil
8688
}
@@ -93,7 +95,7 @@ func (ssm *systemStatsMonitor) monitorLoop() {
9395

9496
select {
9597
case <-ssm.tomb.Stopping():
96-
glog.Infof("System stats monitor stopped")
98+
glog.Infof("System stats monitor stopped: %s", ssm.configPath)
9799
return
98100
default:
99101
ssm.diskCollector.collect()
@@ -106,13 +108,13 @@ func (ssm *systemStatsMonitor) monitorLoop() {
106108
ssm.diskCollector.collect()
107109
ssm.hostCollector.collect()
108110
case <-ssm.tomb.Stopping():
109-
glog.Infof("System stats monitor stopped")
111+
glog.Infof("System stats monitor stopped: %s", ssm.configPath)
110112
return
111113
}
112114
}
113115
}
114116

115117
func (ssm *systemStatsMonitor) Stop() {
116-
glog.Info("Stop system stats monitor")
118+
glog.Infof("Stop system stats monitor %s", ssm.configPath)
117119
ssm.tomb.Stop()
118120
}

0 commit comments

Comments
 (0)