代码拉取完成,页面将自动刷新
package main
import (
"fmt"
"github.com/dream-mo/prom-elastic-alert/boot"
"github.com/dream-mo/prom-elastic-alert/conf"
"github.com/dream-mo/prom-elastic-alert/utils/logger"
"github.com/dream-mo/prom-elastic-alert/utils/redis"
"github.com/dream-mo/prom-elastic-alert/utils/xtime"
"github.com/jessevdk/go-flags"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
"os"
"os/signal"
"runtime/debug"
"syscall"
)
func main() {
var opts conf.FlagOption
defer func() {
if e := recover(); e != nil {
fmt.Printf("%s\n", e)
if opts.Debug {
debug.PrintStack()
}
}
}()
p := flags.NewParser(&opts, flags.HelpFlag)
_, err := p.ParseArgs(os.Args)
if err != nil {
panic(err)
}
logger.SetLogLevel(opts.GetLogLevel())
xtime.FixedZone(opts.Zone)
c := conf.GetAppConfig(opts.ConfigPath)
redis.Setup()
ea := boot.NewElasticAlert(c, &opts)
ea.Start()
if c.Exporter.Enabled {
metrics := boot.NewRuleStatusCollector(ea)
reg := prometheus.NewPedanticRegistry()
err := reg.Register(metrics)
if err != nil {
t := fmt.Sprintf("Register prometheus collector error: %s", err.Error())
panic(t)
}
gatherers := prometheus.Gatherers{
prometheus.DefaultGatherer,
reg,
}
h := promhttp.HandlerFor(gatherers,
promhttp.HandlerOpts{
ErrorHandling: promhttp.ContinueOnError,
})
http.Handle("/metrics", h)
http.HandleFunc("/alert/message", boot.RenderAlertMessage)
e := http.ListenAndServe(c.Exporter.ListenAddr, nil)
if e != nil {
t := fmt.Sprintf("Prometheus exporter start error: %s", e.Error())
panic(t)
}
}
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
for {
s := <-quit
switch s {
case syscall.SIGHUP:
c := conf.GetAppConfig(opts.ConfigPath)
ea.SetAppConf(c)
logger.Logger.Infoln("Reload application config success!")
case syscall.SIGINT:
fallthrough
case syscall.SIGTERM:
ea.Stop()
logger.Logger.Infoln("exiting...")
return
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。