Skip to content

Commit

Permalink
tetragon: Add kprobe stats timer
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri committed Jan 22, 2024
1 parent eb71638 commit d53cdd7
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pkg/sensors/tracing/generickprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"net/http"
"path"
"strings"
"time"

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/link"
"github.com/cilium/tetragon/pkg/api/dataapi"
"github.com/cilium/tetragon/pkg/api/ops"
"github.com/cilium/tetragon/pkg/api/processapi"
Expand All @@ -31,6 +33,7 @@ import (
"github.com/cilium/tetragon/pkg/kernels"
"github.com/cilium/tetragon/pkg/logger"
"github.com/cilium/tetragon/pkg/metrics/kprobemetrics"
"github.com/cilium/tetragon/pkg/metrics/probemetrics"
"github.com/cilium/tetragon/pkg/observer"
"github.com/cilium/tetragon/pkg/option"
"github.com/cilium/tetragon/pkg/policyfilter"
Expand All @@ -39,6 +42,7 @@ import (
"github.com/cilium/tetragon/pkg/sensors"
"github.com/cilium/tetragon/pkg/sensors/program"
"github.com/cilium/tetragon/pkg/strutils"
"github.com/cilium/tetragon/pkg/timer"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -537,6 +541,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.Type {
case link.KprobePEIType, link.KretprobePEIType:
kprobe := pevent.Kprobe()
missed = kprobe.Missed
default:
}
case link.KprobeMultiType:
kmulti := info.KprobeMulti()
missed = kmulti.Missed
default:
}

probemetrics.Store(uint32(policyID), policyName, prog.Attach, float64(missed))
}
}

func createGenericKprobeSensor(
spec *v1alpha1.TracingPolicySpec,
name string,
Expand Down Expand Up @@ -607,10 +639,17 @@ 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 {
var errs error
for _, id := range ids {
Expand All @@ -626,6 +665,10 @@ func createGenericKprobeSensor(
gk.stackTraceMapRef = nil
}
}
statsTimer.Stop()
for _, prog := range progs {
probemetrics.Remove(uint32(policyID), prog.Attach)
}
return errs
},
DestroyHook: func() error {
Expand Down

0 comments on commit d53cdd7

Please sign in to comment.