Skip to content
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
2 changes: 1 addition & 1 deletion cmd/stayrtr/stayrtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var (
LogVerbose = flag.Bool("log.verbose", true, "Additional debug logs (disable with -log.verbose=false)")
Version = flag.Bool("version", false, "Print version")

server_metrics = metrics.NewServerMetrics()
server_metrics = metrics.NewServerMetrics(rtr.APP_VERSION)

protoverToLib = map[int]uint8{
0: rtr.PROTOCOL_VERSION_0,
Expand Down
39 changes: 37 additions & 2 deletions metrics/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package metrics

import "github.com/prometheus/client_golang/prometheus"
import (
"fmt"
"os"
"strings"

"github.com/prometheus/client_golang/prometheus"
)

type ServerMetrics struct {
NumberOfVRPs *prometheus.GaugeVec
Expand All @@ -11,9 +17,10 @@ type ServerMetrics struct {
ClientsMetric *prometheus.GaugeVec
PDUsRecv *prometheus.CounterVec
CurrentSerial prometheus.Gauge
info prometheus.GaugeFunc
}

func NewServerMetrics() *ServerMetrics {
func NewServerMetrics(app_version string) *ServerMetrics {
metrics := &ServerMetrics{}
metrics.NumberOfVRPs = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Expand Down Expand Up @@ -70,6 +77,21 @@ func NewServerMetrics() *ServerMetrics {
Help: "Current serial.",
},
)

nodeName, domainName := getHostAndDomainName()
metrics.info = prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Name: "rtr_info",
Help: "stayrtr information",
ConstLabels: prometheus.Labels{
"domainname": domainName,
"nodename": nodeName,
"version": app_version,
},
},
func() float64 { return 1 },
)

metrics.initMetrics()
return metrics
}
Expand All @@ -84,3 +106,16 @@ func (m *ServerMetrics) initMetrics() {
prometheus.MustRegister(m.PDUsRecv)
prometheus.MustRegister(m.CurrentSerial)
}

func getHostAndDomainName() (string, string) {
hostname, err := os.Hostname()
if err != nil {
fmt.Printf("Error getting hostname: %v\n", err)
return "unknown", "unknown"
}
parts := strings.SplitN(hostname, ".", 2)
if len(parts) > 1 {
return parts[0], parts[1]
}
return parts[0], ""
}
Loading