Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics: add cilium_datapath_nat_gc_entries #12832

Merged
merged 2 commits into from
Nov 19, 2020
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
11 changes: 10 additions & 1 deletion pkg/maps/ctmap/ctmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ const (

metricsAlive = "alive"
metricsDeleted = "deleted"

metricsIngress = "ingress"
metricsEgress = "egress"
)

type action int
Expand Down Expand Up @@ -555,7 +558,13 @@ func PurgeOrphanNATEntries(ctMapTCP, ctMapAny *Map) *NatGCStats {
return nil
}

stats := newNatGCStats(natMap)
family := gcFamilyIPv4
if ctMapTCP.mapType.isIPv6() {
family = gcFamilyIPv6
}
stats := newNatGCStats(natMap, family)
defer stats.finish()

cb := func(key bpf.MapKey, value bpf.MapValue) {
natKey := key.(nat.NatKey)
natVal := value.(nat.NatEntry)
Expand Down
13 changes: 12 additions & 1 deletion pkg/maps/ctmap/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,26 @@ func (s *gcStats) finish() {
type NatGCStats struct {
*bpf.DumpStats

// family is the address family
Family gcFamily

IngressAlive uint32
IngressDeleted uint32
EgressDeleted uint32
// It's not possible with the current PurgeOrphanNATEntries implementation
// to correctly count EgressAlive, so skip it
}

func newNatGCStats(m NatMap) NatGCStats {
func newNatGCStats(m NatMap, family gcFamily) NatGCStats {
return NatGCStats{
DumpStats: m.DumpStats(),
Family: family,
}
}

func (s *NatGCStats) finish() {
family := s.Family.String()
metrics.NatGCSize.WithLabelValues(family, metricsIngress, metricsAlive).Set(float64(s.IngressAlive))
metrics.NatGCSize.WithLabelValues(family, metricsIngress, metricsDeleted).Set(float64(s.IngressDeleted))
metrics.NatGCSize.WithLabelValues(family, metricsEgress, metricsDeleted).Set(float64(s.EgressDeleted))
}
24 changes: 20 additions & 4 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ const (

// LabelVersion is the label for the version number
LabelVersion = "version"

// LabelDirection is the label for traffic direction
LabelDirection = "direction"
)

var (
Expand Down Expand Up @@ -311,6 +314,9 @@ var (
// ConntrackGCSize the number of entries in the conntrack table
ConntrackGCSize = NoOpGaugeVec

// NatGCSize the number of entries in the nat table
NatGCSize = NoOpGaugeVec

// ConntrackGCDuration the duration of the conntrack GC process in milliseconds.
ConntrackGCDuration = NoOpObserverVec

Expand Down Expand Up @@ -811,7 +817,7 @@ func CreateConfiguration(metricsEnabled []string) (Configuration, []prometheus.C
Name: "drop_count_total",
Help: "Total dropped packets, tagged by drop reason and ingress/egress direction",
},
[]string{"reason", "direction"})
[]string{"reason", LabelDirection})

collectors = append(collectors, DropCount)
c.DropCountEnabled = true
Expand All @@ -822,7 +828,7 @@ func CreateConfiguration(metricsEnabled []string) (Configuration, []prometheus.C
Name: "drop_bytes_total",
Help: "Total dropped bytes, tagged by drop reason and ingress/egress direction",
},
[]string{"reason", "direction"})
[]string{"reason", LabelDirection})

collectors = append(collectors, DropBytes)
c.DropBytesEnabled = true
Expand All @@ -833,7 +839,7 @@ func CreateConfiguration(metricsEnabled []string) (Configuration, []prometheus.C
Name: "forward_count_total",
Help: "Total forwarded packets, tagged by ingress/egress direction",
},
[]string{"direction"})
[]string{LabelDirection})

collectors = append(collectors, ForwardCount)
c.NoOpCounterVecEnabled = true
Expand All @@ -844,7 +850,7 @@ func CreateConfiguration(metricsEnabled []string) (Configuration, []prometheus.C
Name: "forward_bytes_total",
Help: "Total forwarded bytes, tagged by ingress/egress direction",
},
[]string{"direction"})
[]string{LabelDirection})

collectors = append(collectors, ForwardBytes)
c.ForwardBytesEnabled = true
Expand Down Expand Up @@ -895,6 +901,16 @@ func CreateConfiguration(metricsEnabled []string) (Configuration, []prometheus.C
collectors = append(collectors, ConntrackGCSize)
c.ConntrackGCSizeEnabled = true

NatGCSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: SubsystemDatapath,
Name: "nat_gc_entries",
Help: "The number of alive and deleted nat entries at the end " +
"of a garbage collector run labeled by datapath family.",
}, []string{LabelDatapathFamily, LabelDirection, LabelStatus})

collectors = append(collectors, NatGCSize)

case Namespace + "_" + SubsystemDatapath + "_conntrack_gc_duration_seconds":
ConntrackGCDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: Namespace,
Expand Down