synthetic-monitoring-agent

by Grafana

Helm chartv2.0.1App v0.71.0

Grafana Synthetic Monitoring agent, to run private probes on Kubernetes.

About this chart

synthetic-monitoring-agent Helm chart

Deploys the Grafana Synthetic Monitoring agent to run a private probe on Kubernetes. Optionally:

  • Clustering (experimental): several agents share the same probe and split its checks.
  • Browser pool (experimental): browser checks run on a fleet of crocochrome instances, a Chromium supervisor, instead of a Chromium inside the agent. The chart can deploy the fleet.

Install

  1. Add a private probe in Grafana and copy its Probe Authentication Token and the API server URL for your region.

  2. Store the token in a Secret:

    kubectl create namespace synthetic-monitoring
    kubectl create secret generic sm-agent -n synthetic-monitoring --from-literal=api-token=<TOKEN>
    
  3. Install the chart:

    helm install sm-agent oci://ghcr.io/grafana/helm-charts/synthetic-monitoring-agent \
      -n synthetic-monitoring \
      --set probe.apiServerAddress=synthetic-monitoring-grpc-eu-west-3.grafana.net:443 \
      --set probe.existingSecret=sm-agent
    

    The chart is also in the grafana Helm repository:

    helm repo add grafana https://grafana.github.io/helm-charts
    helm install sm-agent grafana/synthetic-monitoring-agent -n synthetic-monitoring ...
    

The probe appears as online on the Synthetics > Probes page once the agent connects.

Versions

The chart version is independent of the agent version. The chart's appVersion is the agent release it was tested with, and the default image tag. To run a different agent release, set image.tag.

Run a cluster

Clustering requires:

  • Agent v0.68.0 or later.
  • Synthetic Monitoring API support for clusters: every agent in the ring must receive the probe's full set of checks.
replicas: 3
cluster:
  enabled: true
  # Keep it below replicas, so agents still start when one Pod is unavailable.
  waitForSize: 2

The chart also creates a PodDisruptionBudget, so that node drains and cluster upgrades evict one agent at a time. Set podDisruptionBudget.enabled: false to turn it off.

The chart sets the join addresses to the release's headless Service, the advertise address to the Pod IP, and the cluster name to the release full name, the prefix of every resource name. Every agent in the release uses the same probe token. replicas above 1 requires cluster.enabled, because without clustering every agent runs every check of the probe.

Upgrades replace clustered agents one at a time. A single agent is stopped before its replacement starts, because the API accepts only one connection per probe from an agent without clustering. The probe is offline while the agent restarts.

[!WARNING] To switch a single agent to a cluster, upgrade with replicas: 0 first, then with the cluster values. A direct helm upgrade never completes: the API rejects the clustered agents while the single agent is connected, so they don't become ready and the single agent is never stopped. The probe is offline between the two upgrades.

Cluster security

Cluster traffic is plaintext HTTP/2, and agents don't authenticate each other: cluster.name only prevents accidental merges. To restrict cluster traffic, you can enable the chart's NetworkPolicy (networkPolicy.enabled, off by default). It only allows cluster traffic from the agents of this release, and needs a CNI that enforces NetworkPolicies.

The same policy allows listenPort, which serves /metrics and the debug endpoints, from any source. To limit it to your Prometheus, set networkPolicy.extraIngressFrom.

Autoscale the cluster

The chart can add a HorizontalPodAutoscaler for the agents. It requires cluster.enabled, and it's off by default:

cluster:
  enabled: true
  # Keep it below autoscaling.minReplicas, so agents still start when one Pod is unavailable.
  waitForSize: 2
autoscaling:
  enabled: true
  minReplicas: 3
  maxReplicas: 5
  targetCPUUtilizationPercentage: 70
  targetMemoryUtilizationPercentage: 70

The HPA owns the number of agents, so the chart ignores replicas. It scales on whichever target needs more agents. Set a target to null to remove it.

