Skip to content

Commit

Permalink
metrics: add cilium_datapath_nat_gc_entries
Browse files Browse the repository at this point in the history
Signed-off-by: ArthurChiao <arthurchiao@hotmail.com>
  • Loading branch information
ArthurChiao authored and nathanjsweet committed Nov 19, 2020
1 parent e4bf8ca commit 57784e3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
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))
}
13 changes: 13 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,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 @@ -898,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

0 comments on commit 57784e3

Please sign in to comment.