- Docker (with Compose)
- curl
- jq
Clone the repository:
git clone [email protected]:openmeterio/openmeter.git
cd openmeter/quickstart
Launch OpenMeter and its dependencies via:
docker-compose up
Ingest usage events in CloudEvents format:
curl -X POST http://localhost:8888/api/v1alpha1/events \
-H "Expect:" \
-H 'Content-Type: application/cloudevents+json' \
--data-raw '
{
"specversion" : "1.0",
"type": "api-calls",
"id": "00001",
"time": "2023-01-01T00:00:00.001Z",
"source": "service-0",
"subject": "customer-1",
"data": {
"duration_ms": "1",
"method": "GET",
"path": "/hello"
}
}
'
Note how ID is different:
curl -X POST http://localhost:8888/api/v1alpha1/events \
-H "Expect:" \
-H 'Content-Type: application/cloudevents+json' \
--data-raw '
{
"specversion" : "1.0",
"type": "api-calls",
"id": "00002",
"time": "2023-01-01T00:00:00.001Z",
"source": "service-0",
"subject": "customer-1",
"data": {
"duration_ms": "1",
"method": "GET",
"path": "/hello"
}
}
'
Note how ID and time are different:
curl -X POST http://localhost:8888/api/v1alpha1/events \
-H "Expect:" \
-H 'Content-Type: application/cloudevents+json' \
--data-raw '
{
"specversion" : "1.0",
"type": "api-calls",
"id": "00003",
"time": "2023-01-02T00:00:00.001Z",
"source": "service-0",
"subject": "customer-1",
"data": {
"duration_ms": "1",
"method": "GET",
"path": "/hello"
}
}
'
Query the usage hourly:
curl http://localhost:8888/api/v1alpha1/meters/m1/values?windowSize=HOUR | jq
{
"values": [
{
"subject": "customer-1",
"windowStart": "2023-01-01T00:00:00Z",
"windowEnd": "2023-01-01T01:00:00Z",
"value": 2,
"groupBy": {
"$.method": "GET",
"$.path": "/hello"
}
},
{
"subject": "customer-1",
"windowStart": "2023-01-02T00:00:00Z",
"windowEnd": "2023-01-02T01:00:00Z",
"value": 1,
"groupBy": {
"$.method": "GET",
"$.path": "/hello"
}
}
]
}
Configure how OpenMeter should process your usage events. In this example we will meter the execution duration per API invocation, groupped by method and path. You can think about it how AWS Lambda charges by execution duration on a millisecond level.
# ...
meters:
- id: m1
name: Meter 1
type: api-calls
valueProperty: $.duration_ms
aggregation: SUM
groupBy:
- $.method
- $.path