github.com/containerd/Containerd@v1.4.13/metrics/cgroups/v2/cpu.go (about)

     1  // +build linux
     2  
     3  /*
     4     Copyright The containerd Authors.
     5  
     6     Licensed under the Apache License, Version 2.0 (the "License");
     7     you may not use this file except in compliance with the License.
     8     You may obtain a copy of the License at
     9  
    10         http://www.apache.org/licenses/LICENSE-2.0
    11  
    12     Unless required by applicable law or agreed to in writing, software
    13     distributed under the License is distributed on an "AS IS" BASIS,
    14     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15     See the License for the specific language governing permissions and
    16     limitations under the License.
    17  */
    18  
    19  package v2
    20  
    21  import (
    22  	v2 "github.com/containerd/containerd/metrics/types/v2"
    23  	metrics "github.com/docker/go-metrics"
    24  	"github.com/prometheus/client_golang/prometheus"
    25  )
    26  
    27  var cpuMetrics = []*metric{
    28  	{
    29  		name: "cpu_usage_usec",
    30  		help: "Total cpu usage (cgroup v2)",
    31  		unit: metrics.Unit("microseconds"),
    32  		vt:   prometheus.GaugeValue,
    33  		getValues: func(stats *v2.Metrics) []value {
    34  			if stats.CPU == nil {
    35  				return nil
    36  			}
    37  			return []value{
    38  				{
    39  					v: float64(stats.CPU.UsageUsec),
    40  				},
    41  			}
    42  		},
    43  	},
    44  	{
    45  		name: "cpu_user_usec",
    46  		help: "Current cpu usage in user space (cgroup v2)",
    47  		unit: metrics.Unit("microseconds"),
    48  		vt:   prometheus.GaugeValue,
    49  		getValues: func(stats *v2.Metrics) []value {
    50  			if stats.CPU == nil {
    51  				return nil
    52  			}
    53  			return []value{
    54  				{
    55  					v: float64(stats.CPU.UserUsec),
    56  				},
    57  			}
    58  		},
    59  	},
    60  	{
    61  		name: "cpu_system_usec",
    62  		help: "Current cpu usage in kernel space (cgroup v2)",
    63  		unit: metrics.Unit("microseconds"),
    64  		vt:   prometheus.GaugeValue,
    65  		getValues: func(stats *v2.Metrics) []value {
    66  			if stats.CPU == nil {
    67  				return nil
    68  			}
    69  			return []value{
    70  				{
    71  					v: float64(stats.CPU.SystemUsec),
    72  				},
    73  			}
    74  		},
    75  	},
    76  	{
    77  		name: "cpu_nr_periods",
    78  		help: "Current cpu number of periods (only if controller is enabled)",
    79  		unit: metrics.Total,
    80  		vt:   prometheus.GaugeValue,
    81  		getValues: func(stats *v2.Metrics) []value {
    82  			if stats.CPU == nil {
    83  				return nil
    84  			}
    85  			return []value{
    86  				{
    87  					v: float64(stats.CPU.NrPeriods),
    88  				},
    89  			}
    90  		},
    91  	},
    92  	{
    93  		name: "cpu_nr_throttled",
    94  		help: "Total number of times tasks have been throttled (only if controller is enabled)",
    95  		unit: metrics.Total,
    96  		vt:   prometheus.GaugeValue,
    97  		getValues: func(stats *v2.Metrics) []value {
    98  			if stats.CPU == nil {
    99  				return nil
   100  			}
   101  			return []value{
   102  				{
   103  					v: float64(stats.CPU.NrThrottled),
   104  				},
   105  			}
   106  		},
   107  	},
   108  	{
   109  		name: "cpu_throttled_usec",
   110  		help: "Total time duration for which tasks have been throttled. (only if controller is enabled)",
   111  		unit: metrics.Unit("microseconds"),
   112  		vt:   prometheus.GaugeValue,
   113  		getValues: func(stats *v2.Metrics) []value {
   114  			if stats.CPU == nil {
   115  				return nil
   116  			}
   117  			return []value{
   118  				{
   119  					v: float64(stats.CPU.ThrottledUsec),
   120  				},
   121  			}
   122  		},
   123  	},
   124  }