add unix socket support for prometheus
This commit is contained in:
parent
fb853625d1
commit
7e4883db8e
1 changed files with 20 additions and 1 deletions
|
|
@ -21,6 +21,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
"strings"
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
@ -87,7 +89,24 @@ func InitPrometheus(prometheusHost, prometheusPort, prometheusEntry string) {
|
||||||
handler := promhttp.HandlerFor(promReg, promhttp.HandlerOpts{EnableOpenMetrics: true})
|
handler := promhttp.HandlerFor(promReg, promhttp.HandlerOpts{EnableOpenMetrics: true})
|
||||||
http.Handle("/"+prometheusEntry, handler)
|
http.Handle("/"+prometheusEntry, handler)
|
||||||
go func() {
|
go func() {
|
||||||
glog.Infof("Starting Prometheus on %v:%v, entry point is /%v", prometheusHost, prometheusPort, prometheusEntry)
|
|
||||||
|
if strings.HasPrefix(prometheusHost, "unix:") {
|
||||||
|
socketPath := prometheusHost[5:]
|
||||||
|
glog.Infof("Starting Prometheus on Unix socket %v, entry point is /%v", socketPath, prometheusEntry)
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
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 {
|
if err := http.ListenAndServe(prometheusHost+":"+prometheusPort, nil); err != nil {
|
||||||
glog.Errorf("Error starting Prometheus at port %v:%v: %v", prometheusHost, prometheusPort, err)
|
glog.Errorf("Error starting Prometheus at port %v:%v: %v", prometheusHost, prometheusPort, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue