01-grafana.mdx 7.5 KB
Newer Older
1 2 3 4 5
---
sidebar_label: Grafana
title: Grafana
---

6 7 8
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

9
TDengine can be quickly integrated with the open-source data visualization system [Grafana](https://www.grafana.com/) to build a data monitoring and alerting system. The whole process does not require any code development. And you can visualize the contents of the data tables in TDengine on a dashboard.
10 11 12 13 14

You can learn more about using the TDengine plugin on [GitHub](https://github.com/taosdata/grafanaplugin/blob/master/README.md).

## Prerequisites

15 16
In order for Grafana to add the TDengine data source successfully, the following preparations are required:

17 18 19
1. The TDengine cluster is deployed and functioning properly
2. taosAdapter is installed and running properly. Please refer to the taosAdapter manual for details.

20 21 22 23 24
Record these values:

- TDengine REST API url: `http://tdengine.local:6041`.
- TDengine cluster authorization, with user + password.

25 26
## Installing Grafana

27
TDengine currently supports Grafana versions 7.5 and above. Users can go to the Grafana official website to download the installation package and execute the installation according to the current operating system. The download address is as follows: <https://grafana.com/grafana/download>.
28 29 30

## Configuring Grafana

31 32 33 34
### Install Grafana Plugin and Configure Data Source

<Tabs defaultValue="script">
<TabItem value="script" label="Using Script">
35 36 37 38 39 40 41 42

Set the url and authorization environment variables by `export` or a [`.env`(dotenv) file](https://hexdocs.pm/dotenvy/dotenv-file-format.html):

```sh
export TDENGINE_API=http://tdengine.local:6041
# user + password
export TDENGINE_USER=user
export TDENGINE_PASSWORD=password
43 44 45 46 47 48 49 50 51 52

# Other useful variables
# - If to install TDengine data source, default is true
export TDENGINE_DS_ENABLED=false
# - Data source name to be created, default is TDengine
export TDENGINE_DS_NAME=TDengine
# - Data source organization id, default is 1
export GF_ORG_ID=1
# - Data source is editable in admin ui or not, default is 0 (false)
export TDENGINE_EDITABLE=1
53 54 55 56 57 58 59 60
```

Run `install.sh`:

```sh
bash -c "$(curl -fsSL https://raw.githubusercontent.com/taosdata/grafanaplugin/master/install.sh)"
```

61
With this script, TDengine data source plugin and the Grafana data source will be installed and created automatically with Grafana provisioning configurations. Save the script and type `./install.sh --help` for the full usage of the script.
62 63 64

And then, restart Grafana service and open Grafana in web-browser, usually <http://localhost:3000>.

65 66
</TabItem>
<TabItem value="manual" label="Install & Configure Manually">
67

68
Follow the installation steps in [Grafana](https://grafana.com/grafana/plugins/tdengine-datasource/?tab=installation) with the [``grafana-cli`` command-line tool](https://grafana.com/docs/grafana/latest/administration/cli/) for plugin installation.
69

S
Sean Ely 已提交
70
```bash
71 72 73
grafana-cli plugins install tdengine-datasource
# with sudo
sudo -u grafana grafana-cli plugins install tdengine-datasource
74 75
```

76
Alternatively, you can manually download the .zip file from [GitHub](https://github.com/taosdata/grafanaplugin/releases/tag/latest) or [Grafana](https://grafana.com/grafana/plugins/tdengine-datasource/?tab=installation) and unpack it into your grafana plugins directory.
77 78

```bash
79 80
GF_VERSION=3.2.2
# from GitHub
81
wget https://github.com/taosdata/grafanaplugin/releases/download/v$GF_VERSION/tdengine-datasource-$GF_VERSION.zip
82 83
# from Grafana
wget -O tdengine-datasource-$GF_VERSION.zip https://grafana.com/api/plugins/tdengine-datasource/versions/$GF_VERSION/download
84 85
```

86
Take CentOS 7.2 for example, extract the plugin package to /var/lib/grafana/plugins directory, and restart grafana.
87 88 89 90 91

```bash
sudo unzip tdengine-datasource-$GF_VERSION.zip -d /var/lib/grafana/plugins/
```

92
If Grafana is running in a Docker environment, the TDengine plugin can be automatically installed and set up using the following environment variable settings:
93 94

```bash
95
GF_INSTALL_PLUGINS=tdengine-datasource
96 97
```

98
Now users can log in to the Grafana server (username/password: admin/admin) directly through the URL `http://localhost:3000` and add a datasource through `Configuration -> Data Sources` on the left side, as shown in the following figure.
99

D
dingbo 已提交
100
![TDengine Database TDinsight plugin add datasource 1](./grafana/add_datasource1.webp)
101 102 103

Click `Add data source` to enter the Add data source page, and enter TDengine in the query box to add it, as shown in the following figure.

D
dingbo 已提交
104
![TDengine Database TDinsight plugin add datasource 2](./grafana/add_datasource2.webp)
105 106 107

Enter the datasource configuration page, and follow the default prompts to modify the corresponding configuration.

D
dingbo 已提交
108
![TDengine Database TDinsight plugin add database 3](./grafana/add_datasource3.webp)
109 110 111 112 113

- Host: IP address of the server where the components of the TDengine cluster provide REST service (offered by taosd before 2.4 and by taosAdapter since 2.4) and the port number of the TDengine REST service (6041), by default use `http://localhost:6041`.
- User: TDengine user name.
- Password: TDengine user password.

114
Click `Save & Test` to test. You should see a success message if the test worked.
115

D
dingbo 已提交
116
![TDengine Database TDinsight plugin add database 4](./grafana/add_datasource4.webp)
117

118 119 120
</TabItem>
</Tabs>

121 122
### Create Dashboard

123
Go back to the main interface to create a dashboard and click Add Query to enter the panel query page:
124

D
dingbo 已提交
125
![TDengine Database TDinsight plugin create dashboard 1](./grafana/create_dashboard1.webp)
126 127 128

As shown above, select the `TDengine` data source in the `Query` and enter the corresponding SQL in the query box below for query.

S
Sean Ely 已提交
129
- INPUT SQL: enter the statement to be queried (the result set of the SQL statement should be two columns and multiple rows), for example: `select avg(mem_system) from log.dn where ts >= $from and ts < $to interval($interval)`, where, from, to and interval are built-in variables of the TDengine plugin, indicating the range and time interval of queries fetched from the Grafana plugin panel. In addition to the built-in variables, custom template variables are also supported.
130 131 132 133 134
- ALIAS BY: This allows you to set the current query alias.
- GENERATE SQL: Clicking this button will automatically replace the corresponding variables and generate the final executed statement.

Follow the default prompt to query the average system memory usage for the specified interval on the server where the current TDengine deployment is located as follows.

D
dingbo 已提交
135
![TDengine Database TDinsight plugin create dashboard 2](./grafana/create_dashboard2.webp)
136 137 138 139 140

> For more information on how to use Grafana to create the appropriate monitoring interface and for more details on using Grafana, refer to the official Grafana [documentation](https://grafana.com/docs/).

### Importing the Dashboard

141 142 143 144 145 146 147 148
You can install TDinsight dashboard in data source configuration page (like `http://localhost:3000/datasources/edit/1/dashboards`) as a monitoring visualization tool for TDengine cluster. The dashboard is published in Grafana as [Dashboard 15167 - TDinsight](https://grafana.com/grafana/dashboards/15167). Check the [TDinsight User Manual](/reference/tdinsight/) for the details.

For more dashboards using TDengine data source, [search here in Grafana](https://grafana.com/grafana/dashboards/?dataSource=tdengine-datasource). Here is a sub list:

- [15146](https://grafana.com/grafana/dashboards/15146): Monitor multiple TDengine clusters.
- [15155](https://grafana.com/grafana/dashboards/15155): TDengine alert demo.
- [15167](https://grafana.com/grafana/dashboards/15167): TDinsight.
- [16388](https://grafana.com/grafana/dashboards/16388): Telegraf node metrics dashboard using TDengine data source.