This is a simple demo to show how to use Grafana with a SQL Server database to visualize data.
- Docker
- Docker Compose
- Drop the provided files in whatever directory is mapped to the MSSQL container on the host machine
- By default this is the
/mnt/c/grafanademo
directory from the second volume definition on that container in thedocker-compose.yml
file
- By default this is the
- Connect to your MSSQL container with
docker exec -it <container_name> /bin/bash
to enter an interactive shell - Run
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P Secret1234 -i /demo/01_create_database_and_tables.sql
to create the database and tables - Run
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P Secret1234 -i /demo/02_add_data_sproc.sql
to insert the sproc that will generate our random data - Run
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P Secret1234 -i /demo/03_add_device_data.sql
to insert some data for our devices
- Clone this repository
- Run
docker-compose up -d
to start the containers- If you are going to change where the database files are stored you can add a
.env
file to the root of the repository with the following contents:MSSQL_SCRIPT_DIR=/path/to/your/mssql/files
- This will override the default value of
/mnt/c/grafanademo
in thedocker-compose.yml
file
- This will override the default value of
- Run
docker compose --env-file .env up -d
again after adding the.env
file
- If you are going to change where the database files are stored you can add a
- Navigate to
http://localhost:3000
in your browser - Log in with the default credentials (admin/admin)
- Add a new data source
- Type: Microsoft SQL Server
- Host: mssql
- Database: GrafanaDemo
- User: sa
- Password: Secret1234
- Import the dashboard from the
dashboard.json
file in this repository- Click the "+" in the left sidebar
- Click "Import"
- Click "Upload .json file"
- Select the
dashboard.json
file - Click "Import"
- If you want to add more devices you can update the insert statements in the initial script
- If you want to adjust the date range of data that gets generated you can update the @StartDate and @EndDate variables that get passed to the sproc in the third script