K6 to Grafana

First we need to get K6 remote write its metrics to Prometheus (or influxdb). I chose Prometheus (because why not?)

 

If we have a Prometheus Instance already running(via Operator), we can simply edit the Prometheus CRD

spec:
  enableRemoteWriteReceiver: true

 

After that we can see the updated Statefulset of Prometheus arguments

- --web.enable-remote-write-receiver

 

 

Or we can just deploy another prometheus in the desired namespace with the above option enabled.

 

I chose to deploy k6 as Kubernetes Deployment with the ‘linger’ option turned on.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: k6-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: k6
  template:
    metadata:
      labels:
        app: k6
    spec:
      containers:
      - name: k6
        image: ghcr.io/grafana/k6:latest
        command: ["k6", "run", "-l", "-o", "experimental-prometheus-rw", "/scripts/scripts.js"]
        env:
        - name: K6_PROMETHEUS_RW_SERVER_URL
          value: "http://prometheus-operated:9090/api/v1/write"
        volumeMounts:
        - name: script-cm
          mountPath: /scripts
      volumes:
      - name: script-cm
        configMap:
          name: k6-script-config

 

Now we will be mounting the scripts.js file as configmap.

 

## The configmap format ##
apiVersion: v1
data:
  scripts.js: "<The script data>"
kind: ConfigMap
metadata:
  name: k6-script-config

We can create the above format by using the kubectl create configmap --from-file= command

 

After this we should be able to see the k6 related metrics under k6_ metrics format in Prometheus UI.

← back