1 /* 2 Copyright 2019 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package metrics 18 19 import ( 20 "time" 21 22 "k8s.io/klog/v2" 23 ) 24 25 var processStartTime = NewGaugeVec( 26 &GaugeOpts{ 27 Name: "process_start_time_seconds", 28 Help: "Start time of the process since unix epoch in seconds.", 29 StabilityLevel: ALPHA, 30 }, 31 []string{}, 32 ) 33 34 // RegisterProcessStartTime registers the process_start_time_seconds to 35 // a prometheus registry. This metric needs to be included to ensure counter 36 // data fidelity. 37 func RegisterProcessStartTime(registrationFunc func(Registerable) error) error { 38 start, err := getProcessStart() 39 if err != nil { 40 klog.Errorf("Could not get process start time, %v", err) 41 start = float64(time.Now().Unix()) 42 } 43 // processStartTime is a lazy metric which only get initialized after registered. 44 // so we need to register the metric first and then set the value for it 45 if err = registrationFunc(processStartTime); err != nil { 46 return err 47 } 48 49 processStartTime.WithLabelValues().Set(start) 50 return nil 51 } 52