-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backports/v1.0: Add a metric to provide per-event missed events
[upstream commit d5a7ee2] Example: $ curl localhost:2112/metrics 2> /dev/null | grep 'sent_events_total\|missed_events_total\|ringbuf_perf_event_lost_total\|ringbuf_queue_lost_total\|msg_op_total\|ringbuf_queue_received_total' tetragon_missed_events_total{msg_op="13"} 73300 tetragon_missed_events_total{msg_op="23"} 28 tetragon_missed_events_total{msg_op="24"} 606 tetragon_missed_events_total{msg_op="5"} 20 tetragon_missed_events_total{msg_op="7"} 22 tetragon_msg_op_total{msg_op="13"} 4.268532e+06 tetragon_msg_op_total{msg_op="23"} 12444 tetragon_msg_op_total{msg_op="24"} 2110 tetragon_msg_op_total{msg_op="5"} 11908 tetragon_msg_op_total{msg_op="7"} 12447 tetragon_ringbuf_perf_event_lost_total 73976 tetragon_ringbuf_queue_lost_total 0 tetragon_ringbuf_queue_received_total 4.307441e+06 This PR adds an eBPF map collector for getting metrics directly from a map. This map contains information about the return values of all perf_event_output calls (i.e. if it fails). This provides us the ability to determine missed events per type. Metric tetragon_missed_events_total contains such information. Using the previous example, we can see that we lost 73976 events from the user-space (tetragon_ringbuf_perf_event_lost_total). This is the same as the sum of all tetragon_missed_events_total metrics gathered from the kernel. Signed-off-by: Anastasios Papagiannis <tasos.papagiannnis@gmail.com>
- Loading branch information
Showing
20 changed files
with
110 additions
and
18 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
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 |
---|---|---|
|
@@ -29,6 +29,8 @@ enum msg_ops { | |
|
||
MSG_OP_CGROUP = 25, | ||
|
||
MSG_OP_LOADER = 26, | ||
|
||
MSG_OP_MAX, | ||
}; | ||
|
||
|
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
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
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
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
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
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
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,52 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Tetragon | ||
|
||
package eventmetrics | ||
|
||
import ( | ||
"path/filepath" | ||
"strconv" | ||
|
||
"github.com/cilium/ebpf" | ||
"github.com/cilium/tetragon/pkg/api/processapi" | ||
"github.com/cilium/tetragon/pkg/option" | ||
"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 <- MissedEvents.Desc() | ||
} | ||
|
||
func (c *bpfCollector) Collect(ch chan<- prometheus.Metric) { | ||
mapHandle, err := ebpf.LoadPinnedMap(filepath.Join(option.Config.MapDir, "tg_stats_map"), nil) | ||
if err != nil { | ||
return | ||
} | ||
defer mapHandle.Close() | ||
|
||
var zero uint32 | ||
var allCpuValue []processapi.KernelStats | ||
if err := mapHandle.Lookup(zero, &allCpuValue); err != nil { | ||
return | ||
} | ||
|
||
sum := processapi.KernelStats{} | ||
for _, val := range allCpuValue { | ||
for i, data := range val.SentFailed { | ||
sum.SentFailed[i] += data | ||
} | ||
} | ||
|
||
for i, data := range sum.SentFailed { | ||
if data > 0 { | ||
ch <- MissedEvents.MustMetric(float64(data), strconv.Itoa(i)) | ||
} | ||
} | ||
} |
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
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