github.com/containerd/Containerd@v1.4.13/metrics/cgroups/v1/blkio.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 v1 20 21 import ( 22 "strconv" 23 24 v1 "github.com/containerd/containerd/metrics/types/v1" 25 metrics "github.com/docker/go-metrics" 26 "github.com/prometheus/client_golang/prometheus" 27 ) 28 29 var blkioMetrics = []*metric{ 30 { 31 name: "blkio_io_merged_recursive", 32 help: "The blkio io merged recursive", 33 unit: metrics.Total, 34 vt: prometheus.GaugeValue, 35 labels: []string{"op", "device", "major", "minor"}, 36 getValues: func(stats *v1.Metrics) []value { 37 if stats.Blkio == nil { 38 return nil 39 } 40 return blkioValues(stats.Blkio.IoMergedRecursive) 41 }, 42 }, 43 { 44 name: "blkio_io_queued_recursive", 45 help: "The blkio io queued recursive", 46 unit: metrics.Total, 47 vt: prometheus.GaugeValue, 48 labels: []string{"op", "device", "major", "minor"}, 49 getValues: func(stats *v1.Metrics) []value { 50 if stats.Blkio == nil { 51 return nil 52 } 53 return blkioValues(stats.Blkio.IoQueuedRecursive) 54 }, 55 }, 56 { 57 name: "blkio_io_service_bytes_recursive", 58 help: "The blkio io service bytes recursive", 59 unit: metrics.Bytes, 60 vt: prometheus.GaugeValue, 61 labels: []string{"op", "device", "major", "minor"}, 62 getValues: func(stats *v1.Metrics) []value { 63 if stats.Blkio == nil { 64 return nil 65 } 66 return blkioValues(stats.Blkio.IoServiceBytesRecursive) 67 }, 68 }, 69 { 70 name: "blkio_io_service_time_recursive", 71 help: "The blkio io service time recursive", 72 unit: metrics.Total, 73 vt: prometheus.GaugeValue, 74 labels: []string{"op", "device", "major", "minor"}, 75 getValues: func(stats *v1.Metrics) []value { 76 if stats.Blkio == nil { 77 return nil 78 } 79 return blkioValues(stats.Blkio.IoServiceTimeRecursive) 80 }, 81 }, 82 { 83 name: "blkio_io_serviced_recursive", 84 help: "The blkio io serviced recursive", 85 unit: metrics.Total, 86 vt: prometheus.GaugeValue, 87 labels: []string{"op", "device", "major", "minor"}, 88 getValues: func(stats *v1.Metrics) []value { 89 if stats.Blkio == nil { 90 return nil 91 } 92 return blkioValues(stats.Blkio.IoServicedRecursive) 93 }, 94 }, 95 { 96 name: "blkio_io_time_recursive", 97 help: "The blkio io time recursive", 98 unit: metrics.Total, 99 vt: prometheus.GaugeValue, 100 labels: []string{"op", "device", "major", "minor"}, 101 getValues: func(stats *v1.Metrics) []value { 102 if stats.Blkio == nil { 103 return nil 104 } 105 return blkioValues(stats.Blkio.IoTimeRecursive) 106 }, 107 }, 108 { 109 name: "blkio_sectors_recursive", 110 help: "The blkio sectors recursive", 111 unit: metrics.Total, 112 vt: prometheus.GaugeValue, 113 labels: []string{"op", "device", "major", "minor"}, 114 getValues: func(stats *v1.Metrics) []value { 115 if stats.Blkio == nil { 116 return nil 117 } 118 return blkioValues(stats.Blkio.SectorsRecursive) 119 }, 120 }, 121 } 122 123 func blkioValues(l []*v1.BlkIOEntry) []value { 124 var out []value 125 for _, e := range l { 126 out = append(out, value{ 127 v: float64(e.Value), 128 l: []string{e.Op, e.Device, strconv.FormatUint(e.Major, 10), strconv.FormatUint(e.Minor, 10)}, 129 }) 130 } 131 return out 132 }