refactor
This commit is contained in:
parent
194abc817d
commit
aeb234fbbf
1 changed files with 27 additions and 18 deletions
|
|
@ -91,29 +91,38 @@ func InitPrometheus(prometheusHost, prometheusPort, prometheusEntry string) {
|
||||||
go func() {
|
go func() {
|
||||||
|
|
||||||
if strings.HasPrefix(prometheusHost, "unix:") {
|
if strings.HasPrefix(prometheusHost, "unix:") {
|
||||||
socketPath := prometheusHost[5:]
|
socketPath := prometheusHost[5:] // trim the "unix:" prefix
|
||||||
glog.Infof("Starting Prometheus on Unix socket %v, entry point is /%v", socketPath, prometheusEntry)
|
glog.Infof("Starting Prometheus on Unix socket %v, entry point is /%v", socketPath, prometheusEntry)
|
||||||
_ := os.Remove(socketPath) // allow failure
|
serveOnUnixSocket(socketPath)
|
||||||
unixListener, err := net.Listen("unix", socketPath)
|
} else {
|
||||||
if err != nil {
|
ipPort := prometheusHost+":"+prometheusPort
|
||||||
glog.Errorf("Error starting Prometheus on socket %v: %v", socketPath, err)
|
glog.Infof("Starting Prometheus on IP port %v:%v, entry point is /%v", ipPort, prometheusEntry)
|
||||||
os.Exit(1)
|
serveOnIpPort(ipPort)
|
||||||
}
|
|
||||||
if err := http.Serve(unixListener, nil); err != nil {
|
|
||||||
glog.Errorf("Error starting Prometheus at socket %v: %v", socketPath, err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof("Starting Prometheus on IP port %v:%v, entry point is /%v", prometheusHost, prometheusPort, prometheusEntry)
|
|
||||||
if err := http.ListenAndServe(prometheusHost+":"+prometheusPort, nil); err != nil {
|
|
||||||
glog.Errorf("Error starting Prometheus at port %v:%v: %v", prometheusHost, prometheusPort, err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func serveOnUnixSocket(socketPath string) {
|
||||||
|
_ = os.Remove(socketPath) // allow failure
|
||||||
|
unixListener, err := net.Listen("unix", socketPath)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("Error starting Prometheus on socket %v: %v", socketPath, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if err := http.Serve(unixListener, nil); err != nil {
|
||||||
|
glog.Errorf("Error starting Prometheus at socket %v: %v", socketPath, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func serveOnIpPort(ipPort string) {
|
||||||
|
if err := http.ListenAndServe(ipPort, nil); err != nil {
|
||||||
|
glog.Errorf("Error starting Prometheus at ip port %v: %v", ipPort, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RecordEntryTypeStart = iota
|
RecordEntryTypeStart = iota
|
||||||
RecordEntryTypeSend = iota
|
RecordEntryTypeSend = iota
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue