Enable Prometheus monitoring¶
This guide shows you how to expose Plone metrics to Prometheus by creating a ServiceMonitor for the backend, the frontend, or the Varnish cache.
Prerequisites¶
The Prometheus Operator installed in the cluster (it provides the
ServiceMonitorCRD).A
Prometheusresource that selects theServiceMonitorresources you create (checkserviceMonitorSelectorandserviceMonitorNamespaceSelector).A Plone container instrumented to expose metrics over HTTP. Plone itself does not ship a Prometheus endpoint; you need an add-on (such as a WSGI middleware) or a sidecar exporter.
Enable the ServiceMonitor on the backend¶
import { Plone, PloneVariant } from '@bluedynamics/cdk8s-plone';
new Plone(chart, 'plone', {
variant: PloneVariant.VOLTO,
backend: {
image: 'plone/plone-backend:6.1.3',
servicemonitor: true,
metricsPath: '/metrics',
},
frontend: {
image: 'plone/plone-frontend:16.0.0',
},
});
servicemonitor: true instructs cdk8s-plone to emit a ServiceMonitor that scrapes the backend Service on its main port at /metrics.
Scrape the frontend on a dedicated port¶
Volto can expose metrics on a separate port through middleware such as express-prometheus-middleware.
Point cdk8s-plone at that port:
frontend: {
image: 'plone/plone-frontend:16.0.0',
servicemonitor: true,
metricsPort: 9090,
metricsPath: '/metrics',
}
metricsPort accepts a port number or a Service port name.
Scrape the Varnish cache¶
PloneHttpcache and PloneVinylCache each accept their own monitoring switch.
import { PloneHttpcache } from '@bluedynamics/cdk8s-plone';
new PloneHttpcache(chart, 'cache', {
plone: ploneInstance,
servicemonitor: true,
exporterEnabled: true,
});
exporterEnabled (default true) deploys the Varnish exporter sidecar that the ServiceMonitor scrapes.
For the cloud-vinyl operator:
import { PloneVinylCache } from '@bluedynamics/cdk8s-plone';
new PloneVinylCache(chart, 'cache', {
plone: ploneInstance,
monitoring: true,
});
Verify the rollout¶
# Generate manifests and confirm the ServiceMonitor exists
cdk8s synth
grep -l 'kind: ServiceMonitor' dist/*.yaml
# Apply and inspect on the cluster
kubectl apply -f dist/
kubectl get servicemonitor -n <namespace>
kubectl describe servicemonitor <name> -n <namespace>
If Prometheus is not picking up the new target, confirm:
The
ServiceMonitornamespace matches thePrometheusresource’sserviceMonitorNamespaceSelector.The
ServiceMonitorlabels match thePrometheusresource’sserviceMonitorSelector.The metrics endpoint returns HTTP 200 from a pod in the cluster:
kubectl run -it --rm curl --image=curlimages/curl --restart=Never -- \ curl -sf http://<service>.<namespace>:<port>/metrics | head
See also¶
Configuration options — Reference for
servicemonitor,metricsPort,metricsPath.Prometheus Operator documentation —
ServiceMonitorselectors and lifecycle.