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

View File

@ -82,9 +82,7 @@ var (
Endpoint string Endpoint string
) )
func Parse() error { func Parse(conf string) error {
conf := getYmlFile()
bs, err := file.ReadBytes(conf) bs, err := file.ReadBytes(conf)
if err != nil { if err != nil {
return fmt.Errorf("cannot read yml[%s]: %v", conf, err) return fmt.Errorf("cannot read yml[%s]: %v", conf, err)
@ -164,17 +162,3 @@ func Parse() error {
return nil 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 var Ident string
// Parse configuration file // Parse configuration file
func Parse() error { func Parse(ymlFile string) error {
ymlFile := getYmlFile()
if ymlFile == "" {
return fmt.Errorf("configuration file etc/server.yml not found")
}
bs, err := file.ReadBytes(ymlFile) bs, err := file.ReadBytes(ymlFile)
if err != nil { if err != nil {
return fmt.Errorf("cannot read yml[%s]: %v", ymlFile, err) return fmt.Errorf("cannot read yml[%s]: %v", ymlFile, err)
@ -407,20 +402,6 @@ func Parse() error {
return identity.Parse() 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"] // map["node"]="host1,host2" --> map["node"]=["host1", "host2"]
func formatClusterItems(cluster map[string]string) map[string]*tsdb.ClusterNode { func formatClusterItems(cluster map[string]string) map[string]*tsdb.ClusterNode {
ret := make(map[string]*tsdb.ClusterNode) ret := make(map[string]*tsdb.ClusterNode)

View File

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

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"log" "log"
"os" "os"
@ -36,11 +37,43 @@ import (
_ "github.com/didi/nightingale/v4/src/modules/server/plugins/api" _ "github.com/didi/nightingale/v4/src/modules/server/plugins/api"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/toolkits/file"
pcache "github.com/toolkits/pkg/cache" pcache "github.com/toolkits/pkg/cache"
"github.com/toolkits/pkg/logger" "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() { func main() {
aconf()
parseConf() parseConf()
conf := config.Config conf := config.Config
@ -146,12 +179,31 @@ func main() {
} }
func parseConf() { func parseConf() {
if err := config.Parse(); err != nil { if err := config.Parse(*conf); err != nil {
fmt.Println("cannot parse configuration file:", err) fmt.Println("cannot parse configuration file:", err)
os.Exit(1) 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() { func checkIdentity() {
ip, err := identity.GetIP() ip, err := identity.GetIP()
if err != nil { if err != nil {