[Doc] Add example of Custom Metrics via Kube-state-metrics CustomResourceStateMetrics #1159
Description
Describe the problem/challenge you have
The controller it self has a small number of Metrics available. This should be extended for proper Monitoring/Alerting.
I mostly use the APP resource and there a only some total counter, which does not represent the proper state of the app.
One solution would be to add them to the controller library, but that would need some coding and testing.
There is a easy solution to add metrics on CustomResources via the kube-state-metrics CustomResourceStateMetrics project.
The kube-state-metrics is a K8S addons that is widely installed and already used for a lot of standard components like Deployments or Satefullsets.
Describe the solution you'd like
So the easies way would be to provide a predefined CustomResourceStateMetrics file for the controller.
bsp for app.kappctrl.k14s.io:
kind: CustomResourceStateMetrics
spec:
resources:
- groupVersionKind:
group: kappctrl.k14s.io
kind: App
version: v1alpha1
labelsFromPath:
name:
- metadata
- name
namespace:
- metadata
- namespace
metricNamePrefix: kappctrl_app
metrics:
- name: spec_paused
help: Whether the App is paused and any of its resources will not be processed by the controllers.
each:
gauge:
nilIsZero: true
path:
- spec
- paused
type: Gauge
- name: status
help: The app current status.
each:
type: Gauge
gauge:
nilIsZero: true
path: [ status, conditions ]
labelsFromPath:
type: [ "type" ]
valueFrom: [ "status" ]
This will result in two different Metrics per APP.
kappctrl_app_spec_paused{customresource_group="kappctrl.k14s.io",customresource_kind="App",customresource_version="v1alpha1",name="<metadata.name>",namespace="<metadata.namespace>"} 0
0
unpaused 1
paused
kappctrl_app_status{customresource_group="kappctrl.k14s.io",customresource_kind="App",customresource_version="v1alpha1",name="<metadata.name>",namespace="<metadata.namespace>",type="ReconcileSucceeded"} 1
Will add all the valid types from api definition
Or a 0
if no status.condition.type
is set
kappctrl_app_status{customresource_group="kappctrl.k14s.io",customresource_kind="App",customresource_version="v1alpha1",name="<metadata.name>",namespace="<metadata.namespace>"} 0
The spec file can be extended to all possible metrics some one need and all used resources f.e. package, packageRepositoy can be added.
For Adding it to any cluster use the kube-state-metrics documentation
Metadata
Assignees
Labels
Type
Projects
Status
No status