diff --git a/central/processindicator/datastore/datastore_impl.go b/central/processindicator/datastore/datastore_impl.go index 887a4294d34d2..6f0623f301cb3 100644 --- a/central/processindicator/datastore/datastore_impl.go +++ b/central/processindicator/datastore/datastore_impl.go @@ -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)) } } diff --git a/central/processindicator/datastore/metrics.go b/central/processindicator/datastore/metrics.go index 601c2ed978273..958b1f178db1a 100644 --- a/central/processindicator/datastore/metrics.go +++ b/central/processindicator/datastore/metrics.go @@ -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" ) @@ -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) { @@ -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, ) }