@@ -275,6 +275,14 @@ func (c *criService) collectContainerMetrics(ctx context.Context, container cont
275275 containerMetrics .Metrics = append (containerMetrics .Metrics , fsMetrics ... )
276276 }
277277
278+ // Collect process metrics
279+ processMetrics , err := c .extractProcessMetrics (stats , containerLabels , timestamp )
280+ if err != nil {
281+ log .G (ctx ).WithField ("containerid" , container .ID ).WithError (err ).Debug ("failed to extract process metrics" )
282+ } else {
283+ containerMetrics .Metrics = append (containerMetrics .Metrics , processMetrics ... )
284+ }
285+
278286 return containerMetrics , nil
279287}
280288
@@ -805,6 +813,58 @@ func (c *criService) extractDiskMetrics(stats interface{}, labels []string, time
805813 return metrics , nil
806814}
807815
816+ // extractProcessMetrics extracts process-related metrics from container stats
817+ func (c * criService ) extractProcessMetrics (stats interface {}, labels []string , timestamp int64 ) ([]* runtime.Metric , error ) {
818+ var metrics []* runtime.Metric
819+
820+ switch s := stats .(type ) {
821+ case * cg1.Metrics :
822+ if s .Pids != nil {
823+ metrics = append (metrics , []* runtime.Metric {
824+ {
825+ Name : "container_processes" ,
826+ Timestamp : timestamp ,
827+ MetricType : runtime .MetricType_GAUGE ,
828+ LabelValues : labels ,
829+ Value : & runtime.UInt64Value {Value : s .Pids .Current },
830+ },
831+ {
832+ Name : "container_threads_max" ,
833+ Timestamp : timestamp ,
834+ MetricType : runtime .MetricType_GAUGE ,
835+ LabelValues : labels ,
836+ Value : & runtime.UInt64Value {Value : s .Pids .Limit },
837+ },
838+ }... )
839+ }
840+
841+ case * cg2.Metrics :
842+ if s .Pids != nil {
843+ metrics = append (metrics , []* runtime.Metric {
844+ {
845+ Name : "container_processes" ,
846+ Timestamp : timestamp ,
847+ MetricType : runtime .MetricType_GAUGE ,
848+ LabelValues : labels ,
849+ Value : & runtime.UInt64Value {Value : s .Pids .Current },
850+ },
851+ {
852+ Name : "container_threads_max" ,
853+ Timestamp : timestamp ,
854+ MetricType : runtime .MetricType_GAUGE ,
855+ LabelValues : labels ,
856+ Value : & runtime.UInt64Value {Value : s .Pids .Limit },
857+ },
858+ }... )
859+ }
860+
861+ default :
862+ return nil , fmt .Errorf ("unexpected metrics type: %T from %s" , s , reflect .TypeOf (s ).Elem ().PkgPath ())
863+ }
864+
865+ return metrics , nil
866+ }
867+
808868// extractFilesystemMetrics extracts filesystem-related metrics from container stats
809869func (c * criService ) extractFilesystemMetrics (ctx context.Context , containerID string , labels []string , timestamp int64 ) ([]* runtime.Metric , error ) {
810870 var metrics []* runtime.Metric
0 commit comments