github.com/containerd/Containerd@v1.4.13/metrics/cgroups/v2/io.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  	"strconv"
    23  
    24  	v2 "github.com/containerd/containerd/metrics/types/v2"
    25  	metrics "github.com/docker/go-metrics"
    26  	"github.com/prometheus/client_golang/prometheus"
    27  )
    28  
    29  var ioMetrics = []*metric{
    30  	{
    31  		name:   "io_rbytes",
    32  		help:   "IO bytes read",
    33  		unit:   metrics.Bytes,
    34  		vt:     prometheus.GaugeValue,
    35  		labels: []string{"major", "minor"},
    36  		getValues: func(stats *v2.Metrics) []value {
    37  			if stats.Io == nil {
    38  				return nil
    39  			}
    40  			var out []value
    41  			for _, e := range stats.Io.Usage {
    42  				out = append(out, value{
    43  					v: float64(e.Rbytes),
    44  					l: []string{strconv.FormatUint(e.Major, 10), strconv.FormatUint(e.Minor, 10)},
    45  				})
    46  			}
    47  			return out
    48  		},
    49  	},
    50  	{
    51  		name:   "io_wbytes",
    52  		help:   "IO bytes written",
    53  		unit:   metrics.Bytes,
    54  		vt:     prometheus.GaugeValue,
    55  		labels: []string{"major", "minor"},
    56  		getValues: func(stats *v2.Metrics) []value {
    57  			if stats.Io == nil {
    58  				return nil
    59  			}
    60  			var out []value
    61  			for _, e := range stats.Io.Usage {
    62  				out = append(out, value{
    63  					v: float64(e.Wbytes),
    64  					l: []string{strconv.FormatUint(e.Major, 10), strconv.FormatUint(e.Minor, 10)},
    65  				})
    66  			}
    67  			return out
    68  		},
    69  	},
    70  	{
    71  		name:   "io_rios",
    72  		help:   "Number of read IOs",
    73  		unit:   metrics.Total,
    74  		vt:     prometheus.GaugeValue,
    75  		labels: []string{"major", "minor"},
    76  		getValues: func(stats *v2.Metrics) []value {
    77  			if stats.Io == nil {
    78  				return nil
    79  			}
    80  			var out []value
    81  			for _, e := range stats.Io.Usage {
    82  				out = append(out, value{
    83  					v: float64(e.Rios),
    84  					l: []string{strconv.FormatUint(e.Major, 10), strconv.FormatUint(e.Minor, 10)},
    85  				})
    86  			}
    87  			return out
    88  		},
    89  	},
    90  	{
    91  		name:   "io_wios",
    92  		help:   "Number of write IOs",
    93  		unit:   metrics.Total,
    94  		vt:     prometheus.GaugeValue,
    95  		labels: []string{"major", "minor"},
    96  		getValues: func(stats *v2.Metrics) []value {
    97  			if stats.Io == nil {
    98  				return nil
    99  			}
   100  			var out []value
   101  			for _, e := range stats.Io.Usage {
   102  				out = append(out, value{
   103  					v: float64(e.Wios),
   104  					l: []string{strconv.FormatUint(e.Major, 10), strconv.FormatUint(e.Minor, 10)},
   105  				})
   106  			}
   107  			return out
   108  		},
   109  	},
   110  }