Add Event
Overview
- Type: Exception event-driven(tracing/event)
- Function:Continuously runs in the system and captures context information when preset thresholds are reached
- Characteristics:
- Unlike
autotracing,eventruns continuously rather than being triggered only when exceptions occur. - Event data is stored locally in real-time and also sent to remote ES. You can also generate Prometheus metrics for observation.
- Suitable for continuous monitoring and real-time analysis, enabling timely detection of abnormal behaviors in the system. The performance impact of
eventtype collection is negligible.
- Unlike
- Already Integrated: Soft interrupt abnormalities(softirq)、abnormal memory allocation(oom)、soft lockups(softlockup)、D-state processes(hungtask)、memory reclaim(memreclaim)、abnormal packet loss(dropwatch)、network inbound latency (net_rx_latency), etc.
How to Add Event Metrics
Simply implement the ITracingEvent interface and complete registration to add events to the system.
There is no implementation difference between
AutoTracingandEventin the framework; they are only differentiated based on practical application scenarios.
// ITracingEvent represents a tracing/event
type ITracingEvent interface {
Start(ctx context.Context) error
}
1. Create Event Structure
type exampleTracing struct{}
2. Register Callback Function
func init() {
tracing.RegisterEventTracing("example", newExample)
}
func newExample() (*tracing.EventTracingAttr, error) {
return &tracing.EventTracingAttr{
TracingData: &exampleTracing{},
Internal: 10, // Interval in seconds before re-enabling tracing
Flag: tracing.FlagTracing, // Mark as tracing type; | tracing.FlagMetric (optional)
}, nil
}
3. Implement the ITracingEvent Interface
func (t *exampleTracing) Start(ctx context.Context) error {
// do something
...
// Store data to ES and locally
storage.Save("example", ccontainerID, time.Now(), tracerData)
}
Additionally, you can optionally implement the Collector interface to output in Prometheus format:
func (c *exampleTracing) Update() ([]*metric.Data, error) {
// from tracerData to prometheus.Metric
...
return data, nil
}
The core/events directory in the project has integrated various practical events examples, along with rich underlying interfaces provided by the framework, including BPF program and map data interaction, container information, etc. For more details, refer to the corresponding code implementations.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.