01-grafana.mdx 5.3 KB
Newer Older
D
dingbo 已提交
1 2 3 4 5
---
sidebar_label: Grafana
title: Grafana
---

sangshuduo's avatar
sangshuduo 已提交
6
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.
D
dingbo 已提交
7

8
You can learn more about using the TDengine plugin on [GitHub](https://github.com/taosdata/grafanaplugin/blob/master/README.md).
D
dingbo 已提交
9

陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
10 11 12 13 14 15
## Prerequisites

In order for Grafana to add the TDengine data source successfully, the following preparations are required:
1. The TDengine cluster is deployed and functioning properly
2. taosAdapter is installed and running properly. Please refer to the taosAdapter manual for details.

16
## Installing Grafana
D
dingbo 已提交
17

18
TDengine currently supports Grafana versions 7.0 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>.
D
dingbo 已提交
19

20
## Configuring Grafana
D
dingbo 已提交
21

22
You can download The Grafana plugin for TDengine from <https://github.com/taosdata/grafanaplugin/releases/latest>. The current latest version is 3.1.4.
D
dingbo 已提交
23

24 25 26
Recommend using the [``grafana-cli`` command-line tool](https://grafana.com/docs/grafana/latest/administration/cli/) for plugin installation.

``bash
D
dingbo 已提交
27 28 29 30 31
sudo -u grafana grafana-cli \
  --pluginUrl https://github.com/taosdata/grafanaplugin/releases/download/v3.1.4/tdengine-datasource-3.1.4.zip \
  plugins install tdengine-datasource
```

32
Or download it locally and extract it to the Grafana plugin directory.
D
dingbo 已提交
33 34 35 36 37 38

```bash
GF_VERSION=3.1.4
wget https://github.com/taosdata/grafanaplugin/releases/download/v$GF_VERSION/tdengine-datasource-$GF_VERSION.zip
```

39
Take CentOS 7.2 for example, extract the plugin package to /var/lib/grafana/plugins directory, and restart grafana.
D
dingbo 已提交
40 41 42 43 44

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

45
Grafana versions 7.3+ / 8.x do signature checks on plugins, so you also need to add the following line to the grafana.ini file to use the plugin correctly.
D
dingbo 已提交
46 47 48 49 50 51

```ini
[plugins]
allow_loading_unsigned_plugins = tdengine-datasource
```

52
The TDengine plugin can be automatically installed and set up using the following environment variable settings in a Docker environment.
D
dingbo 已提交
53 54

```bash
55
GF_INSTALL_PLUGINS=https://github.com/taosdata/grafanaplugin/releases/download/v3.1.4/tdengine-datasource-3.1.4.zip;tdengine- datasource
D
dingbo 已提交
56 57 58
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=tdengine-datasource
```

59
## Using Grafana
D
dingbo 已提交
60

61
### Configuring Data Sources
D
dingbo 已提交
62

sangshuduo's avatar
sangshuduo 已提交
63
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.
D
dingbo 已提交
64

D
dingbo 已提交
65
![img](./grafana/add_datasource1.webp)
D
dingbo 已提交
66

67
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 已提交
68

D
dingbo 已提交
69
![img](./grafana/add_datasource2.webp)
D
dingbo 已提交
70

71
Enter the datasource configuration page, and follow the default prompts to modify the corresponding configuration.
D
dingbo 已提交
72

D
dingbo 已提交
73
![img](./grafana/add_datasource3.webp)
D
dingbo 已提交
74

sangshuduo's avatar
sangshuduo 已提交
75
- 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`.
76 77
- User: TDengine user name.
- Password: TDengine user password.
D
dingbo 已提交
78

79
Click `Save & Test` to test. Follows are a success.
D
dingbo 已提交
80

D
dingbo 已提交
81
![img](./grafana/add_datasource4.webp)
D
dingbo 已提交
82

83
### Create Dashboard
D
dingbo 已提交
84

85
Go back to the main interface to create the Dashboard, click Add Query to enter the panel query page:
D
dingbo 已提交
86

D
dingbo 已提交
87
![img](./grafana/create_dashboard1.webp)
D
dingbo 已提交
88

89
As shown above, select the `TDengine` data source in the `Query` and enter the corresponding SQL in the query box below for query.
D
dingbo 已提交
90

91 92 93
- 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.
- 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.
D
dingbo 已提交
94

95
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 已提交
96

D
dingbo 已提交
97
![img](./grafana/create_dashboard2.webp)
D
dingbo 已提交
98

99
> 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/).
D
dingbo 已提交
100

101
### Importing the Dashboard
D
dingbo 已提交
102

103
In version 2.3.3.0 and above, you can import the TDinsight Dashboard (Grafana Dashboard ID: [15168](https://grafana.com/grafana/dashboards/15167)) as a monitoring visualization tool for TDengine clusters. You can find installation and usage instructions in the TDinsight User Manual (/reference/tdinsight/).