In this example, we'll parse application logs and convert them into OpenMeter events. This method is beneficial when you want to gather usage information from systems where integrating the OpenMeter SDK or sending HTTP requests isn't feasible. Using this powerful approach, you can track usage and bill for low-level infrastructure components like message queues, logs, and more.
Here, we replicate our execution duration example from the OpenMeter quickstart. To collect and transform logs, we'll utilize Vector. In this scenario, we'll tail the logs of a Docker container (named demologs
) and transform these log messages into OpenMeter-compatible CloudEvents. These are then ingested into OpenMeter via HTTP. The process consists of the following steps:
- Vector tails logs from the Docker container.
- Vector filters logs based on our criteria.
- Vector transforms logs into the CloudEvents format.
- Vector sends the CloudEvents to the OpenMeter ingest API.
- OpenMeter tracks usage.
Transformations in Vector uses the Vector Remap Language (VRL). In this example we add, delete and rename object properties with VRL.
- First, start OpenMeter. Refer to the quickstart guide for instructions.
- Execute
docker compose up
within this example directory. - To query meters, use the following command:
curl 'http://localhost:8888/api/v1/meters/api_requests_duration/query?groupBy=subject'
.
Note: It's important that you run quickstart's docker compose
first.