《Grafana 部署与可视化展示》
Grafana 是开源的可视化分析平台,常与 Prometheus 配合展示监控指标。
1 项目与文档
- 项目地址:https://github.com/grafana/grafana
- 官方文档:https://grafana.com/docs/
- 教程:https://cloud.tencent.com/developer/article/1411555
2 部署(Debian)
(1)下载安装(dpkg 方式):
wget https://dl.grafana.com/oss/release/grafana_7.1.3_amd64.deb
sudo dpkg -i grafana_7.1.3_amd64.deb
或使用清华镜像源通过 apt 安装:
# 添加 gpg key
curl https://packages.grafana.com/gpg.key | sudo apt-key add -
# apt 支持 https
sudo apt-get install -y apt-transport-https
# 添加 deb 源
echo 'deb https://mirrors.tuna.tsinghua.edu.cn/grafana/apt/ stable main' >> /etc/apt/sources.list
sudo apt-get update
sudo apt-get install grafana
默认配置信息:
- 访问地址:
http://<ip>:3000 - 账号密码:
admin/admin - 日志文件:
/var/log/grafana - 启动脚本:
/etc/init.d/grafana-server - 数据库:
/var/lib/grafana/grafana.db - 配置文件:
/etc/grafana/grafana.ini
3 修改配置文件
将端口从默认 3000 改为 8504,并开启 SMTP 以便发送告警邮件(需确保机器启动了 25 端口的 SMTP 服务):
[server]
# Protocol (http, https, h2, socket)
;protocol = http
# The ip address to bind to, empty will bind to all interfaces
;http_addr =
# The http port to use
http_port = 8504
[smtp]
enabled = true
host = localhost:25
;user =
;password =
;cert_file =
;key_file =
;skip_verify = false
from_address = alert@example.com
from_name = Grafana
;ehlo_identity = dashboard.example.com
;startTLS_policy = NoStartTLS
查看本机 SMTP 服务是否启动(CentOS 使用 postfix):
sudo /etc/init.d/postfix status
# master (pid 7404) is running...
sudo lsof -i:25
# master 7404 root 12u IPv4 ... TCP localhost:smtp (LISTEN)
# smtpd 47589 postfix 6u IPv4 ... TCP localhost:smtp (LISTEN)
4 启动与访问
# start
/etc/init.d/grafana-server start
# [ ok ] Starting Grafana Server:.
# check
/etc/init.d/grafana-server status
# [ ok ] grafana is running.
浏览器访问 http://<server-ip>:8504/login,默认账号 admin / admin。
5 添加数据源与面板
- 点击【设置 ⚙】→【添加数据源】。
- 选择 Prometheus,把 URL 填为 Prometheus server 地址,例如
http://<prometheus-ip>:9090。 - 保存后新建 Dashboard,用 PromQL 表达式添加面板(可参考
_docs/prometheus/prometheus-exporters.md中的常用查询)。
阅读 —
·
全站 —