-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose proxmox api calls metrics. Signed-off-by: Serge Logvinov <serge.logvinov@sinextra.dev>
- Loading branch information
1 parent
e31b24c
commit b81ad14
Showing
11 changed files
with
216 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Metrics documentation | ||
|
||
This document is a reflection of the current state of the exposed metrics of the Proxmox CCM. | ||
|
||
## Gather metrics | ||
|
||
By default, the Proxmox CCM exposes metrics on the `https://localhost:10258/metrics` endpoint. | ||
|
||
```yaml | ||
proxmox-cloud-controller-manager --authorization-always-allow-paths="/metrics" --secure-port=10258 | ||
``` | ||
|
||
### Helm chart values | ||
|
||
The following values can be set in the Helm chart to expose the metrics of the Talos CCM. | ||
|
||
```yaml | ||
podAnnotations: | ||
prometheus.io/scrape: "true" | ||
prometheus.io/scheme: "https" | ||
prometheus.io/port: "10258" | ||
``` | ||
## Metrics exposed by the CCM | ||
### Proxmox API calls | ||
|Metric name|Metric type|Labels/tags| | ||
|-----------|-----------|-----------| | ||
|proxmox_api_request_duration_seconds|Histogram|`request`=<api_request>| | ||
|proxmox_api_request_errors_total|Counter|`request`=<api_request>| | ||
|
||
Example output: | ||
|
||
```txt | ||
proxmox_api_request_duration_seconds_bucket{request="getVmInfo",le="0.1"} 13 | ||
proxmox_api_request_duration_seconds_bucket{request="getVmInfo",le="0.25"} 172 | ||
proxmox_api_request_duration_seconds_bucket{request="getVmInfo",le="0.5"} 199 | ||
proxmox_api_request_duration_seconds_bucket{request="getVmInfo",le="1"} 210 | ||
proxmox_api_request_duration_seconds_bucket{request="getVmInfo",le="2.5"} 210 | ||
proxmox_api_request_duration_seconds_bucket{request="getVmInfo",le="5"} 210 | ||
proxmox_api_request_duration_seconds_bucket{request="getVmInfo",le="10"} 210 | ||
proxmox_api_request_duration_seconds_bucket{request="getVmInfo",le="30"} 210 | ||
proxmox_api_request_duration_seconds_bucket{request="getVmInfo",le="+Inf"} 210 | ||
proxmox_api_request_duration_seconds_sum{request="getVmInfo"} 39.698945394000006 | ||
proxmox_api_request_duration_seconds_count{request="getVmInfo"} 210 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package metrics collects metrics. | ||
package metrics | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// MetricContext indicates the context for Talos client metrics. | ||
type MetricContext struct { | ||
start time.Time | ||
attributes []string | ||
} | ||
|
||
// NewMetricContext creates a new MetricContext. | ||
func NewMetricContext(resource string) *MetricContext { | ||
return &MetricContext{ | ||
start: time.Now(), | ||
attributes: []string{resource}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package metrics | ||
|
||
import ( | ||
"time" | ||
|
||
"k8s.io/component-base/metrics" | ||
"k8s.io/component-base/metrics/legacyregistry" | ||
) | ||
|
||
// CSIMetrics contains the metrics for Talos API calls. | ||
type CSIMetrics struct { | ||
Duration *metrics.HistogramVec | ||
Errors *metrics.CounterVec | ||
} | ||
|
||
var apiMetrics = registerAPIMetrics() | ||
|
||
// ObserveRequest records the request latency and counts the errors. | ||
func (mc *MetricContext) ObserveRequest(err error) error { | ||
apiMetrics.Duration.WithLabelValues(mc.attributes...).Observe( | ||
time.Since(mc.start).Seconds()) | ||
|
||
if err != nil { | ||
apiMetrics.Errors.WithLabelValues(mc.attributes...).Inc() | ||
} | ||
|
||
return err | ||
} | ||
|
||
func registerAPIMetrics() *CSIMetrics { | ||
metrics := &CSIMetrics{ | ||
Duration: metrics.NewHistogramVec( | ||
&metrics.HistogramOpts{ | ||
Name: "proxmox_api_request_duration_seconds", | ||
Help: "Latency of an Proxmox API call", | ||
Buckets: []float64{.1, .25, .5, 1, 2.5, 5, 10, 30}, | ||
}, []string{"request"}), | ||
Errors: metrics.NewCounterVec( | ||
&metrics.CounterOpts{ | ||
Name: "proxmox_api_request_errors_total", | ||
Help: "Total number of errors for an Proxmox API call", | ||
}, []string{"request"}), | ||
} | ||
|
||
legacyregistry.MustRegister( | ||
metrics.Duration, | ||
metrics.Errors, | ||
) | ||
|
||
return metrics | ||
} |
Oops, something went wrong.