Skip to content
Open
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
1 change: 1 addition & 0 deletions central/processindicator/datastore/datastore_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (ds *datastoreImpl) AddProcessIndicators(ctx context.Context, indicators ..
return err
}
} else {
recordProcessIndicatorsBatchAdded(identifierBatch)
log.Debugf("successfully added a batch of %d process indicators", len(identifierBatch))
}
}
Expand Down
42 changes: 42 additions & 0 deletions central/processindicator/datastore/metrics.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package datastore

import (
"unicode/utf8"

"github.com/prometheus/client_golang/prometheus"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/pkg/metrics"
)

Expand All @@ -26,6 +29,21 @@ var (
Name: "process_pruning_cache_misses",
Help: "Number of times we miss the cache, and have to evaluate, when trying to prune processes",
})

processUpsertedArgsSizeHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: metrics.PrometheusNamespace,
Subsystem: metrics.CentralSubsystem.String(),
Name: "process_upserted_args_size",
Help: "Distribution of process argument sizes in characters for upserted indicators",
Buckets: []float64{0, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536},
})

processUpsertedArgsSizeTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: metrics.PrometheusNamespace,
Subsystem: metrics.CentralSubsystem.String(),
Name: "process_upserted_args_size_total",
Help: "Total process argument sizes in characters by cluster and namespace",
}, []string{"cluster", "namespace"})
)

func incrementPrunedProcessesMetric(num int) {
Expand All @@ -40,10 +58,34 @@ func incrementProcessPruningCacheMissesMetric() {
processPruningCacheMisses.Inc()
}

// getProcessArgsSizeChars safely calculates the size of process args in characters (runes).
// Returns 0 if signal or args are nil/empty.
func getProcessArgsSizeChars(indicator *storage.ProcessIndicator) int {
if indicator == nil || indicator.GetSignal() == nil {
return 0
}
return utf8.RuneCountInString(indicator.GetSignal().GetArgs())
}

// recordProcessIndicatorsBatchAdded records metrics for a batch of process indicators successfully written to DB.
func recordProcessIndicatorsBatchAdded(indicators []*storage.ProcessIndicator) {
for _, indicator := range indicators {
argsSizeChars := getProcessArgsSizeChars(indicator)
clusterID := indicator.GetClusterId()
namespace := indicator.GetNamespace()

processUpsertedArgsSizeHistogram.Observe(float64(argsSizeChars))

processUpsertedArgsSizeTotal.WithLabelValues(clusterID, namespace).Add(float64(argsSizeChars))
}
}

func init() {
prometheus.MustRegister(
prunedProcesses,
processPruningCacheHits,
processPruningCacheMisses,
processUpsertedArgsSizeHistogram,
processUpsertedArgsSizeTotal,
)
}
Loading