Agent load comes from the probe's checks, not from traffic, so an autoscaler mostly helps probes whose number of checks grows over time. Keep in mind:

  • Every scale event moves checks. When agents join or leave, the cluster moves some checks to other agents, which run them again straight away. The chart scales down slowly by default: after 10 minutes of lower usage, and one agent every 5 minutes at most. Set autoscaling.behavior to change it.
  • Size the minimum for peak load. Checks with long frequencies run in bursts that are over before the HPA reacts.
  • Targets are a percentage of requests, not limits. Set resources.requests to what an agent really uses, or the targets don't mean much.

Browser checks and autoscaling

Without a browser pool, every browser check starts a Chromium inside the agent that owns it. Chromium uses far more CPU and memory than any other check type, so browser checks dominate an agent's resource use and make it hard to autoscale well:

  • Uneven load. The cluster balances the number of checks across agents, not their cost. An agent that owns several browser checks can use much more CPU and memory than the others.
  • Out-of-memory kills the HPA doesn't prevent. The HPA scales on the average across agents. A busy agent can reach its memory limit and be killed while the average stays below the target. When it restarts, its checks move to other agents and run again.
  • Spiky metrics. Chromium only runs for the length of a check, so CPU and memory jump during browser checks and drop right after. The HPA can scale up after a burst has ended, and the slow scale-down keeps the extra agents for a while.
  • Larger requests and limits. Every agent has to be sized for the browser checks it might own. All agents cost more, and targets measured against those requests mean less.

If the probe runs more than a few browser checks, use the browser pool. Chromium then runs on crocochrome, and the agents only run the browser check scripts. Agent load becomes even and predictable, the HPA's CPU and memory targets reflect the checks the agents run, and agents can use smaller requests and limits and the standard image. The crocochrome fleet scales separately; refer to Autoscale the fleet.

If you run only a few browser checks without the pool, size the memory limit for the heaviest agent, not the average, and expect some scale events around bursts of browser checks.

Use a browser pool

crocochrome is a Chromium supervisor. For each browser session an agent requests, it starts a Chromium browser, and it stops the browser and removes its data when the session ends. Each instance runs one session at a time.

The browser pool requires agent v0.69.0 or later and crocochrome v0.14.0 or later.

browserPool:
  enabled: true
  crocochrome:
    # One browser session per instance. Run at least as many as the peak number of concurrent browser checks.
    replicas: 3

The chart deploys crocochrome as a Deployment with a headless Service, and points the agents to it. The agents can use the standard image (image.variant: standard).

The default instances can all be scheduled on the same node. To spread them across nodes:

browserPool:
  crocochrome:
    topologySpreadConstraints:
      - maxSkew: 1
        topologyKey: kubernetes.io/hostname
        whenUnsatisfiable: ScheduleAnyway
        labelSelector:
          matchLabels:
            app.kubernetes.io/name: synthetic-monitoring-agent
            app.kubernetes.io/instance: <release name>
            app.kubernetes.io/component: crocochrome

Security

crocochrome has two images, and browserPool.crocochrome.unprivileged chooses between them. The chart sets the image and the security context it requires:

Hardened (default)Unprivileged (browserPool.crocochrome.unprivileged: true)
Image tag<tag><tag>-unprivileged
Chromium runs asA separate user (nobody)The same user as crocochrome
Security contextUser 6666, allowPrivilegeEscalation: true, and the SETUID, SETGID, KILL, CHOWN, DAC_OVERRIDE, and FOWNER capabilitiesThe image's non-root user (6666), or the UID the platform assigns, allowPrivilegeEscalation: false, no capabilities
Pod Security profilebaselinerestricted

The hardened image keeps Chromium apart from crocochrome through the user boundary. In the unprivileged image, a compromised Chromium, for example through a malicious page, can kill or trace crocochrome, which restarts the container, and leave files in /chromium-tmp for later sessions on the same instance. Use the unprivileged image only when you trust both the check scripts and the content of the pages they load, including third-party scripts. Otherwise, keep the hardened image. Refer to the crocochrome documentation.

