--- myst: html_meta: "description": "Create a Prometheus ServiceMonitor for the Plone backend, frontend, or Varnish cache to expose metrics." "property=og:description": "Create a Prometheus ServiceMonitor for the Plone backend, frontend, or Varnish cache to expose metrics." "property=og:title": "Enable Prometheus monitoring" "keywords": "Plone, cdk8s, Kubernetes, Prometheus, ServiceMonitor, monitoring, metrics" --- ```{image} ../_static/kup6s-icon-howto.svg :align: center :class: section-icon-large ``` # 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](https://github.com/prometheus-operator/prometheus-operator) installed in the cluster (it provides the `ServiceMonitor` CRD). - A `Prometheus` resource that selects the `ServiceMonitor` resources you create (check `serviceMonitorSelector` and `serviceMonitorNamespaceSelector`). - 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 ```typescript 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`](https://www.npmjs.com/package/express-prometheus-middleware). Point `cdk8s-plone` at that port: ```typescript 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. ```typescript 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: ```typescript import { PloneVinylCache } from '@bluedynamics/cdk8s-plone'; new PloneVinylCache(chart, 'cache', { plone: ploneInstance, monitoring: true, }); ``` ## Verify the rollout ```shell # 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