-
Notifications
You must be signed in to change notification settings - Fork 9
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
8 changed files
with
206 additions
and
108 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
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,69 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ccfos/nightingale/v6/alert" | ||
"github.com/ccfos/nightingale/v6/alert/astats" | ||
"github.com/ccfos/nightingale/v6/alert/process" | ||
"github.com/ccfos/nightingale/v6/conf" | ||
"github.com/ccfos/nightingale/v6/memsto" | ||
"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/idents" | ||
"github.com/ccfos/nightingale/v6/pushgw/writer" | ||
|
||
alertrt "github.com/ccfos/nightingale/v6/alert/router" | ||
pushgwrt "github.com/ccfos/nightingale/v6/pushgw/router" | ||
) | ||
|
||
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 | ||
} | ||
|
||
ctx := ctx.NewContext(context.Background(), nil, false, config.CenterApi) | ||
|
||
syncStats := memsto.NewSyncStats() | ||
|
||
targetCache := memsto.NewTargetCache(ctx, syncStats, nil) | ||
busiGroupCache := memsto.NewBusiGroupCache(ctx, syncStats) | ||
idents := idents.New(ctx) | ||
writers := writer.NewWriters(config.Pushgw) | ||
pushgwRouter := pushgwrt.New(config.HTTP, config.Pushgw, targetCache, busiGroupCache, idents, writers, ctx) | ||
r := httpx.GinEngine(config.Global.RunMode, config.HTTP) | ||
pushgwRouter.Config(r) | ||
|
||
if !config.Alert.Disable { | ||
alertStats := astats.NewSyncStats() | ||
dsCache := memsto.NewDatasourceCache(ctx, syncStats) | ||
alertMuteCache := memsto.NewAlertMuteCache(ctx, syncStats) | ||
alertRuleCache := memsto.NewAlertRuleCache(ctx, syncStats) | ||
notifyConfigCache := memsto.NewNotifyConfigCache(ctx) | ||
|
||
promClients := prom.NewPromClient(ctx, config.Alert.Heartbeat) | ||
externalProcessors := process.NewExternalProcessors() | ||
|
||
alert.Start(config.Alert, config.Pushgw, syncStats, alertStats, externalProcessors, targetCache, busiGroupCache, alertMuteCache, alertRuleCache, notifyConfigCache, dsCache, ctx, promClients) | ||
|
||
alertrtRouter := alertrt.New(config.HTTP, config.Alert, alertMuteCache, targetCache, busiGroupCache, alertStats, ctx, externalProcessors) | ||
|
||
alertrtRouter.Config(r) | ||
} | ||
|
||
httpClean := httpx.Init(config.HTTP, r) | ||
|
||
return func() { | ||
logxClean() | ||
httpClean() | ||
}, nil | ||
} |
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,68 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/ccfos/nightingale/v6/pkg/osx" | ||
"github.com/ccfos/nightingale/v6/pkg/version" | ||
|
||
"github.com/toolkits/pkg/runner" | ||
) | ||
|
||
var ( | ||
showVersion = flag.Bool("version", false, "Show version.") | ||
configDir = flag.String("configs", osx.GetEnv("N9E_EDGE_CONFIGS", "etc"), "Specify configuration directory.(env:N9E_EDGE_CONFIGS)") | ||
cryptoKey = flag.String("crypto-key", "", "Specify the secret key for configuration file field encryption.") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
if *showVersion { | ||
fmt.Println(version.Version) | ||
os.Exit(0) | ||
} | ||
|
||
printEnv() | ||
|
||
cleanFunc, err := Initialize(*configDir, *cryptoKey) | ||
if err != nil { | ||
log.Fatalln("failed to initialize:", err) | ||
} | ||
|
||
code := 1 | ||
sc := make(chan os.Signal, 1) | ||
signal.Notify(sc, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) | ||
|
||
EXIT: | ||
for { | ||
sig := <-sc | ||
fmt.Println("received signal:", sig.String()) | ||
switch sig { | ||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT: | ||
code = 0 | ||
break EXIT | ||
case syscall.SIGHUP: | ||
// reload configuration? | ||
default: | ||
break EXIT | ||
} | ||
} | ||
|
||
cleanFunc() | ||
fmt.Println("process exited") | ||
os.Exit(code) | ||
} | ||
|
||
func printEnv() { | ||
runner.Init() | ||
fmt.Println("runner.cwd:", runner.Cwd) | ||
fmt.Println("runner.hostname:", runner.Hostname) | ||
fmt.Println("runner.fd_limits:", runner.FdLimits()) | ||
fmt.Println("runner.vm_limits:", runner.VMLimits()) | ||
} |
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 was deleted.
Oops, something went wrong.
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