mirror of
https://github.com/slackhq/nebula.git
synced 2024-11-14 20:05:53 +08:00
b37a91cfbc
This change add more metrics around "meta" (non "message" type packets). For lighthouse packets, we also record statistics around the specific lighthouse meta type. We don't keep statistics for the "message" type so that we don't slow down the fast path (and you can just look at metrics on the tun interface to find that information).
97 lines
2.6 KiB
Go
97 lines
2.6 KiB
Go
package nebula
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/rcrowley/go-metrics"
|
|
)
|
|
|
|
type MessageMetrics struct {
|
|
rx [][]metrics.Counter
|
|
tx [][]metrics.Counter
|
|
|
|
rxUnknown metrics.Counter
|
|
txUnknown metrics.Counter
|
|
}
|
|
|
|
func (m *MessageMetrics) Rx(t NebulaMessageType, s NebulaMessageSubType, i int64) {
|
|
if m != nil {
|
|
if t >= 0 && int(t) < len(m.rx) && s >= 0 && int(s) < len(m.rx[t]) {
|
|
m.rx[t][s].Inc(i)
|
|
} else if m.rxUnknown != nil {
|
|
m.rxUnknown.Inc(i)
|
|
}
|
|
}
|
|
}
|
|
func (m *MessageMetrics) Tx(t NebulaMessageType, s NebulaMessageSubType, i int64) {
|
|
if m != nil {
|
|
if t >= 0 && int(t) < len(m.tx) && s >= 0 && int(s) < len(m.tx[t]) {
|
|
m.tx[t][s].Inc(i)
|
|
} else if m.txUnknown != nil {
|
|
m.txUnknown.Inc(i)
|
|
}
|
|
}
|
|
}
|
|
|
|
func newMessageMetrics() *MessageMetrics {
|
|
gen := func(t string) [][]metrics.Counter {
|
|
return [][]metrics.Counter{
|
|
{
|
|
metrics.GetOrRegisterCounter(fmt.Sprintf("messages.%s.handshake_ixpsk0", t), nil),
|
|
},
|
|
nil,
|
|
{metrics.GetOrRegisterCounter(fmt.Sprintf("messages.%s.recv_error", t), nil)},
|
|
{metrics.GetOrRegisterCounter(fmt.Sprintf("messages.%s.lighthouse", t), nil)},
|
|
{
|
|
metrics.GetOrRegisterCounter(fmt.Sprintf("messages.%s.test_request", t), nil),
|
|
metrics.GetOrRegisterCounter(fmt.Sprintf("messages.%s.test_response", t), nil),
|
|
},
|
|
{metrics.GetOrRegisterCounter(fmt.Sprintf("messages.%s.close_tunnel", t), nil)},
|
|
}
|
|
}
|
|
return &MessageMetrics{
|
|
rx: gen("rx"),
|
|
tx: gen("tx"),
|
|
|
|
rxUnknown: metrics.GetOrRegisterCounter("messages.rx.other", nil),
|
|
txUnknown: metrics.GetOrRegisterCounter("messages.tx.other", nil),
|
|
}
|
|
}
|
|
|
|
// Historically we only recorded recv_error, so this is backwards compat
|
|
func newMessageMetricsOnlyRecvError() *MessageMetrics {
|
|
gen := func(t string) [][]metrics.Counter {
|
|
return [][]metrics.Counter{
|
|
nil,
|
|
nil,
|
|
{metrics.GetOrRegisterCounter(fmt.Sprintf("messages.%s.recv_error", t), nil)},
|
|
}
|
|
}
|
|
return &MessageMetrics{
|
|
rx: gen("rx"),
|
|
tx: gen("tx"),
|
|
}
|
|
}
|
|
|
|
func newLighthouseMetrics() *MessageMetrics {
|
|
gen := func(t string) [][]metrics.Counter {
|
|
h := make([][]metrics.Counter, len(NebulaMeta_MessageType_name))
|
|
used := []NebulaMeta_MessageType{
|
|
NebulaMeta_HostQuery,
|
|
NebulaMeta_HostQueryReply,
|
|
NebulaMeta_HostUpdateNotification,
|
|
NebulaMeta_HostPunchNotification,
|
|
}
|
|
for _, i := range used {
|
|
h[i] = []metrics.Counter{metrics.GetOrRegisterCounter(fmt.Sprintf("lighthouse.%s.%s", t, i.String()), nil)}
|
|
}
|
|
return h
|
|
}
|
|
return &MessageMetrics{
|
|
rx: gen("rx"),
|
|
tx: gen("tx"),
|
|
|
|
rxUnknown: metrics.GetOrRegisterCounter("lighthouse.rx.other", nil),
|
|
txUnknown: metrics.GetOrRegisterCounter("lighthouse.tx.other", nil),
|
|
}
|
|
}
|