https://github.com/joshnuss/vertex
Store multi-tenant metrics in ClickHouse
https://github.com/joshnuss/vertex
clickhouse elixir metrics
Last synced: about 1 year ago
JSON representation
Store multi-tenant metrics in ClickHouse
- Host: GitHub
- URL: https://github.com/joshnuss/vertex
- Owner: joshnuss
- Created: 2022-08-07T05:06:24.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-26T04:59:32.000Z (almost 4 years ago)
- Last Synced: 2025-04-11T21:52:41.507Z (about 1 year ago)
- Topics: clickhouse, elixir, metrics
- Language: Elixir
- Homepage:
- Size: 75.2 KB
- Stars: 14
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Vertex
A server for storing multi-tenant metrics in [ClickHouse](https://clickhouse.com/).
## Motivation
Unlike StatsD, events are scoped by tenant. That makes it possible to have alerts and reporting on the tenant level.
For example, if you'd like to when accounts haven't logged in over for 2 weeks. The app could publish an event `login.success` and attach their `account_id` as the `tenant`. Then reporting and alerts could be triggered when `login.success` event is missing over a window of 2 weeks.
This approach is also more economical than DataDog or similar logging systems. It doesn't require expensive hosting, and the same infrastructure can support multiple projects for no additional cost.
## Usage
### Sending a single metric
```bash
curl http://localhost:4000/event \
--header "authorization: Bearer " \
--header "content-type: application/json" \
--data '{ "tenant": "1234", "event": "order.success", "tags": ["enterprise-plan", "sandbox"] }'
```
### Sending a batch of metrics
```bash
curl http://localhost:4000/events \
--header "authorization: Bearer " \
--header "content-type: application/json" \
--data '[{"tenant": "1234", "event": "account.login"}, {"tenant": "1234", "event": "order.success"}]'
```
## Deployment
Create the database using [`setup.sql`](/priv/setup.sql):
```bash
cat priv/setup.sql | clickhouse-client --host --database= --user=default --password=
```
Set up the environment variables:
- `CLICKHOUSE_URL`: URL of the ClickHouse cluster. Including the port (usually `:8123`).
- `CLICKHOUSE_DATABASE`: Name of the ClickHouse database.
- `CLICKHOUSE_USER`: Name of ClickHouse user.
- `CLICKHOUSE_PASSWORD`: Password for ClickHouse user.
For each project that can access the server, create a record in `projects.json`.
```json
{
"my-project": "my-access-token",
"my-other-project": "my-other-access-token"
}
```
The key is the name of the project, and the value is the access token.
## Future ideas
- Support triggers: send an email when something happens
- Support expectations: send an email when something doesn't happen
## License
MIT