packages/hyprspace: enable optional prometheus metrics endpoint
This commit is contained in:
parent
43c5e4b68f
commit
e0569ac31e
2 changed files with 14 additions and 1 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -26,6 +27,7 @@ import (
|
||||||
"github.com/libp2p/go-libp2p/core/peer"
|
"github.com/libp2p/go-libp2p/core/peer"
|
||||||
"github.com/multiformats/go-multiaddr"
|
"github.com/multiformats/go-multiaddr"
|
||||||
"github.com/multiformats/go-multibase"
|
"github.com/multiformats/go-multibase"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -140,6 +142,17 @@ func UpRun(r *cmd.Root, c *cmd.Sub) {
|
||||||
// RPC server
|
// RPC server
|
||||||
go hsrpc.RpcServer(ctx, multiaddr.StringCast(fmt.Sprintf("/unix/run/hyprspace-rpc.%s.sock", cfg.Interface.Name)), host, *cfg)
|
go hsrpc.RpcServer(ctx, multiaddr.StringCast(fmt.Sprintf("/unix/run/hyprspace-rpc.%s.sock", cfg.Interface.Name)), host, *cfg)
|
||||||
|
|
||||||
|
// metrics endpoint
|
||||||
|
metricsPort, ok := os.LookupEnv("HYPRSPACE_METRICS_PORT")
|
||||||
|
if ok {
|
||||||
|
metricsTuple := fmt.Sprintf("127.0.0.1:%s", metricsPort)
|
||||||
|
http.Handle("/metrics", promhttp.Handler())
|
||||||
|
go func() {
|
||||||
|
http.ListenAndServe(metricsTuple, nil)
|
||||||
|
}()
|
||||||
|
fmt.Printf("[+] Listening for metrics scrape requests on http://%s/metrics\n", metricsTuple)
|
||||||
|
}
|
||||||
|
|
||||||
// Write lock to filesystem to indicate an existing running daemon.
|
// Write lock to filesystem to indicate an existing running daemon.
|
||||||
err = os.WriteFile(lockPath, []byte(fmt.Sprint(os.Getpid())), os.ModePerm)
|
err = os.WriteFile(lockPath, []byte(fmt.Sprint(os.Getpid())), os.ModePerm)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
|
@ -8,6 +8,7 @@ require (
|
||||||
github.com/libp2p/go-libp2p-kad-dht v0.25.0
|
github.com/libp2p/go-libp2p-kad-dht v0.25.0
|
||||||
github.com/multiformats/go-multiaddr v0.11.0
|
github.com/multiformats/go-multiaddr v0.11.0
|
||||||
github.com/multiformats/go-multibase v0.2.0
|
github.com/multiformats/go-multibase v0.2.0
|
||||||
|
github.com/prometheus/client_golang v1.16.0
|
||||||
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
|
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
|
||||||
github.com/vishvananda/netlink v1.1.0
|
github.com/vishvananda/netlink v1.1.0
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
|
@ -87,7 +88,6 @@ require (
|
||||||
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
|
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/polydawn/refmt v0.89.0 // indirect
|
github.com/polydawn/refmt v0.89.0 // indirect
|
||||||
github.com/prometheus/client_golang v1.16.0 // indirect
|
|
||||||
github.com/prometheus/client_model v0.4.0 // indirect
|
github.com/prometheus/client_model v0.4.0 // indirect
|
||||||
github.com/prometheus/common v0.44.0 // indirect
|
github.com/prometheus/common v0.44.0 // indirect
|
||||||
github.com/prometheus/procfs v0.11.1 // indirect
|
github.com/prometheus/procfs v0.11.1 // indirect
|
||||||
|
|
Loading…
Reference in a new issue