Skip to content

Commit

Permalink
feat: alloy and greptimecloud in demo (#51)
Browse files Browse the repository at this point in the history
* feat: alloy and greptimecloud in demo

* refactor:  remove obsolete prometheus file

* chore: add screenshots

* chore: screenshots

* chore: style update

* chore: update readme

* feat: add grafana provisioning

* docs: update readme
  • Loading branch information
sunng87 authored Oct 7, 2024
1 parent 6924b59 commit cfee3e0
Show file tree
Hide file tree
Showing 13 changed files with 24,102 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Scripts and samples to support Greptime Demos and Talks. Might be rough around t
* [Kafka + Vector + GreptimeDB + Web UI](kafka-ingestion)
* [Flight data ingestion and visualization](flight-data-ingester), including
geospatial index with H3
* [Grafana Alloy + GreptimeDB](grafana-alloy)

### Data Migrations

Expand Down
4 changes: 4 additions & 0 deletions grafana-alloy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/prometheus-data
/prometheus.yml
greptime.env
greptime.env.bak
106 changes: 106 additions & 0 deletions grafana-alloy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Grafana Alloy with GreptimeDB

This docker-compose file demos how to ingest data from Grafana Alloy to
GreptimeDB.

It uses [Grafana Alloy](https://grafana.com/docs/alloy) as a Prometheus data
source (combination of Prometheus Node Exporter and Prometheus Agent), and use
remote write protocol to ingest data into GreptimeDB.

## How to run this demo

Ensure you have `git`, `docker`, `docker-compose` and `mysql` client
installed. To run this demo:

```shell
git clone https://github.com/GreptimeTeam/demo-scene.git
cd demo-scene/grafana-alloy
docker compose up
```

You can access GreptimeDB using `mysql` client. Just run `mysql -h 127.0.0.1 -P
4002` to connect to the database and use SQL query like `SHOW TABLES` as a
start.

```
mysql -h 127.0.0.1 -P 4002
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.2 Greptime
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show tables;
+---------------------------------------------+
| Tables |
+---------------------------------------------+
| greptime_physical_table |
| node_boot_time_seconds |
| node_context_switches_total |
| node_cooling_device_cur_state |
| node_cooling_device_max_state |
| node_cpu_frequency_hertz |
| node_cpu_frequency_max_hertz |
| node_cpu_frequency_min_hertz |
| node_cpu_scaling_frequency_hertz |
| node_cpu_scaling_frequency_max_hertz |
| node_cpu_scaling_frequency_min_hertz |
| node_cpu_scaling_governor |
| node_cpu_seconds_total |
| node_disk_discard_time_seconds_total |
| node_disk_discarded_sectors_total |
| node_disk_discards_completed_total |
| node_disk_discards_merged_total |
| ... |
```

## How it works

The topology is illustrated in this diagram.

```mermaid
flowchart LR
greptimedb[(GreptimeDB)]
alloy[Alloy]
grafana[Grafana]
alloy --> greptimedb
greptimedb --> grafana
```

## Run in GreptimeCloud

By default, this example writes data into a GreptimeDB instance within the
docker compose. It's also possible to write to your own GreptimeCloud instance
by creating a `greptime.env` file from our sample `greptime.env.sample` and
providing your host, dbname and authentication information. Then use `docker
compose down` and `docker compose up` to recreate the compose cluster and apply
new settings.

## Screenshots

GreptimeCloud Visualization

![greptimecloud](media/greptimecloud.png)

Grafana Dashboard

![grafana dashboard](media/grafana-dashboard.png)

Grafana Alloy Topology Graph

![alloy graph](media/alloy-graph.png)

Grafana Alloy Component Detail

![alloy component detail](media/alloy-sink-detail.png)

## What's Next

- Use Grafana Alloy for Log ingestion into GreptimeDB
28 changes: 28 additions & 0 deletions grafana-alloy/config.alloy.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
prometheus.exporter.unix "local_system" { }

prometheus.scrape "scrape_metrics" {
targets = prometheus.exporter.unix.local_system.targets
forward_to = [prometheus.relabel.filter_metrics.receiver]
scrape_interval = "15s"
}

prometheus.relabel "filter_metrics" {
rule {
action = "drop"
source_labels = ["env"]
regex = "dev"
}

forward_to = [prometheus.remote_write.metrics_service.receiver]
}

prometheus.remote_write "metrics_service" {
endpoint {
url = "${GREPTIME_SCHEME:=http}://${GREPTIME_HOST:=greptimedb}:${GREPTIME_PORT:=4000}/v1/prometheus/write?db=${GREPTIME_DB:=public}"
basic_auth {
username = "${GREPTIME_USERNAME}"
password = "${GREPTIME_PASSWORD}"
}
}
}
55 changes: 55 additions & 0 deletions grafana-alloy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
services:
envsubst:
image: docker.io/widerplan/envsubst
command: "-i /config_input/config.alloy.tpl -o /config_output/config.alloy"
volumes:
- ./config.alloy.tpl:/config_input/config.alloy.tpl
- config:/config_output
env_file:
- path: "greptime.env"
required: false
init: true

greptimedb:
image: docker.io/greptime/greptimedb:v0.9.3
command: standalone start --http-addr=0.0.0.0:4000 --rpc-addr=0.0.0.0:4001 --mysql-addr=0.0.0.0:4002 --postgres-addr 0.0.0.0:4003
ports:
- 4000:4000
- 4001:4001
- 4002:4002
- 4003:4003
networks:
- demo-network
healthcheck:
test: [ "CMD", "curl", "-f", "http://127.0.0.1:4000/health" ]
interval: 3s
timeout: 3s
retries: 5

grafana:
image: docker.io/grafana/grafana:11.1.0
ports:
- 3000:3000
networks:
- demo-network
volumes:
- ./grafana_provisioning:/etc/grafana/provisioning

alloy:
image: docker.io/grafana/alloy:v1.4.1
command: run --server.http.listen-addr=0.0.0.0:12345 /etc/alloy/config.alloy
ports:
- 12345:12345
networks:
- demo-network
volumes:
- config:/etc/alloy
depends_on:
envsubst:
condition: service_completed_successfully

networks:
demo-network:

volumes:
config:
23 changes: 23 additions & 0 deletions grafana-alloy/grafana_provisioning/dashboards/dashboards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: 1

providers:
# <string> an unique provider name. Required
- name: 'greptimedb demo dashboards'
# <int> Org id. Default to 1
orgId: 1
# <string> name of the dashboard folder.
folder: ''
# <string> folder UID. will be automatically generated if not specified
folderUid: ''
# <string> provider type. Default to 'file'
type: file
# <bool> disable dashboard deletion
disableDeletion: false
# <int> how often Grafana will scan for changed dashboards
updateIntervalSeconds: 10
# <bool> allow updating provisioned dashboards from the UI
allowUiUpdates: false
options:
# <string, required> path to dashboard files on disk. Required when using the 'file' type
path: /etc/grafana/provisioning/dashboards
# <bool> use folder names from filesystem to create folders in Grafana
Loading

0 comments on commit cfee3e0

Please sign in to comment.