Debian Codegraph @

pkg/server/routes/metrics.go

raw
1 /*
2 Copyright 2014 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 routes
18
19 import (
20 handlersmetrics "k8s.io/apiserver/pkg/endpoints/handlers/metrics"
21 apimetrics "k8s.io/apiserver/pkg/endpoints/metrics"
22 "k8s.io/apiserver/pkg/server/mux"
23 cachermetrics "k8s.io/apiserver/pkg/storage/cacher/metrics"
24 etcd3metrics "k8s.io/apiserver/pkg/storage/etcd3/metrics"
25 flowcontrolmetrics "k8s.io/apiserver/pkg/util/flowcontrol/metrics"
26 peerproxymetrics "k8s.io/apiserver/pkg/util/peerproxy/metrics"
27 "k8s.io/component-base/metrics/legacyregistry"
28 )
29
30 // DefaultMetrics installs the default prometheus metrics handler
31 type DefaultMetrics struct{}
32
33 // Install adds the DefaultMetrics handler
34 func (m DefaultMetrics) Install(c *mux.PathRecorderMux) {
35 register()
36 c.Handle("/metrics", legacyregistry.Handler())
37 }
38
39 // MetricsWithReset install the prometheus metrics handler extended with support for the DELETE method
40 // which resets the metrics.
41 type MetricsWithReset struct{}
42
43 // Install adds the MetricsWithReset handler
44 func (m MetricsWithReset) Install(c *mux.PathRecorderMux) {
45 register()
46 c.Handle("/metrics", legacyregistry.HandlerWithReset())
47 }
48
49 // register apiserver and etcd metrics
50 func register() {
51 apimetrics.Register()
52 cachermetrics.Register()
53 etcd3metrics.Register()
54 flowcontrolmetrics.Register()
55 peerproxymetrics.Register()
56 handlersmetrics.Register()
57 }