Skip to content

Commit

Permalink
feat(docs): example meters
Browse files Browse the repository at this point in the history
  • Loading branch information
hekike committed Mar 4, 2024
1 parent 7bad5af commit fc0c2c6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ telemetry:

meters:
# Sample meter to count API requests
- slug: api_requests # Unique identifier for the meter
- slug: api_requests_total # Unique identifier for the meter
description: API Requests
eventType: request # Filter events by type
aggregation: COUNT # Aggregation method: COUNT, SUM, etc.
Expand All @@ -28,7 +28,7 @@ meters:
route: $.route # Route: /products/:product_id

# Sample meter to count LLM Token Usage
- slug: tokens
- slug: tokens_total
description: AI Token Usage
eventType: prompt # Filter events by type
aggregation: SUM
Expand Down
2 changes: 1 addition & 1 deletion examples/ingest-logs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Transformations in Vector uses the [Vector Remap Language](https://vector.dev/do

1. First, start OpenMeter. Refer to the [quickstart guide](/quickstart) for instructions.
2. Execute `docker compose up` within this example directory.
3. To query meters, use the following command: `curl http://localhost:8888/api/v1/meters/api_requests/values`.
3. To query meters, use the following command: `curl http://localhost:8888/api/v1/meters/api_requests_total/values`.

Note: It's important that you run quickstart's `docker compose` first.
8 changes: 4 additions & 4 deletions quickstart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ curl -X POST http://localhost:8888/api/v1/events \
Query the usage hourly:

```sh
curl 'http://localhost:8888/api/v1/meters/api_requests/query?windowSize=HOUR&groupBy=method&groupBy=route' | jq
curl 'http://localhost:8888/api/v1/meters/api_requests_total/query?windowSize=HOUR&groupBy=method&groupBy=route' | jq
```

```json
Expand Down Expand Up @@ -125,7 +125,7 @@ curl 'http://localhost:8888/api/v1/meters/api_requests/query?windowSize=HOUR&gro
Query the total usage for `customer-1`:

```sh
curl 'http://localhost:8888/api/v1/meters/api_requests/query?subject=customer-1' | jq
curl 'http://localhost:8888/api/v1/meters/api_requests_total/query?subject=customer-1' | jq
```

```json
Expand All @@ -147,14 +147,14 @@ curl 'http://localhost:8888/api/v1/meters/api_requests/query?subject=customer-1'
In this example we will meter LLM token usage, groupped by AI model and prompt type.
You can think about it how OpenAI [charges](https://openai.com/pricing) by tokens for ChatGPT.

Configure how OpenMeter should process your usage events in this new `tokens` meter.
Configure how OpenMeter should process your usage events in this new `tokens_total` meter.

```yaml
# ...

meters:
# Sample meter to count LLM Token Usage
- slug: tokens
- slug: tokens_total
description: AI Token Usage
eventType: prompt # Filter events by type
aggregation: SUM
Expand Down
4 changes: 2 additions & 2 deletions quickstart/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sink:

meters:
# Sample meter to count API requests
- slug: api_requests # Unique identifier for the meter
- slug: api_requests_total # Unique identifier for the meter
description: API Requests
eventType: request # Filter events by type
aggregation: COUNT # Aggregation method: COUNT, SUM, etc.
Expand All @@ -21,7 +21,7 @@ meters:
route: $.route # Route: /products/:product_id

# Sample meter to count LLM Token Usage
- slug: tokens
- slug: tokens_total
description: AI Token Usage
eventType: prompt # Filter events by type
aggregation: SUM
Expand Down
2 changes: 1 addition & 1 deletion quickstart/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
volumes:
- ./config.yaml:/etc/openmeter/config.yaml
healthcheck:
test: wget --no-verbose --tries=1 --spider http://openmeter:8888/api/v1/meters/api_requests/query || exit 1
test: wget --no-verbose --tries=1 --spider http://openmeter:8888/api/v1/meters/api_requests_total/query || exit 1
interval: 5s
timeout: 3s
retries: 100
Expand Down
2 changes: 1 addition & 1 deletion quickstart/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

temp_file=$(mktemp)

curl http://localhost:8888/api/v1/meters/api_requests/query?windowSize=HOUR >$temp_file
curl http://localhost:8888/api/v1/meters/api_requests_total/query?windowSize=HOUR >$temp_file

[ $(cat $temp_file | jq '.data[0].value') == 2 ] || (echo "Unexpected value" && cat $temp_file && exit 1)
[ $(cat $temp_file | jq '.data[1].value') == 1 ] || (echo "Unexpected value" && cat $temp_file && exit 1)

0 comments on commit fc0c2c6

Please sign in to comment.