这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions cmd/bosun/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package main
//go:generate go run ../../build/generate/generate.go

import (
"bosun.org/_version"
"bosun.org/host"
"flag"
"fmt"
"gopkg.in/fsnotify.v1"
"net/http"
"net/http/httptest"
_ "net/http/pprof"
Expand All @@ -19,6 +16,9 @@ import (
"syscall"
"time"

version "bosun.org/_version"
"gopkg.in/fsnotify.v1"

"bosun.org/annotate/backend"
"bosun.org/cmd/bosun/conf"
"bosun.org/cmd/bosun/conf/rule"
Expand Down Expand Up @@ -101,23 +101,6 @@ var (
mains []func() // Used to hook up syslog on *nix systems
)

func initHostManager(customHostname string) {
var hm host.Manager
var err error

if customHostname != "" {
hm, err = host.NewManagerForHostname(customHostname, false)
} else {
hm, err = host.NewManager(false)
}

if err != nil {
slog.Fatalf("couldn't initialise host factory: %v", err)
}

util.SetHostManager(hm)
}

func main() {
flag.Parse()
if *flagVersion {
Expand All @@ -132,7 +115,7 @@ func main() {
slog.Fatalf("couldn't read system configuration: %v", err)
}

initHostManager(systemConf.Hostname)
util.InitHostManager(systemConf.Hostname, false)

// Check if ES version is set by getting configs on start-up.
// Because the current APIs don't return error so calling slog.Fatalf
Expand Down
22 changes: 2 additions & 20 deletions cmd/scollector/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"bosun.org/host"
"bytes"
"encoding/json"
_ "expvar"
Expand All @@ -20,7 +19,7 @@ import (
"strings"
"time"

"bosun.org/_version"
version "bosun.org/_version"
"bosun.org/cmd/scollector/collectors"
"bosun.org/cmd/scollector/conf"
"bosun.org/collect"
Expand Down Expand Up @@ -62,23 +61,6 @@ func (t *scollectorHTTPTransport) RoundTrip(req *http.Request) (*http.Response,
return t.RoundTripper.RoundTrip(req)
}

func initHostManager(customHostname string, useFullHostName bool) {
var hm host.Manager
var err error

if customHostname != "" {
hm, err = host.NewManagerForHostname(customHostname, useFullHostName)
} else {
hm, err = host.NewManager(useFullHostName)
}

if err != nil {
slog.Fatalf("couldn't initialise host factory: %v", err)
}

util.SetHostManager(hm)
}

func main() {
flag.Parse()
if *flagToToml != "" {
Expand Down Expand Up @@ -137,7 +119,7 @@ func main() {
}
collectors.AddTags = conf.Tags

initHostManager(conf.Hostname, conf.FullHost)
util.InitHostManager(conf.Hostname, conf.FullHost)

if conf.ColDir != "" {
collectors.InitPrograms(conf.ColDir)
Expand Down
18 changes: 11 additions & 7 deletions cmd/tsdbrelay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ import (
)

var (
listenAddr = flag.String("l", ":4242", "Listen address.")
bosunServer = flag.String("b", "bosun", "Target Bosun server. Can specify port with host:port.")
secondaryRelays = flag.String("r", "", "Additional relays to send data to. Intended for secondary data center replication. Only response from primary tsdb server wil be relayed to clients.")
tsdbServer = flag.String("t", "", "Target OpenTSDB server. Can specify port with host:port.")
logVerbose = flag.Bool("v", false, "enable verbose logging")
toDenormalize = flag.String("denormalize", "", "List of metrics to denormalize. Comma seperated list of `metric__tagname__tagname` rules. Will be translated to `__tagvalue.tagvalue.metric`")
flagVersion = flag.Bool("version", false, "Prints the version and exits.")
listenAddr = flag.String("l", ":4242", "Listen address.")
bosunServer = flag.String("b", "bosun", "Target Bosun server. Can specify port with host:port.")
secondaryRelays = flag.String("r", "", "Additional relays to send data to. Intended for secondary data center replication. Only response from primary tsdb server wil be relayed to clients.")
tsdbServer = flag.String("t", "", "Target OpenTSDB server. Can specify port with host:port.")
logVerbose = flag.Bool("v", false, "enable verbose logging")
hostnameOverride = flag.String("hostname", "", "Override the own hostname. Especially useful when running in a container.")
useFullHostname = flag.Bool("useFullHostname", false, "Whether to use the fully qualified hostname")
toDenormalize = flag.String("denormalize", "", "List of metrics to denormalize. Comma seperated list of `metric__tagname__tagname` rules. Will be translated to `__tagvalue.tagvalue.metric`")
flagVersion = flag.Bool("version", false, "Prints the version and exits.")

redisHost = flag.String("redis", "", "redis host for aggregating external counters")
redisDb = flag.Int("db", 0, "redis db to use for counters")
Expand Down Expand Up @@ -106,6 +108,8 @@ func main() {
}
}

util.InitHostManager(*hostnameOverride, *useFullHostname)

tsdbURL, err := parseHost(*tsdbServer, "", true)
if err != nil {
slog.Fatalf("Invalid -t value: %s", err)
Expand Down
19 changes: 19 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,32 @@ package util // import "bosun.org/util"

import (
"bosun.org/host"
"bosun.org/slog"

"regexp"
)

// This is here only until we manage to refactor more of the system, allowing us to pass a host.Manager around
// the system, rather than holding onto global state
var hostManager host.Manager

func InitHostManager(customHostname string, useFullHostName bool) {
var hm host.Manager
var err error

if customHostname != "" {
hm, err = host.NewManagerForHostname(customHostname, useFullHostName)
} else {
hm, err = host.NewManager(useFullHostName)
}

if err != nil {
slog.Fatalf("couldn't initialise host factory: %v", err)
}

SetHostManager(hm)
}

func SetHostManager(hm host.Manager) {
hostManager = hm
}
Expand Down