Skip to content

Commit

Permalink
tetragon: Add kprobe stats timer
Browse files Browse the repository at this point in the history
Adding kprobe stats timer that's responsible for retrieving missed
stats for attached kprobes and storing them as metrics.

The stats are collected every other second.

Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Mar 30, 2024
1 parent 1959f24 commit 9209527
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pkg/sensors/tracing/generickprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"net/http"
"path"
"strings"
"time"

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/link"
"github.com/cilium/tetragon/pkg/api/ops"
"github.com/cilium/tetragon/pkg/api/processapi"
api "github.com/cilium/tetragon/pkg/api/tracingapi"
Expand All @@ -34,6 +36,7 @@ import (
"github.com/cilium/tetragon/pkg/selectors"
"github.com/cilium/tetragon/pkg/sensors"
"github.com/cilium/tetragon/pkg/sensors/program"
"github.com/cilium/tetragon/pkg/timer"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -516,6 +519,34 @@ func getKprobeSymbols(symbol string, syscall bool, lists []v1alpha1.ListSpec) ([
return []string{symbol}, syscall, nil
}

func getKprobeStats(policyID policyfilter.PolicyID, policyName string, progs []*program.Program) {
for _, prog := range progs {
info, err := prog.Link.Info()
if err != nil {
continue
}

missed := uint64(0)

switch info.Type {
case link.PerfEventType:
pevent := info.PerfEvent()
switch pevent.PerfEventType {
case link.KprobePerfEventInfoType, link.KretprobePerfEventInfoType:
kprobe := pevent.Kprobe()
missed = kprobe.Missed
default:
}
case link.KprobeMultiType:
kmulti := info.KprobeMulti()
missed = kmulti.Missed
default:
}

kprobemetrics.MissedStore(uint32(policyID), policyName, prog.Attach, float64(missed))
}
}

func createGenericKprobeSensor(
spec *v1alpha1.TracingPolicySpec,
name string,
Expand Down Expand Up @@ -586,10 +617,24 @@ func createGenericKprobeSensor(
return nil, err
}

statsTimer := timer.NewPeriodicTimer("generickprobe stats timer",
func() { getKprobeStats(policyID, policyName, progs) }, true)

return &sensors.Sensor{
Name: name,
Progs: progs,
Maps: maps,
PostLoadHook: func() error {
statsTimer.Start(2 * time.Second)
return nil
},
PostUnloadHook: func() error {
statsTimer.Stop()
for _, prog := range progs {
kprobemetrics.MissedRemove(uint32(policyID), prog.Attach)
}
return nil
},
DestroyHook: func() error {
var errs error
for _, id := range ids {
Expand Down

0 comments on commit 9209527

Please sign in to comment.