...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/metrics/metrics.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/metrics

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package metrics
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"github.com/prometheus/client_golang/prometheus"
    21  	"go.opencensus.io/stats"
    22  )
    23  
    24  var (
    25  	namespace = "configconnector"
    26  	labels    = []string{"namespace", "group_version_kind", "status"}
    27  )
    28  
    29  // metrics defined in the format of OpenCensus
    30  var (
    31  	MReconcileOccupiedWorkers = stats.Int64("ReconcileOccupiedWorkers", "The number of occupied reconcile workers", stats.UnitDimensionless)
    32  	MReconcileTotalWorkers    = stats.Int64("ReconcileTotalWorkers", "The number of total reconcile workers", stats.UnitDimensionless)
    33  	MReconcileRequests        = stats.Int64("ReconcileRequests", "The number of reconcile requests", stats.UnitDimensionless)
    34  	MInternalErrors           = stats.Int64("InternalErrorsTotal", "The number of internal errors", stats.UnitDimensionless)
    35  	MReconcileDuration        = stats.Float64("ReconcileDuration", "The duration of reconcile requests", "seconds")
    36  	MProcessStartTime         = stats.Float64("ProcessStartTimeSeconds", "Start time of the process since unix epoch in seconds", "seconds")
    37  )
    38  
    39  // metrics defined in the format of prometheus/client_golang
    40  func NewAppliedResourcesCollector() *prometheus.GaugeVec {
    41  	return prometheus.NewGaugeVec(prometheus.GaugeOpts{
    42  		Namespace: namespace,
    43  		Name:      "applied_resources_total",
    44  		Help:      "The number of applied resources",
    45  	}, labels)
    46  }
    47  
    48  func NewBuildInfoCollector(version string) prometheus.Collector {
    49  	return prometheus.NewGaugeFunc(
    50  		prometheus.GaugeOpts{
    51  			Namespace: namespace,
    52  			Name:      "build_info",
    53  			Help: fmt.Sprintf(
    54  				"A metric with a constant '1' value labeled by version from which %s was built.",
    55  				namespace,
    56  			),
    57  			ConstLabels: prometheus.Labels{
    58  				"version": version,
    59  			},
    60  		},
    61  		func() float64 { return 1 },
    62  	)
    63  }
    64  

View as plain text