Use RisingWave to monitor RisingWave metrics
RisingWave uses Prometheus to collect the system metrics. Prometheus is a powerful monitoring platform that provides an end-to-end solution from instrumenting applications to querying metrics.
Overview
However, Prometheus’s local storage is limited to single-node durability and scalability. To replicate data from local storage to remote storage systems, we can use a proxy service that sends data in JSON format to Kafka. Then RisingWave can read, store, and perform complex queries on the data from Kafka.
There are numerous RisingWave system metrics that Prometheus collects. The most convenient method of tracking these metrics would be using a live dashboard. Luckily, since RisingWave is Postgres-compatible, we can use Grafana to visualize the metrics changing over time by creating dashboards.
In this tutorial, you will learn how to use RisingWave as a metrics store to monitor its runtime metrics and visualize them using Grafana.
Prerequisites
- Ensure you have Docker and Docker Compose installed in your environment. Note that Docker Compose is included in Docker Desktop for Windows and macOS. If you use Docker Desktop, ensure it is running before launching the demo cluster.
- Ensure that the PostgreSQL interactive terminal,
psql
, is installed in your environment. For detailed instructions, see Download PostgreSQL.
Step 1: Launch the demo cluster
In the demo cluster, we packaged RisingWave, Prometheus, and Grafana. Prometheus has been set up to collect metrics from RisingWave.
First, clone the risingwave repository to the environment.
Now navigate to the integration_tests/prometheus
directory and start the demo cluster from the docker compose file.
COMMAND NOT FOUND?
The default command-line syntax in Compose V2 starts with docker compose
. See details in the Docker docs.
If you’re using Compose V1, use docker-compose
instead.
Necessary RisingWave components, Prometheus, and Grafana will be started. Prometheus will start collecting data from RisingWave and write them to Kafka topics. In this demo cluster, the data ingested from the Kafka topic will be stored in the MinIO instance.
Now connect to RisingWave to manage data streams and perform data analysis.
Step 2: Connect RisingWave to data streams
Between Prometheus and Kafka, we use Prometheus-kafka-adapter, a proxy service that converts metrics into JSON and then sends them to a Kafka topic.
Here is a sample JSON:
Once the Kafka topic is ready, we can prepare the RisingWave SQL pipeline. The following SQL statement registers the Kafka topic to RisingWave.
We have connected RisingWave to the streams, but RisingWave has not started to consume data yet. For data to be processed, we need to define materialized views. After a materialized view is created, RisingWave will begin to consume data from the specified offset.
Step 3: Create a materialized view
Now, create a materialized view that tracks the average metric values every 30 seconds. We will split the stream into 30 seconds windows and calculate the average metric value over each window. Here we use the tumble window functionality to support window slicing.
Here is an example result.
Step 4: Add RisingWave as a data source in Grafana
Trying to track how a specific metric changes over time without a dashboard is difficult so we will use Grafana to visualize the metrics to make this easier.
Grafana is packaged in the demo cluster and running. To visit Grafana, enter 127.0.0.1:3001
in your web browser. Since RisingWave is Postgres-compatible, RisingWave directly connects to Grafana with the built-in Postgres connector.
To add RisingWave as a Postgres data source:
- Go to Configuration > Data Sources.
- Click Add data source and select PostgreSQL.
- Specify the database connection parameters.
- Click Save & test.
This example uses RisingWave’s “root” user for testing purposes. While in the production environment, it is recommended to use a dedicated read-only user when querying the database using Grafana. To do so, use the following SQL queries:
Step 5: Visualize RisingWave metrics through Grafana
Finally, we can visualize the metrics the materialized view tracks by creating a data panel.
To create a panel:
- In Grafana, go to Dashboards > New dashboard.
- Click on Add a new panel.
- Specify the time range, data source, and query to visualize RisingWave metrics.
When you finish, run the following command to disconnect RisingWave.
Optional: Remove the containers and the data generated with the following command.
Summary:
In this demo, we learned:
- How to set up the data flow of RisingWave → Prometheus → Kafka → RisingWave.
- How to visualize RisingWave’s computed results via Grafana.
Was this page helpful?