Skip to content

Commit a4d64fb

Browse files
committed
docs(customresourestate): add example to expose same metrics with different label
Signed-off-by: clavinjune <[email protected]>
1 parent d3f0c18 commit a4d64fb

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

docs/metrics/extend/customresourcestate-metrics.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,73 @@ kube_customresource_ref_info{customresource_group="myteam.io", customresource_ki
254254
kube_customresource_ref_info{customresource_group="myteam.io", customresource_kind="Foo", customresource_version="v1", name="foo",ref="foo_with_extensions"} 1
255255
```
256256

257+
#### Same Metrics with Different Labels
258+
259+
```yaml
260+
recommendation:
261+
containerRecommendations:
262+
- containerName: consumer
263+
lowerBound:
264+
cpu: 100m
265+
memory: 262144k
266+
```
267+
268+
For example in VPA we have above attributes and we want to have a same metrics for both CPU and Memory, you can use below config:
269+
270+
```
271+
kind: CustomResourceStateMetrics
272+
spec:
273+
resources:
274+
- groupVersionKind:
275+
group: autoscaling.k8s.io
276+
kind: "VerticalPodAutoscaler"
277+
version: "v1"
278+
labelsFromPath:
279+
verticalpodautoscaler: [metadata, name]
280+
namespace: [metadata, namespace]
281+
target_api_version: [apiVersion]
282+
target_kind: [spec, targetRef, kind]
283+
target_name: [spec, targetRef, name]
284+
metrics:
285+
# for memory
286+
- name: "verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound"
287+
help: "Minimum memory resources the container can use before the VerticalPodAutoscaler updater evicts it."
288+
commonLabels:
289+
unit: "byte"
290+
resource: "memory"
291+
each:
292+
type: Gauge
293+
gauge:
294+
path: [status, recommendation, containerRecommendations]
295+
labelsFromPath:
296+
container: [containerName]
297+
valueFrom: [lowerBound, memory]
298+
# for CPU
299+
- name: "verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound"
300+
help: "Minimum cpu resources the container can use before the VerticalPodAutoscaler updater evicts it."
301+
commonLabels:
302+
unit: "core"
303+
resource: "cpu"
304+
each:
305+
type: Gauge
306+
gauge:
307+
path: [status, recommendation, containerRecommendations]
308+
labelsFromPath:
309+
container: [containerName]
310+
valueFrom: [lowerBound, cpu]
311+
```
312+
313+
Produces the following metrics:
314+
315+
```prometheus
316+
# HELP kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound Minimum memory resources the container can use before the VerticalPodAutoscaler updater evicts it.
317+
# TYPE kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound gauge
318+
kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound{container="consumer",customresource_group="autoscaling.k8s.io",customresource_kind="VerticalPodAutoscaler",customresource_version="v1",namespace="namespace-example",resource="memory",target_api_version="apps/v1",target_kind="Deployment",target_name="target-name-example",unit="byte",verticalpodautoscaler="vpa-example"} 123456
319+
# HELP kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound Minimum cpu resources the container can use before the VerticalPodAutoscaler updater evicts it.
320+
# TYPE kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound gauge
321+
kube_customresource_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound{container="consumer",customresource_group="autoscaling.k8s.io",customresource_kind="VerticalPodAutoscaler",customresource_version="v1",namespace="namespace-example",resource="cpu",target_api_version="apps/v1",target_kind="Deployment",target_name="target-name-example",unit="core",verticalpodautoscaler="vpa-example"} 0.1
322+
```
323+
257324
#### VerticalPodAutoscaler
258325

259326
In v2.9.0 the `vericalpodautoscalers` resource was removed from the list of default resources. In order to generate metrics for `verticalpodautoscalers`, you can use the following Custom Resource State config:

0 commit comments

Comments
 (0)