Print monitor config path in the logs

This commit is contained in:
Zhen Wang
2019-07-30 11:00:47 -07:00
parent 599ca532e8
commit 182a9450dd
3 changed files with 26 additions and 18 deletions

View File

@@ -43,6 +43,7 @@ func init() {
}
type customPluginMonitor struct {
configPath string
config cpmtypes.CustomPluginConfig
conditions []types.Condition
plugin *plugin.Plugin
@@ -54,7 +55,8 @@ type customPluginMonitor struct {
// NewCustomPluginMonitorOrDie create a new customPluginMonitor, panic if error occurs.
func NewCustomPluginMonitorOrDie(configPath string) types.Monitor {
c := &customPluginMonitor{
tomb: tomb.NewTomb(),
configPath: configPath,
tomb: tomb.NewTomb(),
}
f, err := ioutil.ReadFile(configPath)
if err != nil {
@@ -76,7 +78,7 @@ func NewCustomPluginMonitorOrDie(configPath string) types.Monitor {
glog.Fatalf("Failed to validate custom plugin config %+v: %v", c.config, err)
}
glog.Infof("Finish parsing custom plugin monitor config file: %+v", c.config)
glog.Infof("Finish parsing custom plugin monitor config file %s: %+v", c.configPath, c.config)
c.plugin = plugin.NewPlugin(c.config)
// A 1000 size channel should be big enough.
@@ -107,14 +109,14 @@ func initializeProblemMetricsOrDie(rules []*cpmtypes.CustomRule) {
}
func (c *customPluginMonitor) Start() (<-chan *types.Status, error) {
glog.Info("Start custom plugin monitor")
glog.Infof("Start custom plugin monitor %s", c.configPath)
go c.plugin.Run()
go c.monitorLoop()
return c.statusChan, nil
}
func (c *customPluginMonitor) Stop() {
glog.Info("Stop custom plugin monitor")
glog.Infof("Stop custom plugin monitor %s", c.configPath)
c.tomb.Stop()
}
@@ -127,13 +129,13 @@ func (c *customPluginMonitor) monitorLoop() {
for {
select {
case result := <-resultChan:
glog.V(3).Infof("Receive new plugin result: %+v", result)
glog.V(3).Infof("Receive new plugin result for %s: %+v", c.configPath, result)
status := c.generateStatus(result)
glog.Infof("New status generated: %+v", status)
c.statusChan <- status
case <-c.tomb.Stopping():
c.plugin.Stop()
glog.Infof("Custom plugin monitor stopped")
glog.Infof("Custom plugin monitor stopped: %s", c.configPath)
c.tomb.Done()
break
}

View File

@@ -45,6 +45,7 @@ func init() {
}
type logMonitor struct {
configPath string
watcher watchertypes.LogWatcher
buffer LogBuffer
config MonitorConfig
@@ -56,7 +57,10 @@ type logMonitor struct {
// NewLogMonitorOrDie create a new LogMonitor, panic if error occurs.
func NewLogMonitorOrDie(configPath string) types.Monitor {
l := &logMonitor{tomb: tomb.NewTomb()}
l := &logMonitor{
configPath: configPath,
tomb: tomb.NewTomb(),
}
f, err := ioutil.ReadFile(configPath)
if err != nil {
@@ -70,9 +74,9 @@ func NewLogMonitorOrDie(configPath string) types.Monitor {
(&l.config).ApplyDefaultConfiguration()
err = l.config.ValidateRules()
if err != nil {
glog.Fatalf("Failed to validate matching rules %+v: %v", l.config.Rules, err)
glog.Fatalf("Failed to validate %s matching rules %+v: %v", l.configPath, l.config.Rules, err)
}
glog.Infof("Finish parsing log monitor config file: %+v", l.config)
glog.Infof("Finish parsing log monitor config file %s: %+v", l.configPath, l.config)
l.watcher = logwatchers.GetLogWatcherOrDie(l.config.WatcherConfig)
l.buffer = NewLogBuffer(l.config.BufferSize)
@@ -104,7 +108,7 @@ func initializeProblemMetricsOrDie(rules []systemlogtypes.Rule) {
}
func (l *logMonitor) Start() (<-chan *types.Status, error) {
glog.Info("Start log monitor")
glog.Infof("Start log monitor %s", l.configPath)
var err error
l.logCh, err = l.watcher.Watch()
if err != nil {
@@ -115,7 +119,7 @@ func (l *logMonitor) Start() (<-chan *types.Status, error) {
}
func (l *logMonitor) Stop() {
glog.Info("Stop log monitor")
glog.Infof("Stop log monitor %s", l.configPath)
l.tomb.Stop()
}
@@ -129,7 +133,7 @@ func (l *logMonitor) monitorLoop() {
l.parseLog(log)
case <-l.tomb.Stopping():
l.watcher.Stop()
glog.Infof("Log monitor stopped")
glog.Infof("Log monitor stopped: %s", l.configPath)
return
}
}

View File

@@ -38,6 +38,7 @@ func init() {
}
type systemStatsMonitor struct {
configPath string
config ssmtypes.SystemStatsConfig
diskCollector *diskCollector
hostCollector *hostCollector
@@ -47,7 +48,8 @@ type systemStatsMonitor struct {
// NewSystemStatsMonitorOrDie creates a system stats monitor.
func NewSystemStatsMonitorOrDie(configPath string) types.Monitor {
ssm := systemStatsMonitor{
tomb: tomb.NewTomb(),
configPath: configPath,
tomb: tomb.NewTomb(),
}
// Apply configurations.
@@ -67,7 +69,7 @@ func NewSystemStatsMonitorOrDie(configPath string) types.Monitor {
err = ssm.config.Validate()
if err != nil {
glog.Fatalf("Failed to validate configuration %+v: %v", ssm.config, err)
glog.Fatalf("Failed to validate %s configuration %+v: %v", ssm.configPath, ssm.config, err)
}
if len(ssm.config.DiskConfig.MetricsConfigs) > 0 {
@@ -80,7 +82,7 @@ func NewSystemStatsMonitorOrDie(configPath string) types.Monitor {
}
func (ssm *systemStatsMonitor) Start() (<-chan *types.Status, error) {
glog.Info("Start system stats monitor")
glog.Infof("Start system stats monitor %s", ssm.configPath)
go ssm.monitorLoop()
return nil, nil
}
@@ -93,7 +95,7 @@ func (ssm *systemStatsMonitor) monitorLoop() {
select {
case <-ssm.tomb.Stopping():
glog.Infof("System stats monitor stopped")
glog.Infof("System stats monitor stopped: %s", ssm.configPath)
return
default:
ssm.diskCollector.collect()
@@ -106,13 +108,13 @@ func (ssm *systemStatsMonitor) monitorLoop() {
ssm.diskCollector.collect()
ssm.hostCollector.collect()
case <-ssm.tomb.Stopping():
glog.Infof("System stats monitor stopped")
glog.Infof("System stats monitor stopped: %s", ssm.configPath)
return
}
}
}
func (ssm *systemStatsMonitor) Stop() {
glog.Info("Stop system stats monitor")
glog.Infof("Stop system stats monitor %s", ssm.configPath)
ssm.tomb.Stop()
}