-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Tetragon | ||
|
||
package probemetrics | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// bpfCollector implements prometheus.Collector. It collects metrics directly from BPF maps. | ||
type bpfCollector struct{} | ||
|
||
func NewBPFCollector() prometheus.Collector { | ||
return &bpfCollector{} | ||
} | ||
|
||
func (c *bpfCollector) Describe(ch chan<- *prometheus.Desc) { | ||
ch <- MissedProbes.Desc() | ||
} | ||
|
||
func (c *bpfCollector) Collect(ch chan<- prometheus.Metric) { | ||
lock.Lock() | ||
defer lock.Unlock() | ||
|
||
for key, stat := range stats { | ||
ch <- MissedProbes.MustMetric(stat.missed, stat.policy, key.attach) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Tetragon | ||
|
||
package probemetrics | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/cilium/tetragon/pkg/metrics" | ||
"github.com/cilium/tetragon/pkg/metrics/consts" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
type Key struct { | ||
id uint32 | ||
attach string | ||
} | ||
|
||
type Stat struct { | ||
policy string | ||
missed float64 | ||
} | ||
|
||
var ( | ||
MissedProbes = metrics.NewBPFCounter(prometheus.NewDesc( | ||
prometheus.BuildFQName(consts.MetricsNamespace, "", "missed_probes_total"), | ||
"The total number of Tetragon probe missed per policy,probe.", | ||
[]string{"policy", "attach"}, nil, | ||
)) | ||
|
||
lock sync.Mutex | ||
stats = make(map[Key]Stat) | ||
) | ||
|
||
func Store(id uint32, policy, attach string, missed float64) { | ||
key := Key{id, attach} | ||
if stat, found := stats[key]; found { | ||
stat.missed = missed | ||
stats[key] = stat | ||
} | ||
|
||
lock.Lock() | ||
defer lock.Unlock() | ||
|
||
stats[key] = Stat{ | ||
policy: policy, | ||
missed: missed, | ||
} | ||
} | ||
|
||
func Remove(id uint32, attach string) { | ||
lock.Lock() | ||
defer lock.Unlock() | ||
delete(stats, Key{id, attach}) | ||
} |