在Ubuntu 部署 Grafana且监控MySQL数据

一、安装

打开终端按顺序执行以下命令

1.添加 Grafana 的 APT 仓库

复制代码
sudo apt-get install -y software-properties-common
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"

2.导入Grafana GPG key

复制代码
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -

3.安装 Grafana

复制代码
sudo apt update
sudo apt install grafana

4.启动 Grafana 服务&设置开机自启

复制代码
sudo systemctl start grafana-server
sudo systemctl enable grafana-server

二、验证安装

通过浏览器访问 Grafana (默认地址http://localhost:3000,默认用户名和密码都是 admin)。

出现以下界面证明安装成功,登录成功后,我想创建数据源

或者命令行执行

复制代码
sudo systemctl status grafana-server

返回running表示启动成功

三、监控mysql

配置mysql数据源

发现报错了,让在日志里看详情

要不我创建一个查询账号看看,看上面的建议说使用只有Select权限的账号就可以了

复制代码
-- 创建新用户
CREATE USER 'newuser'@'%' IDENTIFIED BY 'password';
 
-- 赋予Select权限
GRANT SELECT ON hmblogs.* TO 'newuser'@'%';
 
-- 刷新权限使其立即生效
FLUSH PRIVILEGES;

换成只有查询权限的账号后,问题解决了,数据源能正常连通了

在做仪表盘的时候,也能选到表和字段了

这里添加了一个监控,然后我要添加告警,但是失败了

查看contact配置,发现发不出邮件,说什么请检查grafana.ini配置

配置成如上这样就行,下面贴出配置

复制代码
#################################### SMTP / Emailing ##########################
[smtp]
enabled = true
host = smtp.163.com:465
user = southpoet@163.com
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = FFJEPDMVMOPCOKAH
cert_file =
key_file =
skip_verify = false
from_address = southpoet@163.com
from_name = veminghe
# EHLO identity in SMTP dialog (defaults to instance_name)
ehlo_identity = dashboard.example.com
# SMTP startTLS policy (defaults to 'OpportunisticStartTLS')
;startTLS_policy = NoStartTLS
# Enable trace propagation in e-mail headers, using the 'traceparent', 'tracestate' and (optionally) 'baggage' fields (defaults to false)
;enable_tracing = false

[smtp.static_headers]
# Include custom static headers in all outgoing emails
;Foo-Header = bar
;Foo = bar

[emails]
welcome_email_on_sign_up = false
templates_pattern = emails/*.html, emails/*.txt
content_types = text/html

过程中还遇到了SMTP服务器: smtp.163.com对应应该使用哪个端口?

尝试使用465端口,重启服务,然后发现,Test能发出邮件了,然后也能收到grafana的告警邮件了。

虽然调通了,但是告警规则没搞清,符合什么条件就会告警,条件怎么定义呢?

相关推荐
计算机毕设定制辅导-无忧学长1 天前
Grafana 与 InfluxDB 可视化深度集成(二)
信息可视化·数据分析·grafana
云游1 天前
大模型性能指标的监控系统(prometheus3.5.0)和可视化工具(grafana12.1.0)基础篇
grafana·prometheus·可视化·监控
qq_232045573 天前
非容器方式安装Prometheus和Grafana,以及nginx配置访问Grafana
nginx·grafana·prometheus
测试开发Kevin3 天前
详解grafana k6 中stage的核心概念与作用
测试工具·压力测试·grafana
天翼云开发者社区4 天前
Grafana无法启动修复解决
grafana
Ditglu.5 天前
使用Prometheus + Grafana + node_exporter实现Linux服务器性能监控
服务器·grafana·prometheus
hxdcxy8 天前
prometheus+Grafana 监控中间件项目
grafana·prometheus
xiejava10188 天前
Loki+Alloy+Grafana构建轻量级的日志分析系统
grafana·loki·日志分析·alloy
whiteBrocade8 天前
APM-Grafana-Mimir代替Prometheus实现指标长期存储
docker·grafana·prometheus
louqle14 天前
【AI问答】PromQL中interval和rate_interval的区别以及Grafana面板的配置建议
grafana·prometheus