Skip to content

Latest commit

 

History

History

kubernetes-pod-exec-time

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Kubernetes Pod Execution Time

This example demonstrates metering execution time of Pods running in Kubernetes.

Table of Contents

Prerequisites

Any local (or remote if that's what's available for you) Kubernetes cluster will do.

We will use kind in this example.

Additional tools you are going to need:

Preparations

Create a new Kubernetes cluster using kind:

kind create cluster

Tip

Alternatively, set up your kubectl context to point to an existing cluster.

Deploy the test Pods to the cluster:

kubectl apply -f https://raw.githubusercontent.com/openmeterio/openmeter/main/examples/collectors/kubernetes-pod-exec-time/seed/pod.yaml
Running locally
kubectl apply -f seed/pod.yaml


 Create a meter 
using the button or manually with the following details:

  • Event type: kube-pod-exec-time
  • Aggregation: SUM
  • Value property: $.duration_seconds
  • Group by (optional):
    • pod_namespace: $.pod_namespace
    • pod_name: $.pod_name
Configuration for self-hosted OpenMeter
# ...

meters:
  - slug: pod_execution_time
    eventType: kube-pod-exec-time
    aggregation: SUM
    valueProperty: $.duration_seconds
    groupBy:
      pod_namespace: $.pod_namespace
      pod_name: $.pod_name

Tip

Read more about creating a meters in the documentation.

Deploy the example

Deploy Benthos to your cluster:

helm install --devel --namespace benthos-collector --create-namespace --set preset=kubernetes-pod-exec-time --set openmeter.url=<OPENMETER_URL> --set openmeter.token=<OPENMETER_TOKEN> benthos-collector oci://ghcr.io/openmeterio/helm-charts/benthos-collector
Running locally
helm install --devel --namespace benthos-collector --create-namespace --set preset=kubernetes-pod-exec-time --set openmeter.url=$OPENMETER_URL --set openmeter.token=$OPENMETER_TOKEN benthos-collector ../../../deploy/charts/benthos-collector

Note

If you use OpenMeter Cloud, you can omit the openmeter.url parameter.

Checking events

Read more in the collector examples README.

Cleanup

Uninstall Benthos from the cluster:

helm delete --namespace benthos-collector benthos-collector

Remove the sample Pods from the cluster:

kubectl delete -f https://raw.githubusercontent.com/openmeterio/openmeter/main/examples/collectors/kubernetes-pod-exec-time/seed/pod.yaml
Running locally
kubectl delete -f seed/pod.yaml

Delete the cluster:

kind delete cluster

Advanced configuration

This example uses a custom Benthos plugin called kubernetes_resources (included in this project) to periodically scrape the Kubernetes API for active pods.

The entire pipeline can be found in this file.

Check out the configuration file and the Benthos documentation for more details.

Production use

We are actively working on improving the documentation and the examples. In the meantime, feel free to contact us in email or on Discord.

We are more than happy to help you set up OpenMeter in your production environment.