github.com/containerd/containerd@v22.0.0-20200918172823-438c87b8e050+incompatible/metrics/cgroups/v1/pids.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  	v1 "github.com/containerd/containerd/metrics/types/v1"
    23  	metrics "github.com/docker/go-metrics"
    24  	"github.com/prometheus/client_golang/prometheus"
    25  )
    26  
    27  var pidMetrics = []*metric{
    28  	{
    29  		name: "pids",
    30  		help: "The limit to the number of pids allowed",
    31  		unit: metrics.Unit("limit"),
    32  		vt:   prometheus.GaugeValue,
    33  		getValues: func(stats *v1.Metrics) []value {
    34  			if stats.Pids == nil {
    35  				return nil
    36  			}
    37  			return []value{
    38  				{
    39  					v: float64(stats.Pids.Limit),
    40  				},
    41  			}
    42  		},
    43  	},
    44  	{
    45  		name: "pids",
    46  		help: "The current number of pids",
    47  		unit: metrics.Unit("current"),
    48  		vt:   prometheus.GaugeValue,
    49  		getValues: func(stats *v1.Metrics) []value {
    50  			if stats.Pids == nil {
    51  				return nil
    52  			}
    53  			return []value{
    54  				{
    55  					v: float64(stats.Pids.Current),
    56  				},
    57  			}
    58  		},
    59  	},
    60  }