Skip to content

Commit

Permalink
prometheis prefix, makefule tweaks, BGP state duration
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcoles committed Mar 20, 2024
1 parent db6b08c commit 94e780c
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 94 deletions.
7 changes: 3 additions & 4 deletions cmd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ default: vc5 config.json
race:
$(MAKE) default FLAGS=-race

vc5: libbpf/src/libbpf.a *.go static/*
vc5: libbpf/bpf libbpf/src/libbpf.a *.go static/*
CGO_CFLAGS="-I$(LIBBPF)" CGO_LDFLAGS="-L$(LIBBPF)/bpf" go build $(FLAGS) -o $@


# avoid clobbering an existing config file when make is run with -B
config.yaml:
if [ ! -e $@ ]; then cp config.sample.yaml $@; fi
Expand All @@ -30,10 +29,10 @@ distclean: clean
libbpf:
git clone -b $(BPFVER) https://github.com/libbpf/libbpf

libbpf/bpf:
libbpf/bpf: libbpf
cd libbpf && ln -s src bpf

libbpf/src/libbpf.a: libbpf libbpf/bpf
libbpf/src/libbpf.a: libbpf
cd libbpf/src && $(MAKE)

# need to pass as a hook to git
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func main() {
http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {

mutex.Lock()
metrics := prometheus(services, summary, vip)
metrics := prometheus("vc5", services, summary, vip)
mutex.Unlock()

w.Header().Set("Content-Type", "text/plain")
Expand Down
176 changes: 88 additions & 88 deletions cmd/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ import (
"time"
)

func prometheus(services map[netip.Addr][]Serv, summary Summary, vips map[netip.Addr]State) []string {
r := []string{help()}
func prometheus(p string, services map[netip.Addr][]Serv, summary Summary, vips map[netip.Addr]State) []string {
r := []string{help(p)}

var defcon uint8

r = append(r, fmt.Sprintf(`vc5_uptime %d`, summary.Uptime))
r = append(r, fmt.Sprintf(`vc5_defcon %d`, defcon))
r = append(r, fmt.Sprintf(`vc5_latency %d`, summary.Latency))
r = append(r, fmt.Sprintf(`vc5_sessions %d`, summary.Current))
r = append(r, fmt.Sprintf(`vc5_session_total %d`, summary.Flows))
r = append(r, fmt.Sprintf(`vc5_rx_packets %d`, summary.IngressPackets))
r = append(r, fmt.Sprintf(`vc5_rx_octets %d`, summary.IngressOctets))
r = append(r, fmt.Sprintf(`vc5_tx_packets %d`, summary.EgressPackets))
r = append(r, fmt.Sprintf(`vc5_tx_octets %d`, summary.EgressOctets))
r = append(r, fmt.Sprintf(p+`_uptime %d`, summary.Uptime))
r = append(r, fmt.Sprintf(p+`_defcon %d`, defcon))
r = append(r, fmt.Sprintf(p+`_latency %d`, summary.Latency))
r = append(r, fmt.Sprintf(p+`_sessions %d`, summary.Current))
r = append(r, fmt.Sprintf(p+`_session_total %d`, summary.Flows))
r = append(r, fmt.Sprintf(p+`_rx_packets %d`, summary.IngressPackets))
r = append(r, fmt.Sprintf(p+`_rx_octets %d`, summary.IngressOctets))
r = append(r, fmt.Sprintf(p+`_tx_packets %d`, summary.EgressPackets))
r = append(r, fmt.Sprintf(p+`_tx_octets %d`, summary.EgressOctets))

zeroone := func(u bool) uint8 {
if u {
Expand All @@ -57,8 +57,8 @@ func prometheus(services map[netip.Addr][]Serv, summary Summary, vips map[netip.
now := time.Now()

for vip, s := range vips {
r = metric(r, `vc5_vip_status{vip="%s"} %d`, vip, zeroone(s.up))
r = metric(r, `vc5_vip_status_duration{vip="%s",status="%s"} %d`, vip, updown(s.up), now.Sub(s.time)/time.Second)
r = metric(r, p+`_vip_status{vip="%s"} %d`, vip, zeroone(s.up))
r = metric(r, p+`_vip_status_duration{vip="%s",status="%s"} %d`, vip, updown(s.up), now.Sub(s.time)/time.Second)
}

for _, x := range services {
Expand All @@ -72,29 +72,29 @@ func prometheus(services map[netip.Addr][]Serv, summary Summary, vips map[netip.
name = strings.ReplaceAll(name, `\`, `\\`)
name = strings.ReplaceAll(name, `"`, `\"`)

r = metric(r, `vc5_service_sessions{service="%s",name="%s"} %d`, serv, name, stat.Current)
r = metric(r, `vc5_service_sessions_total{service="%s",name="%s"} %d`, serv, name, stat.Flows)
r = metric(r, `vc5_service_rx_packets{service="%s",name="%s"} %d`, serv, name, stat.IngressPackets)
r = metric(r, `vc5_service_rx_octets{service="%s",name="%s"} %d`, serv, name, stat.IngressOctets)
r = metric(r, `vc5_service_tx_packets{service="%s",name="%s"} %d`, serv, name, stat.EgressPackets)
r = metric(r, `vc5_service_tx_octets{service="%s",name="%s"} %d`, serv, name, stat.EgressOctets)
r = metric(r, `vc5_service_status{service="%s",name="%s"} %d`, serv, name, up)
r = metric(r, `vc5_service_status_duration{service="%s",name="%s",status="%s"} %d`, serv, name, updown(s.Up), s.For)
r = metric(r, `vc5_service_reserves_used{service="%s",name="%s"} %d`, serv, name, 666)
r = metric(r, p+`_service_sessions{service="%s",name="%s"} %d`, serv, name, stat.Current)
r = metric(r, p+`_service_sessions_total{service="%s",name="%s"} %d`, serv, name, stat.Flows)
r = metric(r, p+`_service_rx_packets{service="%s",name="%s"} %d`, serv, name, stat.IngressPackets)
r = metric(r, p+`_service_rx_octets{service="%s",name="%s"} %d`, serv, name, stat.IngressOctets)
r = metric(r, p+`_service_tx_packets{service="%s",name="%s"} %d`, serv, name, stat.EgressPackets)
r = metric(r, p+`_service_tx_octets{service="%s",name="%s"} %d`, serv, name, stat.EgressOctets)
r = metric(r, p+`_service_status{service="%s",name="%s"} %d`, serv, name, up)
r = metric(r, p+`_service_status_duration{service="%s",name="%s",status="%s"} %d`, serv, name, updown(s.Up), s.For)
r = metric(r, p+`_service_reserves_used{service="%s",name="%s"} %d`, serv, name, 666)

for _, d := range s.Destinations {
real := fmt.Sprintf("%s:%d", d.Address, d.Port)
up := zeroone(d.Up)

r = metric(r, `vc5_backend_sessions{service="%s",name="%s",backend="%s"} %d`, serv, name, real, stat.Current)
r = metric(r, `vc5_backend_sessions_total{service="%s",name="%s",backend="%s"} %d`, serv, name, real, stat.Flows)
r = metric(r, `vc5_backend_rx_packets{service="%s",name="%s",backend="%s"} %d`, serv, name, real, stat.IngressPackets)
r = metric(r, `vc5_backend_rx_octets{service="%s",name="%s",backend="%s"} %d`, serv, name, real, stat.IngressOctets)
r = metric(r, `vc5_backend_tx_packets{service="%s",name="%s",backend="%s"} %d`, serv, name, real, stat.EgressPackets)
r = metric(r, `vc5_backend_tx_octets{service="%s",name="%s",backend="%s"} %d`, serv, name, real, stat.EgressOctets)
r = metric(r, `vc5_backend_status{service="%s",name="%s",backend="%s"} %d`, serv, name, real, up)
r = metric(r, `vc5_backend_status_duration{service="%s",name="%s",backend="%s",status="%s"} %d`, serv, name, real, updown(d.Up), d.For)
r = metric(r, `vc5_backend_reserves_used{service="%s",name="%s",backend="%s"} %d`, serv, name, real, 666)
r = metric(r, p+`_backend_sessions{service="%s",name="%s",backend="%s"} %d`, serv, name, real, stat.Current)
r = metric(r, p+`_backend_sessions_total{service="%s",name="%s",backend="%s"} %d`, serv, name, real, stat.Flows)
r = metric(r, p+`_backend_rx_packets{service="%s",name="%s",backend="%s"} %d`, serv, name, real, stat.IngressPackets)
r = metric(r, p+`_backend_rx_octets{service="%s",name="%s",backend="%s"} %d`, serv, name, real, stat.IngressOctets)
r = metric(r, p+`_backend_tx_packets{service="%s",name="%s",backend="%s"} %d`, serv, name, real, stat.EgressPackets)
r = metric(r, p+`_backend_tx_octets{service="%s",name="%s",backend="%s"} %d`, serv, name, real, stat.EgressOctets)
r = metric(r, p+`_backend_status{service="%s",name="%s",backend="%s"} %d`, serv, name, real, up)
r = metric(r, p+`_backend_status_duration{service="%s",name="%s",backend="%s",status="%s"} %d`, serv, name, real, updown(d.Up), d.For)
r = metric(r, p+`_backend_reserves_used{service="%s",name="%s",backend="%s"} %d`, serv, name, real, 666)

}
}
Expand All @@ -108,61 +108,61 @@ func metric(l []string, f string, a ...any) []string {
return append(l, fmt.Sprintf(f, a...))
}

func help() string {
return `# TYPE vc5_uptime counter
# TYPE vc5_defcon gauge
# TYPE vc5_latency gauge
# TYPE vc5_sessions gauge
# TYPE vc5_session_total counter
# TYPE vc5_rx_packets counter
# TYPE vc5_rx_octets counter
# TYPE vc5_tx_packets counter
# TYPE vc5_tx_octets counter
# TYPE vc5_vip_status gauge
# TYPE vc5_vip_status_duration gauge
# TYPE vc5_service_sessions gauge
# TYPE vc5_service_sessions_total counter
# TYPE vc5_service_rx_packets counter
# TYPE vc5_service_rx_octets counter
# TYPE vc5_service_tx_packets counter
# TYPE vc5_service_tx_octets counter
# TYPE vc5_service_status gauge
# TYPE vc5_service_status_duration gauge
# TYPE vc5_service_reserves_used gauge
# TYPE vc5_backend_sessions gauge
# TYPE vc5_backend_sessions_total counter
# TYPE vc5_backend_rx_packets counter
# TYPE vc5_backend_rx_octets counter
# TYPE vc5_backend_tx_packets counter
# TYPE vc5_backend_tx_octets counter
# TYPE vc5_backend_status gauge
# TYPE vc5_backend_status_duration gauge
# HELP vc5_uptime Uptime in seconds
# HELP vc5_defcon Readiness level
# HELP vc5_latency Average packet processing latency in nanoseconds
# HELP vc5_sessions Estimated number of current active sessions
# HELP vc5_session_total Total number of new sessions written to state tracking table
# HELP vc5_rx_packets Total number of incoming packets
# HELP vc5_rx_octets Total number incoming bytes
# HELP vc5_tx_packets Total number of outgoing packets
# HELP vc5_tx_octets Total number outgoing bytes
# HELP vc5_vip_status gauge
# HELP vc5_vip_status_duration gauge
# HELP vc5_service_sessions gauge
# HELP vc5_service_sessions_total counter
# HELP vc5_service_rx_packets counter
# HELP vc5_service_rx_octets counter
# HELP vc5_service_tx_packets counter
# HELP vc5_service_tx_octets counter
# HELP vc5_service_status gauge
# HELP vc5_service_status_duration gauge
# HELP vc5_service_reserves_used gauge
# HELP vc5_backend_sessions gauge
# HELP vc5_backend_sessions_total counter
# HELP vc5_backend_rx_packets counter
# HELP vc5_backend_rx_octets counter
# HELP vc5_backend_tx_packets counter
# HELP vc5_backend_tx_octets counter
# HELP vc5_backend_status gauge
# HELP vc5_backend_status_duration gauge`
func help(p string) string {
return `# TYPE ` + p + `_uptime counter
# TYPE ` + p + `_defcon gauge
# TYPE ` + p + `_latency gauge
# TYPE ` + p + `_sessions gauge
# TYPE ` + p + `_session_total counter
# TYPE ` + p + `_rx_packets counter
# TYPE ` + p + `_rx_octets counter
# TYPE ` + p + `_tx_packets counter
# TYPE ` + p + `_tx_octets counter
# TYPE ` + p + `_vip_status gauge
# TYPE ` + p + `_vip_status_duration gauge
# TYPE ` + p + `_service_sessions gauge
# TYPE ` + p + `_service_sessions_total counter
# TYPE ` + p + `_service_rx_packets counter
# TYPE ` + p + `_service_rx_octets counter
# TYPE ` + p + `_service_tx_packets counter
# TYPE ` + p + `_service_tx_octets counter
# TYPE ` + p + `_service_status gauge
# TYPE ` + p + `_service_status_duration gauge
# TYPE ` + p + `_service_reserves_used gauge
# TYPE ` + p + `_backend_sessions gauge
# TYPE ` + p + `_backend_sessions_total counter
# TYPE ` + p + `_backend_rx_packets counter
# TYPE ` + p + `_backend_rx_octets counter
# TYPE ` + p + `_backend_tx_packets counter
# TYPE ` + p + `_backend_tx_octets counter
# TYPE ` + p + `_backend_status gauge
# TYPE ` + p + `_backend_status_duration gauge
# HELP ` + p + `_uptime Uptime in seconds
# HELP ` + p + `_defcon Readiness level
# HELP ` + p + `_latency Average packet processing latency in nanoseconds
# HELP ` + p + `_sessions Estimated number of current active sessions
# HELP ` + p + `_session_total Total number of new sessions written to state tracking table
# HELP ` + p + `_rx_packets Total number of incoming packets
# HELP ` + p + `_rx_octets Total number incoming bytes
# HELP ` + p + `_tx_packets Total number of outgoing packets
# HELP ` + p + `_tx_octets Total number outgoing bytes
# HELP ` + p + `_vip_status gauge
# HELP ` + p + `_vip_status_duration gauge
# HELP ` + p + `_service_sessions gauge
# HELP ` + p + `_service_sessions_total counter
# HELP ` + p + `_service_rx_packets counter
# HELP ` + p + `_service_rx_octets counter
# HELP ` + p + `_service_tx_packets counter
# HELP ` + p + `_service_tx_octets counter
# HELP ` + p + `_service_status gauge
# HELP ` + p + `_service_status_duration gauge
# HELP ` + p + `_service_reserves_used gauge
# HELP ` + p + `_backend_sessions gauge
# HELP ` + p + `_backend_sessions_total counter
# HELP ` + p + `_backend_rx_packets counter
# HELP ` + p + `_backend_rx_octets counter
# HELP ` + p + `_backend_tx_packets counter
# HELP ` + p + `_backend_tx_octets counter
# HELP ` + p + `_backend_status gauge
# HELP ` + p + `_backend_status_duration gauge`
}
2 changes: 1 addition & 1 deletion cmd/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function summary_t(s, bgp) {
for(var peer of peers) {
var conn = bgp[peer];
append(hd, "th", "BGP: " + peer)
append(tr, "td", conn.state, conn.state == "ESTABLISHED" ? "up" : "dn")
append(tr, "td", conn.state + " " + dhms(conn.duration_s), conn.state == "ESTABLISHED" ? "up" : "dn")
}

return div
Expand Down

0 comments on commit 94e780c

Please sign in to comment.