Skip to content

datalayers-io/datalayers-with-grafana

Repository files navigation

DataLayers with Grafana

Visualize the data stored in DataLayers using Grafana.

How to use

  1. Clone the code repository.
$ git clone https://github.com/datalayers-io/datalayers-with-grafana.git
  1. Please run the following script first.
$ cd datalayers-with-grafana && ./init.sh
  1. 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 standalone.yaml up -d
  1. Perform database operations using command line tools:
$ docker compose -f standalone.yaml exec -it datalayers dlsql -u admin -p public
> create database demo;
  1. 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.

  1. 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:18361/api/v1/sql?db=demo" -H 'Content-Type: application/binary' -d "$code" -s -o /dev/null
  sleep 1
done
  1. Query data using command line tools:
$ docker compose -f standalone.yaml exec -it datalayers dlsql -u admin -p public
> select * from demo.test limit 10
  1. Use Grafana for data visualization:

Visit: http://localhost:13000/

Username: admin
Password: admin

Try to add dashboard by Menu - Dashboards page.

add dashboard

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.

Cluster Mode

Click to Cluster-mode documentation.

License

Apache License 2.0