[FIX] Fix bugs that reset the configuration file every time

This commit is contained in:
zhoujunhao 2018-07-31 18:43:31 +08:00
parent faef2dc77a
commit dc3c2bed5d
2 changed files with 15 additions and 1 deletions

View File

@ -82,7 +82,7 @@ func NewManager(config *option.Config, a *AlertingRulesManager) *Manager {
a: a,
}
m.LoadConfig()
m.a.RulesConfig.SaveAlertingRulesConfig()
m.a.RulesConfig.InitRulesConfig()
return m
}

View File

@ -4,6 +4,7 @@ import (
"github.com/Sirupsen/logrus"
"io/ioutil"
"gopkg.in/yaml.v2"
"os"
)
type AlertingRulesConfig struct {
@ -106,4 +107,17 @@ func (a *AlertingRulesConfig) AddRules(val AlertingNameConfig) error {
group = append(group, &val)
a.Groups = group
return nil
}
func (a *AlertingRulesConfig) InitRulesConfig() {
_, err := os.Stat("/etc/prometheus/rules.yml") //os.Stat获取文件信息
if err != nil {
if os.IsExist(err) {
return
}
a.SaveAlertingRulesConfig()
return
}
return
}