forked from feiyu563/PrometheusAlert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (42 loc) · 1.15 KB
/
main.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
package main
import (
"PrometheusAlert/model"
"PrometheusAlert/models"
_ "PrometheusAlert/routers"
"github.com/Unknwon/com"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
_ "github.com/mattn/go-sqlite3"
"github.com/prometheus/client_golang/prometheus/promhttp"
"os"
"path"
)
func init() {
// 检查数据库文件
Db_name := "./db/PrometheusAlertDB.db"
if !com.IsExist(Db_name) {
os.MkdirAll(path.Dir(Db_name), os.ModePerm)
os.Create(Db_name)
}
// 注册模型
orm.RegisterModel(new(models.PrometheusAlertDB))
// 注册驱动(“sqlite3” 属于默认注册,此处代码可省略)
orm.RegisterDriver("sqlite3", orm.DRSqlite)
// 注册默认数据库
orm.RegisterDataBase("default", "sqlite3", Db_name, 10)
orm.RunSyncdb("default", false, true)
}
func main() {
orm.Debug = true
logtype := beego.AppConfig.String("logtype")
if logtype == "console" {
logs.SetLogger(logtype)
} else if logtype == "file" {
logpath := beego.AppConfig.String("logpath")
logs.SetLogger(logtype, `{"filename":"`+logpath+`"}`)
}
model.MetricsInit()
beego.Handler("/metrics", promhttp.Handler())
beego.Run()
}