Skip to content

Commit

Permalink
v6 release
Browse files Browse the repository at this point in the history
  • Loading branch information
710leo committed Mar 9, 2023
1 parent 87899cb commit 178de1f
Show file tree
Hide file tree
Showing 421 changed files with 28,479 additions and 27,261 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.
limitations under the License.
46 changes: 13 additions & 33 deletions Makefile
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 &
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
- 补充和完善文档 => [n9e.github.io](https://n9e.github.io/)
- 分享您在使用夜莺监控过程中的最佳实践和经验心得 => [文章分享](https://n9e.github.io/docs/prologue/share/)
- 提交产品建议 =》 [github issue](https://github.com/ccfos/nightingale/issues/new?assignees=&labels=kind%2Ffeature&template=enhancement.md)
- 提交代码,让夜莺监控更快、更稳、更好用 => [github pull request](https://github.com/didi/nightingale/pulls)
- 提交代码,让夜莺监控更快、更稳、更好用 => [github pull request](https://github.com/ccfos/nightingale/pulls)

**尊重、认可和记录每一位贡献者的工作**是夜莺开源社区的第一指导原则,我们提倡**高效的提问**,这既是对开发者时间的尊重,也是对整个社区知识沉淀的贡献:
- 提问之前请先查阅 [FAQ](https://www.gitlink.org.cn/ccfos/nightingale/wiki/faq)
Expand All @@ -112,7 +112,7 @@
</a>

## License
[Apache License V2.0](https://github.com/didi/nightingale/blob/main/LICENSE)
[Apache License V2.0](https://github.com/ccfos/nightingale/blob/main/LICENSE)

## Contact Us
推荐您关注夜莺监控公众号,及时获取相关产品和社区动态:
Expand Down
12 changes: 6 additions & 6 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ Nightingale is an cloud-native monitoring system by All-In-On design, support en
<img src="doc/img/install-vm.png" width="680">

## Contact us and feedback questions
- We recommend that you use [github issue](https://github.com/didi/nightingale/issues) as the preferred channel for issue feedback and requirement submission;
- We recommend that you use [github issue](https://github.com/ccfos/nightingale/issues) as the preferred channel for issue feedback and requirement submission;
- You can join our WeChat group

<img src="doc/img/n9e-vx-new.png" width="180">


## Contributing
We welcome your participation in the Nightingale open source project and open source community in a variety of ways:
- Feedback on problems and bugs => [github issue](https://github.com/didi/nightingale/issues)
- Feedback on problems and bugs => [github issue](https://github.com/ccfos/nightingale/issues)
- Additional and improved documentation => [n9e.github.io](https://n9e.github.io/)
- Share your best practices and insights on using Nightingale => [User Story](https://github.com/didi/nightingale/issues/897)
- Join our community events => [Nightingale wechat group](https://s3-gz01.didistatic.com/n9e-pub/image/n9e-wx.png)
- Submit code to make Nightingale better =>[github PR](https://github.com/didi/nightingale/pulls)
- Share your best practices and insights on using Nightingale => [User Story](https://github.com/ccfos/nightingale/issues/897)
- Join our community events => [Nightingale wechat group](https://s3-gz01.ccfosstatic.com/n9e-pub/image/n9e-wx.png)
- Submit code to make Nightingale better =>[github PR](https://github.com/ccfos/nightingale/pulls)


## License
Nightingale with [Apache License V2.0](https://github.com/didi/nightingale/blob/main/LICENSE) open source license.
Nightingale with [Apache License V2.0](https://github.com/ccfos/nightingale/blob/main/LICENSE) open source license.
71 changes: 71 additions & 0 deletions alert/aconf/conf.go
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
}
}
99 changes: 99 additions & 0 deletions alert/alert.go
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)
}
Loading

0 comments on commit 178de1f

Please sign in to comment.