01-grafana.mdx 10.2 KB
Newer Older
1 2
---
title: Grafana
D
danielclow 已提交
3 4
sidebar_label: Grafana
description: This document describes how to integrate TDengine with Grafana.
5 6
---

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

10
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. You can learn more about using the TDengine plugin on [GitHub](https://github.com/taosdata/grafanaplugin/blob/master/README.md).
11 12 13

## Prerequisites

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

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

19 20 21 22 23
Record these values:

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

24 25
## Installing Grafana

26
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>.
27 28 29

## Configuring Grafana

30 31 32
### Install Grafana Plugin and Configure Data Source

<Tabs defaultValue="script">
33
<TabItem value="gui" label="With GUI">
34

35
Under Grafana 8, plugin catalog allows you to [browse and manage plugins within Grafana](https://grafana.com/docs/grafana/next/administration/plugin-management/#plugin-catalog) (but for Grafana 7.x, use **With Script** or **Install & Configure Manually**). Find the page at **Configurations > Plugins**, search **TDengine** and click it to install.
36

37 38 39 40 41 42 43 44 45 46 47 48 49 50
![Search tdengine in grafana plugins](./grafana/grafana-plugin-search-tdengine.png)

Installation may cost some minutes, then you can **Create a TDengine data source**:

![Install and configure Grafana data source](./grafana/grafana-install-and-config.png)

Then you can add a TDengine data source by filling up the configuration options.

![TDengine Database Grafana plugin add data source](./grafana/grafana-data-source.png)

You can create dashboards with TDengine now.

</TabItem>
<TabItem value="script" label="With Script">
51

52
On a server with Grafana installed, run `install.sh` with TDengine url and username/passwords will install TDengine data source plugin and add a data source named TDengine. This is the recommended way for Grafana 7.x or [Grafana provisioning](https://grafana.com/docs/grafana/latest/administration/provisioning/) users.
53 54

```sh
55 56 57 58 59
bash -c "$(curl -fsSL \
  https://raw.githubusercontent.com/taosdata/grafanaplugin/master/install.sh)" -- \
  -a http://localhost:6041 \
  -u root \
  -p taosdata
60 61
```

62
Restart Grafana service and open Grafana in web-browser, usually <http://localhost:3000>.
63

64
Save the script and type `./install.sh --help` for the full usage of the script.
65

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

69
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.
70

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

77
You can also download zip files from [GitHub](https://github.com/taosdata/grafanaplugin/releases/tag/latest) or [Grafana](https://grafana.com/grafana/plugins/tdengine-datasource/?tab=installation) and install manually. The commands are as follows:
78 79

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

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

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

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

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

99
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.
100

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

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 已提交
105
![TDengine Database TDinsight plugin add datasource 2](./grafana/add_datasource2.webp)
106 107 108

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

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

- 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.

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

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

119 120 121 122 123 124 125 126 127 128 129 130 131
</TabItem>
<TabItem value="container" label="Container">

Please refer to [Install plugins in the Docker container](https://grafana.com/docs/grafana/next/setup-grafana/installation/docker/#install-plugins-in-the-docker-container). This will install `tdengine-datasource` plugin when Grafana container starts:

```bash
docker run -d \
  -p 3000:3000 \
  --name=grafana \
  -e "GF_INSTALL_PLUGINS=tdengine-datasource" \
  grafana/grafana
```

132
You can setup a zero-configuration stack for TDengine + Grafana by [docker-compose](https://docs.docker.com/compose/) and [Grafana provisioning](https://grafana.com/docs/grafana/latest/administration/provisioning/) file:
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185

1. Save the provisioning configuration file to `tdengine.yml`.

    ```yml
    apiVersion: 1
    datasources:
    - name: TDengine
      type: tdengine-datasource
      orgId: 1
      url: "$TDENGINE_API"
      isDefault: true
      secureJsonData:
        url: "$TDENGINE_URL"
        basicAuth: "$TDENGINE_BASIC_AUTH"
        token: "$TDENGINE_CLOUD_TOKEN"
      version: 1
      editable: true
    ```

2. Write `docker-compose.yml` with [TDengine](https://hub.docker.com/r/tdengine/tdengine) and [Grafana](https://hub.docker.com/r/grafana/grafana) image.

    ```yml
    version: "3.7"

    services:
      tdengine:
        image: tdengine/tdengine:2.6.0.2
        environment:
          TAOS_FQDN: tdengine
        volumes:
          - tdengine-data:/var/lib/taos/
      grafana:
        image: grafana/grafana:8.5.6
        volumes:
          - ./tdengine.yml/:/etc/grafana/provisioning/tdengine.yml
          - grafana-data:/var/lib/grafana
        environment:
          # install tdengine plugin at start
          GF_INSTALL_PLUGINS: "tdengine-datasource"
          TDENGINE_URL: "http://tdengine:6041"
          #printf "$TDENGINE_USER:$TDENGINE_PASSWORD" | base64
          TDENGINE_BASIC_AUTH: "cm9vdDp0YmFzZTEyNQ=="
        ports:
          - 3000:3000
    volumes:
      grafana-data:
      tdengine-data:
    ```

3. Start TDengine and Grafana services: `docker-compose up -d`.

Open Grafana <http://localhost:3000>, and you can add dashboard with TDengine now.

186 187 188
</TabItem>
</Tabs>

189 190
### Create Dashboard

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

D
dingbo 已提交
193
![TDengine Database TDinsight plugin create dashboard 1](./grafana/create_dashboard1.webp)
194 195 196

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

197
- INPUT SQL: Enter the desired query (the results being two columns and multiple rows), such as `select _wstart, avg(mem_system) from log.dnodes_info where ts >= $from and ts < $to interval($interval)`. In this statement, $from, $to, and $interval are variables that Grafana replaces with the query time range and interval. In addition to the built-in variables, custom template variables are also supported.
198 199 200 201 202
- 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 已提交
203
![TDengine Database TDinsight plugin create dashboard 2](./grafana/create_dashboard2.webp)
204 205 206 207 208

> 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

209 210 211 212 213
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. Ensure that you use TDinsight for 3.x.

![TDengine Database Grafana plugine import dashboard](./import_dashboard.webp)

A dashboard for TDengine 2.x has been published on Grafana: [Dashboard 15167 - TDinsight](https://grafana.com/grafana/dashboards/15167)) 。 Check the [TDinsight User Manual](/reference/tdinsight/) for the details.
214 215 216 217 218 219 220

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.