Skip to content

Commit 0b7fc0e

Browse files
committed
Add promo metrics for openSSL tracker
Signed-off-by: Mohamed S. Mahmoud <[email protected]>
1 parent 1f00f09 commit 0b7fc0e

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

pkg/flow/tracer_ringbuf.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/binary"
77
"errors"
88
"fmt"
9+
"strconv"
910
"sync/atomic"
1011
"syscall"
1112
"time"
@@ -132,7 +133,7 @@ func (m *RingBufTracer) listenAndForwardRingBuffer(debugging bool, forwardCh cha
132133
return nil
133134
}
134135

135-
func (m *RingBufTracer) listenAndForwardRingBufferSSL(forwardCh chan<- *model.RawRecord) error {
136+
func (m *RingBufTracer) listenAndForwardRingBufferSSL(_ chan<- *model.RawRecord) error {
136137
rtlog.Debug("listenAndForwardRingBufferSSL: waiting for SSL event...")
137138
event, err := m.ringBufferSSL.ReadSSLRingBuf()
138139
if err != nil {
@@ -175,12 +176,13 @@ func (m *RingBufTracer) listenAndForwardRingBufferSSL(forwardCh chan<- *model.Ra
175176
rtlog.Warnf("Failed to read SSL data: read %d/%d bytes, err=%v", n, dataLen, err)
176177
}
177178

178-
rtlog.Infof("SSL EVENT: pid=%d, timestamp=%d, data_len=%d, ssl_type=%d",
179+
rtlog.Debugf("SSL EVENT: pid=%d, timestamp=%d, data_len=%d, ssl_type=%d",
179180
pidTgid, timestamp, dataLen, sslType)
180181
printLen := min(256, len(data))
181-
rtlog.Infof("SSL data as string: %s", string(data[:printLen]))
182+
rtlog.Debugf("SSL data as string: %s", string(data[:printLen]))
183+
m.metrics.OpenSSLDataEventsCounter.Increase(strconv.Itoa(int(sslType)), int(dataLen))
182184
} else {
183-
rtlog.Infof("SSL EVENT: pid=%d, timestamp=%d, data_len=%d (invalid), ssl_type=%d",
185+
rtlog.Debugf("SSL EVENT: pid=%d, timestamp=%d, data_len=%d (invalid), ssl_type=%d",
184186
pidTgid, timestamp, dataLen, sslType)
185187
}
186188

pkg/metrics/metrics.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ var (
164164
"mac",
165165
"retries",
166166
)
167+
opensslDataEventsCounter = defineMetric(
168+
"openssl_data_events_total",
169+
"Number of OpenSSL data events",
170+
TypeCounter,
171+
"openssl_type",
172+
"data_len",
173+
)
167174
)
168175

169176
func (def *MetricDefinition) mapLabels(labels []string) prometheus.Labels {
@@ -194,16 +201,17 @@ type Metrics struct {
194201
Settings *Settings
195202

196203
// Shared metrics:
197-
EvictionCounter *EvictionCounter
198-
EvictedFlowsCounter *EvictionCounter
199-
EvictedPacketsCounter *EvictionCounter
200-
DroppedFlowsCounter *EvictionCounter
201-
FilteredFlowsCounter *EvictionCounter
202-
NetworkEventsCounter *EvictionCounter
203-
FlowBufferSizeGauge *FlowBufferSizeGauge
204-
Errors *ErrorCounter
205-
FlowEnrichmentCounter *FlowEnrichmentCounter
206-
InterfaceEventsCounter *InterfaceEventsCounter
204+
EvictionCounter *EvictionCounter
205+
EvictedFlowsCounter *EvictionCounter
206+
EvictedPacketsCounter *EvictionCounter
207+
DroppedFlowsCounter *EvictionCounter
208+
FilteredFlowsCounter *EvictionCounter
209+
NetworkEventsCounter *EvictionCounter
210+
FlowBufferSizeGauge *FlowBufferSizeGauge
211+
Errors *ErrorCounter
212+
FlowEnrichmentCounter *FlowEnrichmentCounter
213+
InterfaceEventsCounter *InterfaceEventsCounter
214+
OpenSSLDataEventsCounter *OpenSSLDataEventsCounter
207215
}
208216

209217
func NewMetrics(settings *Settings) *Metrics {
@@ -220,6 +228,7 @@ func NewMetrics(settings *Settings) *Metrics {
220228
m.Errors = &ErrorCounter{vec: m.NewCounterVec(&errorsCounter)}
221229
m.FlowEnrichmentCounter = &FlowEnrichmentCounter{vec: m.NewCounterVec(&flowEnrichmentCounter)}
222230
m.InterfaceEventsCounter = newInterfaceEventsCounter(m.NewCounterVec(&interfaceEventsCounter), settings.Level)
231+
m.OpenSSLDataEventsCounter = &OpenSSLDataEventsCounter{vec: m.NewCounterVec(&opensslDataEventsCounter)}
223232
return m
224233
}
225234

@@ -346,6 +355,14 @@ type InterfaceEventsCounter struct {
346355
Increase func(typez, ifname string, ifindex int, netns string, mac [6]uint8, retries int)
347356
}
348357

358+
type OpenSSLDataEventsCounter struct {
359+
vec *prometheus.CounterVec
360+
}
361+
362+
func (c *OpenSSLDataEventsCounter) Increase(sslType string, dataLen int) {
363+
c.vec.WithLabelValues(sslType, strconv.Itoa(dataLen)).Inc()
364+
}
365+
349366
func newInterfaceEventsCounter(vec *prometheus.CounterVec, lvl Level) *InterfaceEventsCounter {
350367
switch lvl {
351368
case LevelTrace:

0 commit comments

Comments
 (0)