Visualize the data stored in DataLayers using Grafana.
- Clone the code repository.
$ git clone https://github.com/datalayers-io/datalayers-with-grafana.git
- Please run the following script first.
$ cd datalayers-with-grafana && ./init.sh
- Please make sure you have installed docker, and then run the following commands to start the demo:
$ docker pull datalayers/datalayers:nightly
$ docker compose -f cluster.yaml up -d --scale datalayers=2
--scale datalayers=2
means to run 2 instances of datalayers.
- Perform database operations using command line tools:
$ docker compose -f cluster.yaml exec -it datalayers dlsql -u admin -p public
> create database demo;
- Create tables:
> use demo;
> CREATE TABLE test(
ts TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
sn int NOT NULL,
speed float NOT NULL,
temperature float,
timestamp KEY (ts))
PARTITION BY HASH(sn) PARTITIONS 2
ENGINE=TimeSeries;
Use exit
to quit the command line tool.
- Use the following script to write data:
while true
do
speed=$((RANDOM % 21 + 100))
temperature=$((RANDOM % 11 + 10))
code="insert into demo.test(sn,speed,temperature) values(10000, ${temperature}, ${speed})"
echo "$code"
curl -u"admin:public" -X POST "http://127.0.0.1:28361/api/v1/sql?db=demo" -H 'Content-Type: application/binary' -d "$code" -s -o /dev/null
sleep 1
done
- Query data using command line tools:
$ docker compose -f cluster.yaml exec -it datalayers dlsql -u admin -p public
> select * from demo.test limit 10
- Use Grafana for data visualization:
Visit: http://localhost:23000/
Username: admin
Password: admin
Try to add dashboard by Menu - Dashboards
page.
For example:
> SELECT date_bin('5 seconds', ts) as timepoint, avg(speed) FROM demo.test group by timepoint;
As always, you can use SQL functions in the sentence.
Click to Standalone-mode documentation.