forked from ccfos/nightingale
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
421 changed files
with
28,479 additions
and
27,261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,30 @@ | ||
.PHONY: start build | ||
|
||
NOW = $(shell date -u '+%Y%m%d%I%M%S') | ||
|
||
|
||
APP = n9e | ||
SERVER_BIN = $(APP) | ||
ROOT:=$(shell pwd -P) | ||
GIT_COMMIT:=$(shell git --work-tree ${ROOT} rev-parse 'HEAD^{commit}') | ||
_GIT_VERSION:=$(shell git --work-tree ${ROOT} describe --tags --abbrev=14 "${GIT_COMMIT}^{commit}" 2>/dev/null) | ||
TAG=$(shell echo "${_GIT_VERSION}" | awk -F"-" '{print $$1}') | ||
RELEASE_VERSION:="$(TAG)-$(GIT_COMMIT)" | ||
|
||
# RELEASE_ROOT = release | ||
# RELEASE_SERVER = release/${APP} | ||
# GIT_COUNT = $(shell git rev-list --all --count) | ||
# GIT_HASH = $(shell git rev-parse --short HEAD) | ||
# RELEASE_TAG = $(RELEASE_VERSION).$(GIT_COUNT).$(GIT_HASH) | ||
|
||
all: build | ||
|
||
build: | ||
go build -ldflags "-w -s -X github.com/didi/nightingale/v5/src/pkg/version.VERSION=$(RELEASE_VERSION)" -o $(SERVER_BIN) ./src | ||
|
||
build-linux: | ||
GOOS=linux GOARCH=amd64 go build -ldflags "-w -s -X github.com/didi/nightingale/v5/src/pkg/version.VERSION=$(RELEASE_VERSION)" -o $(SERVER_BIN) ./src | ||
|
||
# start: | ||
# @go run -ldflags "-X main.VERSION=$(RELEASE_TAG)" ./cmd/${APP}/main.go web -c ./configs/config.toml -m ./configs/model.conf --menu ./configs/menu.yaml | ||
run_webapi: | ||
nohup ./n9e webapi > webapi.log 2>&1 & | ||
go build -ldflags "-w -s -X github.com/ccfos/nightingale/v6/pkg/version.Version=$(RELEASE_VERSION)" -o n9e ./cmd/center/main.go | ||
|
||
run_server: | ||
nohup ./n9e server > server.log 2>&1 & | ||
build-alert: | ||
go build -ldflags "-w -s -X github.com/ccfos/nightingale/v6/pkg/version.Version=$(RELEASE_VERSION)" -o n9e-alert ./cmd/alert/main.go | ||
|
||
# swagger: | ||
# @swag init --parseDependency --generalInfo ./cmd/${APP}/main.go --output ./internal/app/swagger | ||
build-pushgw: | ||
go build -ldflags "-w -s -X github.com/ccfos/nightingale/v6/pkg/version.Version=$(RELEASE_VERSION)" -o n9e-pushgw ./cmd/pushgw/main.go | ||
|
||
# wire: | ||
# @wire gen ./internal/app | ||
build-cli: | ||
go build -ldflags "-w -s -X github.com/ccfos/nightingale/v6/pkg/version.Version=$(RELEASE_VERSION)" -o n9e-cli ./cmd/cli/main.go | ||
|
||
# test: | ||
# cd ./internal/app/test && go test -v | ||
run: | ||
nohup ./n9e > n9e.log 2>&1 & | ||
|
||
# clean: | ||
# rm -rf data release $(SERVER_BIN) internal/app/test/data cmd/${APP}/data | ||
run_alert: | ||
nohup ./n9e-alert > n9e-alert.log 2>&1 & | ||
|
||
pack: build | ||
rm -rf $(APP)-$(RELEASE_VERSION).tar.gz | ||
tar -zcvf $(APP)-$(RELEASE_VERSION).tar.gz docker etc $(SERVER_BIN) pub/font pub/index.html pub/assets pub/image | ||
run_pushgw: | ||
nohup ./n9e-pushgw > n9e-pushgw.log 2>&1 & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package aconf | ||
|
||
import ( | ||
"path" | ||
|
||
"github.com/toolkits/pkg/runner" | ||
) | ||
|
||
type Alert struct { | ||
EngineDelay int64 | ||
Heartbeat HeartbeatConfig | ||
Alerting Alerting | ||
SMTP SMTPConfig | ||
Ibex Ibex | ||
} | ||
|
||
type SMTPConfig struct { | ||
Host string | ||
Port int | ||
User string | ||
Pass string | ||
From string | ||
InsecureSkipVerify bool | ||
Batch int | ||
} | ||
|
||
type HeartbeatConfig struct { | ||
IP string | ||
Interval int64 | ||
Endpoint string | ||
ClusterName string | ||
} | ||
|
||
type Alerting struct { | ||
Timeout int64 | ||
TemplatesDir string | ||
NotifyConcurrency int | ||
} | ||
|
||
type CallPlugin struct { | ||
Enable bool | ||
PluginPath string | ||
Caller string | ||
} | ||
|
||
type RedisPub struct { | ||
Enable bool | ||
ChannelPrefix string | ||
ChannelKey string | ||
} | ||
|
||
type Ibex struct { | ||
Address string | ||
BasicAuthUser string | ||
BasicAuthPass string | ||
Timeout int64 | ||
} | ||
|
||
func (a *Alert) PreCheck() { | ||
if a.Alerting.TemplatesDir == "" { | ||
a.Alerting.TemplatesDir = path.Join(runner.Cwd, "etc", "template") | ||
} | ||
|
||
if a.Alerting.Timeout == 0 { | ||
a.Alerting.Timeout = 30000 | ||
} | ||
|
||
if a.Heartbeat.Interval == 0 { | ||
a.Heartbeat.Interval = 1000 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package alert | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ccfos/nightingale/v6/alert/aconf" | ||
"github.com/ccfos/nightingale/v6/alert/astats" | ||
"github.com/ccfos/nightingale/v6/alert/dispatch" | ||
"github.com/ccfos/nightingale/v6/alert/eval" | ||
"github.com/ccfos/nightingale/v6/alert/naming" | ||
"github.com/ccfos/nightingale/v6/alert/process" | ||
"github.com/ccfos/nightingale/v6/alert/queue" | ||
"github.com/ccfos/nightingale/v6/alert/record" | ||
"github.com/ccfos/nightingale/v6/alert/router" | ||
"github.com/ccfos/nightingale/v6/alert/sender" | ||
"github.com/ccfos/nightingale/v6/conf" | ||
"github.com/ccfos/nightingale/v6/memsto" | ||
"github.com/ccfos/nightingale/v6/models" | ||
"github.com/ccfos/nightingale/v6/pkg/ctx" | ||
"github.com/ccfos/nightingale/v6/pkg/httpx" | ||
"github.com/ccfos/nightingale/v6/pkg/logx" | ||
"github.com/ccfos/nightingale/v6/prom" | ||
"github.com/ccfos/nightingale/v6/pushgw/pconf" | ||
"github.com/ccfos/nightingale/v6/pushgw/writer" | ||
"github.com/ccfos/nightingale/v6/storage" | ||
) | ||
|
||
func Initialize(configDir string, cryptoKey string) (func(), error) { | ||
config, err := conf.InitConfig(configDir, cryptoKey) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to init config: %v", err) | ||
} | ||
|
||
logxClean, err := logx.Init(config.Log) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
db, err := storage.New(config.DB) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ctx := ctx.NewContext(context.Background(), db) | ||
|
||
syncStats := memsto.NewSyncStats() | ||
alertStats := astats.NewSyncStats() | ||
|
||
targetCache := memsto.NewTargetCache(ctx, syncStats) | ||
busiGroupCache := memsto.NewBusiGroupCache(ctx, syncStats) | ||
alertMuteCache := memsto.NewAlertMuteCache(ctx, syncStats) | ||
|
||
alertRuleCache := memsto.NewAlertRuleCache(ctx, syncStats) | ||
|
||
promClients := prom.NewPromClient(ctx, config.Alert.Heartbeat) | ||
|
||
externalProcessors := process.NewExternalProcessors() | ||
|
||
Start(config.Alert, config.Pushgw, syncStats, alertStats, externalProcessors, targetCache, busiGroupCache, alertMuteCache, alertRuleCache, ctx, promClients) | ||
|
||
r := httpx.GinEngine(config.Global.RunMode, config.HTTP) | ||
rt := router.New(config.HTTP, config.Alert, alertMuteCache, targetCache, busiGroupCache, alertStats, ctx, externalProcessors) | ||
rt.Config(r) | ||
|
||
httpClean := httpx.Init(config.HTTP, r) | ||
|
||
return func() { | ||
logxClean() | ||
httpClean() | ||
}, nil | ||
} | ||
|
||
func Start(alertc aconf.Alert, pushgwc pconf.Pushgw, syncStats *memsto.Stats, alertStats *astats.Stats, externalProcessors *process.ExternalProcessorsType, targetCache *memsto.TargetCacheType, busiGroupCache *memsto.BusiGroupCacheType, | ||
alertMuteCache *memsto.AlertMuteCacheType, alertRuleCache *memsto.AlertRuleCacheType, ctx *ctx.Context, promClients *prom.PromClientMap) { | ||
userCache := memsto.NewUserCache(ctx, syncStats) | ||
userGroupCache := memsto.NewUserGroupCache(ctx, syncStats) | ||
alertSubscribeCache := memsto.NewAlertSubscribeCache(ctx, syncStats) | ||
recordingRuleCache := memsto.NewRecordingRuleCache(ctx, syncStats) | ||
webhookCache := memsto.NewWebhookCache(ctx) | ||
notifyScript := memsto.NewNotifyScript(ctx) | ||
|
||
go models.InitNotifyConfig(ctx, alertc.Alerting.TemplatesDir) | ||
|
||
naming := naming.NewNaming(ctx, alertc.Heartbeat) | ||
|
||
writers := writer.NewWriters(pushgwc) | ||
record.NewScheduler(alertc, recordingRuleCache, promClients, writers, alertStats) | ||
|
||
eval.NewScheduler(alertc, externalProcessors, alertRuleCache, targetCache, busiGroupCache, alertMuteCache, promClients, naming, ctx, alertStats) | ||
|
||
dp := dispatch.NewDispatch(alertRuleCache, userCache, userGroupCache, alertSubscribeCache, targetCache, webhookCache, notifyScript, alertc.Alerting, alertc.Ibex, ctx) | ||
consumer := dispatch.NewConsumer(alertc.Alerting, ctx, dp) | ||
|
||
go dp.ReloadTpls() | ||
go consumer.LoopConsume() | ||
|
||
go queue.ReportQueueSize(alertStats) | ||
go sender.StartEmailSender(alertc.SMTP) | ||
} |
Oops, something went wrong.