complete version information

This commit is contained in:
710leo 2021-04-15 19:35:25 +08:00
parent 999c1b4239
commit 46f7ec7af9
5 changed files with 77 additions and 43 deletions

View File

@ -24,6 +24,7 @@ import (
"github.com/didi/nightingale/v4/src/modules/agentd/timer"
"github.com/didi/nightingale/v4/src/modules/agentd/udp"
"github.com/toolkits/file"
"github.com/toolkits/pkg/logger"
"github.com/toolkits/pkg/runner"
)
@ -58,6 +59,7 @@ func init() {
}
func main() {
aconf()
parseConf()
loggeri.Init(config.Config.Logger)
@ -127,12 +129,31 @@ func monStart() {
}
func parseConf() {
if err := config.Parse(); err != nil {
if err := config.Parse(*conf); err != nil {
fmt.Println("cannot parse configuration file:", err)
os.Exit(1)
}
}
func aconf() {
if *conf != "" && file.IsExist(*conf) {
return
}
*conf = "etc/agentd.local.yml"
if file.IsExist(*conf) {
return
}
*conf = "etc/agentd.yml"
if file.IsExist(*conf) {
return
}
fmt.Println("no configuration file for server")
os.Exit(1)
}
func endingProc() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)

View File

@ -82,9 +82,7 @@ var (
Endpoint string
)
func Parse() error {
conf := getYmlFile()
func Parse(conf string) error {
bs, err := file.ReadBytes(conf)
if err != nil {
return fmt.Errorf("cannot read yml[%s]: %v", conf, err)
@ -164,17 +162,3 @@ func Parse() error {
return nil
}
func getYmlFile() string {
yml := "etc/agentd.local.yml"
if file.IsExist(yml) {
return yml
}
yml = "etc/agentd.yml"
if file.IsExist(yml) {
return yml
}
return ""
}

View File

@ -208,12 +208,7 @@ var Config *ConfigT
var Ident string
// Parse configuration file
func Parse() error {
ymlFile := getYmlFile()
if ymlFile == "" {
return fmt.Errorf("configuration file etc/server.yml not found")
}
func Parse(ymlFile string) error {
bs, err := file.ReadBytes(ymlFile)
if err != nil {
return fmt.Errorf("cannot read yml[%s]: %v", ymlFile, err)
@ -407,20 +402,6 @@ func Parse() error {
return identity.Parse()
}
func getYmlFile() string {
yml := "etc/server.local.yml"
if file.IsExist(yml) {
return yml
}
yml = "etc/server.yml"
if file.IsExist(yml) {
return yml
}
return ""
}
// map["node"]="host1,host2" --> map["node"]=["host1", "host2"]
func formatClusterItems(cluster map[string]string) map[string]*tsdb.ClusterNode {
ret := make(map[string]*tsdb.ClusterNode)

View File

@ -6,8 +6,6 @@ import (
"path/filepath"
"plugin"
"strings"
"github.com/toolkits/pkg/logger"
)
const pluginDir = "plugins"
@ -15,14 +13,12 @@ const pluginDir = "plugins"
func init() {
plugins, err := listPlugins(pluginDir)
if err != nil {
logger.Warningf("list plugins: %s", err)
return
}
for _, file := range plugins {
_, err := plugin.Open(file)
if err != nil {
logger.Warningf("plugin.Open %s err %s", file, err)
continue
}
}

View File

@ -1,6 +1,7 @@
package main
import (
"flag"
"fmt"
"log"
"os"
@ -36,11 +37,43 @@ import (
_ "github.com/didi/nightingale/v4/src/modules/server/plugins/api"
_ "github.com/go-sql-driver/mysql"
"github.com/toolkits/file"
pcache "github.com/toolkits/pkg/cache"
"github.com/toolkits/pkg/logger"
"github.com/toolkits/pkg/runner"
)
var (
vers *bool
help *bool
conf *string
version = "No Version Provided"
)
func init() {
vers = flag.Bool("v", false, "display the version.")
help = flag.Bool("h", false, "print this help.")
conf = flag.String("f", "", "specify configuration file.")
flag.Parse()
if *vers {
fmt.Println("Version:", version)
os.Exit(0)
}
if *help {
flag.Usage()
os.Exit(0)
}
runner.Init()
fmt.Println("runner.cwd:", runner.Cwd)
fmt.Println("runner.hostname:", runner.Hostname)
}
func main() {
aconf()
parseConf()
conf := config.Config
@ -146,12 +179,31 @@ func main() {
}
func parseConf() {
if err := config.Parse(); err != nil {
if err := config.Parse(*conf); err != nil {
fmt.Println("cannot parse configuration file:", err)
os.Exit(1)
}
}
func aconf() {
if *conf != "" && file.IsExist(*conf) {
return
}
*conf = "etc/server.local.yml"
if file.IsExist(*conf) {
return
}
*conf = "etc/server.yml"
if file.IsExist(*conf) {
return
}
fmt.Println("no configuration file for server")
os.Exit(1)
}
func checkIdentity() {
ip, err := identity.GetIP()
if err != nil {