browserPool:
  crocochrome:
    unprivileged: true

The chart doesn't set a user for the unprivileged image, so it also runs with the UID that platforms such as the OpenShift restricted-v2 SecurityContextConstraints assign.

The crocochrome API doesn't have authentication: anything that can reach it can start browser sessions in your network. To only allow the agents to reach it, enable the chart's crocochrome NetworkPolicy (browserPool.crocochrome.networkPolicy.enabled, off by default). It needs a CNI that enforces NetworkPolicies.

The policy also blocks scrapers, whether they use the ServiceMonitor or discover the Pods on their own. To scrape crocochrome metrics, which use the same port, add your scraper's Pods to browserPool.crocochrome.networkPolicy.extraIngressFrom, for example:

browserPool:
  crocochrome:
    networkPolicy:
      enabled: true
      extraIngressFrom:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: monitoring

crocochrome runs with its own ServiceAccount (browserPool.crocochrome.serviceAccount), without a token, so that identities given to the agent's ServiceAccount don't reach the browsers.

Autoscale the fleet

The chart doesn't include an autoscaler for crocochrome. avg(sm_crocochrome_session_active) is the share of the fleet in use, and you can autoscale on it with your own HorizontalPodAutoscaler or with KEDA. Set browserPool.crocochrome.replicas: null, so that helm upgrade doesn't reset the number of instances the autoscaler chose, and add the autoscaler with extraObjects. For example, with KEDA:

browserPool:
  crocochrome:
    replicas: null
extraObjects:
  - apiVersion: keda.sh/v1alpha1
    kind: ScaledObject
    metadata:
      name: '{{ include "sm-agent.crocochromeName" . }}'
    spec:
      scaleTargetRef:
        name: '{{ include "sm-agent.crocochromeName" . }}'
      minReplicaCount: 3
      maxReplicaCount: 20
      triggers:
        - type: prometheus
          metadata:
            serverAddress: http://prometheus.monitoring.svc:9090
            query: avg(sm_crocochrome_session_active{namespace="{{ .Release.Namespace }}"})
            threshold: "0.7"

Size the minimum for bursts: browser checks with long frequencies tend to start at the same time, and autoscalers react slowly.

Security contexts

The chart sets the security contexts that the agent and crocochrome images require, so they aren't values:

  • Agent: runs as user 12345 with a read-only root filesystem, no privilege escalation, and only the NET_RAW capability, which ping and traceroute checks need. baseline doesn't allow NET_RAW, so it needs the Pod Security privileged profile. The seccompProfile defaults to RuntimeDefault, and the Pod fsGroup to 12345.
  • crocochrome: depends on the image, refer to Security. The seccompProfile defaults to RuntimeDefault.

To add fields, such as seLinuxOptions or a different seccompProfile, use extraPodSecurityContext and extraSecurityContext, or browserPool.crocochrome.extraPodSecurityContext and browserPool.crocochrome.extraSecurityContext. They can't change the fields the images require: the user, the root filesystem, privilege escalation, and capabilities. The unprivileged crocochrome image doesn't require a user, so browserPool.crocochrome.extraSecurityContext can set one.

Feature flags

features accepts the agent's optional feature flags. The chart passes them as they are: the agent ignores unknown names without a warning. k6 and traceroute are always enabled.

Values

Values set to null use the agent's own default, and the chart doesn't pass the flag. Most descriptions name the agent flag a value sets.

KeyTypeDefaultDescription
affinityobject{}Agent affinity.
autoscalingobject`{"behavior":{},"enabled":false,"maxReplicas":5,"min

Deploy synthetic-monitoring-agent with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has synthetic-monitoring-agent on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartsynthetic-monitoring-agent is pinned at v2.0.1 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply