Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions sensor/common/networkflow/manager/manager_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,34 @@ func (m *networkFlowManager) getCurrentContext() context.Context {
return m.pipelineCtx
}

func (m *networkFlowManager) updateEnrichmentCollectionsSize() {
numConnections := 0
numEndpoints := 0
concurrency.WithRLock(&m.connectionsByHostMutex, func() {
for _, hostConns := range m.connectionsByHost {
concurrency.WithLock(&hostConns.mutex, func() {
numConnections += len(hostConns.connections)
numEndpoints += len(hostConns.endpoints)
})
}
})
flowMetrics.EnrichmentCollectionsSize.WithLabelValues("connectionsInEnrichQueue", "connections").Set(float64(numConnections))
flowMetrics.EnrichmentCollectionsSize.WithLabelValues("endpointsInEnrichQueue", "endpoints").Set(float64(numEndpoints))

concurrency.WithRLock(&m.activeConnectionsMutex, func() {
flowMetrics.EnrichmentCollectionsSize.WithLabelValues("activeConnections", "connections").Set(float64(len(m.activeConnections)))
flowMetrics.EnrichmentCollectionsSize.WithLabelValues("activeEndpoints", "endpoints").Set(float64(len(m.activeEndpoints)))
})

concurrency.WithRLock(&m.lastSentStateMutex, func() {
flowMetrics.EnrichmentCollectionsSize.WithLabelValues("enrichedConnectionsLastSentState", "connections").Set(float64(len(m.enrichedConnsLastSentState)))
flowMetrics.EnrichmentCollectionsSize.WithLabelValues("enrichedEndpointsLastSentState", "endpoints").Set(float64(len(m.enrichedEndpointsLastSentState)))
flowMetrics.EnrichmentCollectionsSize.WithLabelValues("enrichedProcessesLastSentState", "processes").Set(float64(len(m.enrichedProcessesLastSentState)))
})
}

func (m *networkFlowManager) enrichAndSend() {
m.updateEnrichmentCollectionsSize()
// Takes host connections & endpoints and updates them by enriching with additional data.
// Updates m.activeEndpoints and m.activeConnections if lastSeen was reported as null by the Collector.
currentConns, currentEndpoints, currentProcesses := m.currentEnrichedConnsAndEndpoints()
Expand Down Expand Up @@ -636,8 +663,8 @@ func computeUpdatedEndpoints(current map[containerEndpointIndicator]timestamp.Mi
func computeUpdatedProcesses(current map[processListeningIndicator]timestamp.MicroTS, previous map[processListeningIndicator]timestamp.MicroTS, previousMutex *sync.RWMutex) []*storage.ProcessListeningOnPortFromSensor {
if !env.ProcessesListeningOnPort.BooleanSetting() {
if len(current) > 0 {
logging.GetRateLimitedLogger().Warn(loggingRateLimiter,
"Received process while ProcessesListeningOnPort feature is disabled. This may indicate a misconfiguration.", len(current))
logging.GetRateLimitedLogger().WarnL(loggingRateLimiter,
"Received process while ProcessesListeningOnPort feature is disabled. This may indicate a misconfiguration.")
}
return []*storage.ProcessListeningOnPortFromSensor{}
}
Expand Down Expand Up @@ -673,9 +700,11 @@ func (m *networkFlowManager) getAllHostConnections() []*hostConnections {
m.connectionsByHostMutex.RLock()
defer m.connectionsByHostMutex.RUnlock()

allHostConns := make([]*hostConnections, 0, len(m.connectionsByHost))
allHostConns := make([]*hostConnections, len(m.connectionsByHost))
i := 0
for _, hostConns := range m.connectionsByHost {
allHostConns = append(allHostConns, hostConns)
allHostConns[i] = hostConns // avoiding append() here improves the cpu time by 5-19%
i++
}
return allHostConns
}
Expand Down
9 changes: 9 additions & 0 deletions sensor/common/networkflow/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

func init() {
prometheus.MustRegister(
EnrichmentCollectionsSize,

// Host Connections
NetworkConnectionInfoMessagesRcvd,
NumUpdated,
Expand Down Expand Up @@ -38,6 +40,13 @@ const (

// Metrics for network flows
var (
EnrichmentCollectionsSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metrics.PrometheusNamespace,
Subsystem: metrics.SensorSubsystem.String(),
Name: hostConnectionsPrefix + "collections_size_current",
Help: "Current size of given collection involved in enrichment",
}, []string{"Name", "Type"})

// A networkConnectionInfo message arrives from collector

// NetworkConnectionInfoMessagesRcvd - 1. Collector sends NetworkConnection Info messages where each contains endpoints and connections
Expand Down
Loading