Skip to content

Commit

Permalink
Update readme with example of pod and json
Browse files Browse the repository at this point in the history
  • Loading branch information
Elijah Wilson committed Oct 3, 2023
1 parent a0dcc55 commit 61f6537
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,61 @@ When running locally, this assumes you have a Kubernetes context already configu
```bash
./openmeter-pod-runtime-watcher
```

## How it works

This application will query for pods in a namespace with the `k8s.openmeter.cloud/monitor` label set.
For each pod found, it will look up each label that starts with `k8s.openmeter.cloud/data-` and use the suffix as the key to send to OpenMeter.
Here's a full example of a pod and the data it will send to OpenMeter:
```yaml
# source: examples/k8s-manifests/pod.yaml
kind: Pod
apiVersion: v1
metadata:
name: openmeter-pod-runtime-watcher-example
labels:
k8s.openmeter.cloud/monitor: kernel_runtime
k8s.openmeter.cloud/subject: eli-test
k8s.openmeter.cloud/data-file_id: 00703462-bb3e-4d99-966e-518fa207fcf8
k8s.openmeter.cloud/data-kernel_session_id: 934f5a4b-8f59-44bd-a69c-2d39bda56aad
k8s.openmeter.cloud/data-project_id: 6f0dff14-67d4-4cdf-bca4-b60019211e1a
k8s.openmeter.cloud/data-space_id: 285698d3-23cc-4816-b891-d554351611d0
k8s.openmeter.cloud/data-hardware_kind: cpu
k8s.openmeter.cloud/data-hardware_size: small
spec:
containers:
- name: busybox
image: busybox
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
```
This will map to the following cloudevents JSON request to OpenMeter:
```json
{
"specversion": "1.0",
"type": "kernel_runtime",
"source": "kubernetes-api",
"id": "9c6d076d-3c8f-456a-9df1-85e247e34151",
"time": "2023-10-03T20:00:00Z",
"datacontenttype": "application/json",
"data": {
"file_id": "00703462-bb3e-4d99-966e-518fa207fcf8",
"kernel_session_id": "934f5a4b-8f59-44bd-a69c-2d39bda56aad",
"project_id": "6f0dff14-67d4-4cdf-bca4-b60019211e1a",
"space_id": "285698d3-23cc-4816-b891-d554351611d0",
"hardware_kind": "cpu",
"hardware_size": "small",
"subject": "eli-test",
"duration": "5"
}
}
```
The rate at which events are sent for pods is configurable using the `MONITOR_RATE_SECONDS` environment variable.
Or, the `settings.monitor_rate_seconds` helm chart value.
The source can also be configured using the `SOURCE` environment variable or the `settings.source` helm chart value.
By default, we send events to the https://openmeter.cloud API, but if you self-host, this can be configured using the `OPENMETER_URL` environment variable or the `settings.openmeter_url` helm chart value.

0 comments on commit 61f6537

Please sign in to comment.