网站首页 文章专栏 telegraf+influxdb+grafana监控(三)
telegraf+influxdb+grafana监控(三)
编辑时间:2022-04-06 09:56:55 作者:admin 浏览量:48

       在前面的文章已经详细讲解了MQTT、telegraf、influxDB等组件,并已将三者之间的关系理顺,即:MQTT(mosquitto)->telegraf->influxDB。本文将通过 grafana 展示 influxDB 中的数据。

一、安装

https://grafana.com/grafana/download?platform=linux&edition=oss

# wget https://dl.grafana.com/oss/release/grafana-8.4.5.linux-amd64.tar.gz
#  tar -zxvf grafana-8.4.5.linux-amd64.tar.gz
#  运行以下配置文件
 ./grafana-server --config=/home/lxy/telegraf/grafana-8.4.5/conf/defaults.ini

在配置文件中,开放注册模块、并进行端口设置,默认是 Sqlite3,我们可以改为MySQL。

可参考官网文档:https://grafana.com/docs/grafana/latest/administration/configuration/

# [database]
# You can configure the database connection by specifying type, host, name, user and password
# as separate properties or as on string using the url property.

# Either "mysql", "postgres" or "sqlite3", it's your choice
#type = sqlite3
#host = 127.0.0.1:3306
#name = grafana
#user = root
type = mysql
host = 127.0.0.1:3306
name = grafana
user = root

# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = xxxx

# [users]

# disable user signup / registration
# allow_sign_up = false
allow_sign_up = true

# Allow non admin users to create organizations
allow_org_create = false

# Set to true to automatically assign new users to the default organization (id 1)
auto_assign_org = true

# Set this value to automatically add new users to the provided organization (if auto_assign_org above is set to true)
auto_assign_org_id = 1

# Default role new users will be automatically assigned (if auto_assign_org above is set to true)
auto_assign_org_role = Viewer

# Require email validation before sign up completes
verify_email_enabled = false

# Background text for the user field on the login page
login_hint = email or username

[security]
# disable creation of admin user on first start of grafana
disable_initial_admin_creation = false

# default admin user, created on startup
admin_user = admin

# default admin password, can be changed before first start of grafana, or in profile settings
admin_password = xxxx

# used for signing
secret_key = SW2YcwTIb9zpOOhoPsMm

二、安装 plugin (natel-influx-admin-panel)

参考官网文档:https://grafana.com/docs/grafana/latest/administration/cli/#plugins-commands

# List available plugins
 grafana-cli plugins list-remote |grep influx
---------------------------------------------------------------
✔ id: natel-influx-admin-panel version: 0.0.6
---------------------------------------------------------------
#  Install the latest version of a plugin
 grafana-cli plugins install <plugin-id>
---------------------------------------------------------------
#  Install a specific version of a plugin
 grafana-cli plugins install <plugin-id> <version>  
---------------------------------------------------------------
✔ Downloaded natel-influx-admin-panel v0.0.6 zip successfully
✔ Please restart Grafana after installing plugins. Refer to Grafana documentation for instructions if necessary.
---------------------------------------------------------------
#  List installed plugins
  grafana-cli plugins ls
---------------------------------------------------------------
......

三、查询绘图

参考官网文档:https://grafana.com/docs/grafana/latest/dashboards/dashboard-create/

1、连接influxDB

admin账户登录后,添加账户、密码等连接方式。

image.png

2、创建 dashboard

点击添加 panel

image.png

3、配置 sql 语句查询

image.png

可见,上图展示了数据库中的部聚合数据。

image.png


来说两句吧
最新评论