- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章zabbix 监控mysql的方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
zabbix部署文档 。
zabbix部署完之后 。
zabbix-agent操作 。
1.监控mysql,首先要先安装mysql 。
1
|
[root@localhost ~]# yum -y install mariadb mariadb-server
|
2.编写mysql监控项的脚本 。
在zabbix-agent先授权个用户 不然测试时没有权限 。
1
2
3
4
5
6
7
8
9
10
11
|
[root@localhost ~]# mysql
welcome
to
the mariadb monitor. commands
end
with
;
or
\g.
your mariadb
connection
id
is
33
server version: 5.5.65-mariadb mariadb server
copyright (c) 2000, 2018, oracle, mariadb corporation ab
and
others.
type
'help;'
or
'\h'
for
help. type
'\c'
to
clear the
current
input statement.
mariadb [(none)]>
grant
all
on
*.*
to
'check'
@
'localhost'
identified
by
'123'
;
query ok, 0
rows
affected (0.00 sec)
|
mysql监控的内容主要有 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
[root@localhost ~]# mkdir /etc/zabbix/scipts
[root@localhost ~]# cd /etc/zabbix/scipts/
[root@localhost scipts]# vim mysql.sh
#!/bin/bash
mysql=
"mysql -ucheck -p123"
case
$1
in
# mysql主从状态
slave_status)
$mysql -e
"show slave status\g"
|grep
"yes"
|wc -l
;;
# mysql流量 接受
bytes_received)
mysqladmin extended-status |grep
"bytes_received"
|awk
'{print $4}'
;;
# mysql流量 发送
bytes_sent)
mysqladmin extended-status |grep
"bytes_sent"
|awk
'{print $4}'
;;
# mysql常规操作 增
com_insert)
mysqladmin extended-status |grep -w
"com_insert"
|awk
'{print $4}'
;;
# mysql常规操作 删
com_delete)
mysqladmin extended-status |grep -w
"com_delete"
|awk
'{print $4}'
;;
# mysql常规操作 改
com_update)
mysqladmin extended-status |grep -w
"com_update"
|awk
'{print $4}'
;;
# mysql常规操作 查
com_select)
mysqladmin extended-status |grep -w
"com_select"
|awk
'{print $4}'
;;
# mysql tps
tps)
mysqladmin status |awk
'{print $6/$2}'
;;
# mysql qps=(
rollback
+
commit
)/uptime
qps)
rollback
=$(mysqladmin extended-status |grep -w
"com_rollback"
|awk
'{print $4}'
)
commit
=$(mysqladmin extended-status |grep -w
"com_commit"
|awk
'{print $4}'
)
uptime=$(mysqladmin status |awk
'{print $2}'
)
count
=$[$
rollback
+$
commit
]
echo
"$count $uptime"
> /tmp/a.txt
cat /tmp/a.txt |awk
'{print $1/$2}'
;;
# 库大小 我们这里拿mysql库举例
db)
$mysql -e
"select sum(data_length) from information_schema.tables where table_schema='mysql'"
|sed -n
'2p'
;;
# 表大小 我们这里拿mysql下面的
user
表举例
tb)
$mysql -e
"select sum(data_length) from information_schema.tables where table_schema='mysql' and table_name='user'"
|sed -n
'2p'
;;
esac
|
3.自定义键值key 重启zabbix-agent 。
1
2
3
4
|
[root@localhost scipts]# cd /etc/zabbix/zabbix_agentd.d/
[root@localhost zabbix_agentd.d]# vim mysql.conf
userparameter=mysql[*],/etc/zabbix/scipts/mysql.sh $1
[root@localhost zabbix_agentd.d]# systemctl restart zabbix-agent
|
4.在zabbix-server测试 先安装zabbix-get 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
[root@localhost ~]# yum -y install zabbix-get
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[slave_status]
2
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[bytes_received]
850970
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[bytes_sent]
224906
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[com_insert]
3001
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[com_delete]
135
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[com_update]
128
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[com_select]
19
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[qps]
0.864842
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[tps]
1.92936
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[db]
555118
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[tb]
420
|
报错处理 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[slave_status]
sh: /etc/zabbix/scipts/mysql.sh: 权限不够
脚本执行权限不够 去zabbix-agent 加权限
[root@localhost zabbix_agentd.d]# chmod +x /etc/zabbix/scipts/mysql.sh
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[slave_status]
error 1227 (42000)
at
line 1: access denied; you need (
at
least one
of
) the super,replication client privilege(s)
for
this operation
是因为用户没有权限查看 去zabbix-agent 授权个用户在脚本里面加上
[root@localhost ~]# mysql
welcome
to
the mariadb monitor. commands
end
with
;
or
\g.
your mariadb
connection
id
is
33
server version: 5.5.65-mariadb mariadb server
copyright (c) 2000, 2018, oracle, mariadb corporation ab
and
others.
type
'help;'
or
'\h'
for
help. type
'\c'
to
clear the
current
input statement.
mariadb [(none)]>
grant
all
on
*.*
to
'check'
@
'localhost'
identified
by
'123'
;
query ok, 0
rows
affected (0.00 sec)
[root@localhost scipts]# vim mysql.sh
#!/bin/bash
mysql=
"mysql -ucheck -p123"
case
$1
in
# mysql主从状态
slave_status)
$mysql -e
"show slave status\g"
|grep
"yes"
|wc -l
;;
|
zabbix页面上添加监控项和图形 。
查看mysql流量数据 。
查看mysql qps tps 。
查看mysql主从状态 。
查看mysql常规操作 。
查看mysql库表大小 。
mysql主从配置 。
一.zabbix-server端 。
1
|
[root@localhost ~]# vim /etc/my.cnf
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysql
welcome
to
the mariadb monitor. commands
end
with
;
or
\g.
your mariadb
connection
id
is
7
server version: 5.5.65-mariadb mariadb server
copyright (c) 2000, 2018, oracle, mariadb corporation ab
and
others.
type
'help;'
or
'\h'
for
help. type
'\c'
to
clear the
current
input statement.
mariadb [(none)]> show master status;
+
------------------+----------+--------------+------------------+
| file | position | binlog_do_db | binlog_ignore_db |
+
------------------+----------+--------------+------------------+
| mysql-bin.000001 | 175170 | | |
+
------------------+----------+--------------+------------------+
1 row
in
set
(0.00 sec)
mariadb [(none)]>
grant
all
on
*.*
to
'tom'
@
'%'
identified
by
'123'
;
query ok, 0
rows
affected (0.00 sec)
mariadb [(none)]> flush
privileges
;
query ok, 0
rows
affected (0.00 sec)
|
二.zabbix-agent端 。
1
|
[root@localhost ~]# vim /etc/my.cnf
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysql
welcome
to
the mariadb monitor. commands
end
with
;
or
\g.
your mariadb
connection
id
is
2
server version: 5.5.65-mariadb mariadb server
copyright (c) 2000, 2018, oracle, mariadb corporation ab
and
others.
type
'help;'
or
'\h'
for
help. type
'\c'
to
clear the
current
input statement.
mariadb [(none)]> change master
to
-> master_host=
'192.168.27.136'
,
-> master_user=
'tom'
,
-> master_password=
'123'
,
-> master_log_file=
'mysql-bin.000001'
,
-> master_log_pos=175170;
query ok, 0
rows
affected (0.01 sec)
mariadb [(none)]> start slave;
query ok, 0
rows
affected (0.00 sec)
mariadb [(none)]> show slave status \g;
*************************** 1. row ***************************
slave_io_state: waiting
for
master
to
send event
master_host: 192.168.27.136
master_user: tom
master_port: 3306
connect_retry: 60
master_log_file: mysql-bin.000001
read_master_log_pos: 175170
relay_log_file: mysql-relay.000004
relay_log_pos: 529
relay_master_log_file: mysql-bin.000001
slave_io_running: yes
slave_sql_running:
no
replicate_do_db:
replicate_ignore_db:
replicate_do_table:
replicate_ignore_table:
replicate_wild_do_table:
replicate_wild_ignore_table:
last_errno: 1146
last_error: error
'table '
zabbix.history_uint
' doesn'
t exist
' on query. default database: '
zabbix
'. query: '
insert
into
history_uint (itemid,clock,ns,value)
values
(23287,1602301747,810415730,1)
'
skip_counter: 0
exec_master_log_pos: 173424
relay_log_space: 2565
until_condition: none
until_log_file:
until_log_pos: 0
master_ssl_allowed: no
master_ssl_ca_file:
master_ssl_ca_path:
master_ssl_cert:
master_ssl_cipher:
master_ssl_key:
seconds_behind_master: null
master_ssl_verify_server_cert: no
last_io_errno: 0
last_io_error:
last_sql_errno: 1146
last_sql_error: error '
table
'zabbix.history_uint'
doesn
't exist'
on
query.
default
database
:
'zabbix'
. query:
'insert into history_uint (itemid,clock,ns,value) values (23287,1602301747,810415730,1)'
replicate_ignore_server_ids:
master_server_id: 1
1 row
in
set
(0.00 sec)
error:
no
query specified
|
报错处理 。
1
|
[root@localhost ~]# vim /etc/my.cnf
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysql
welcome
to
the mariadb monitor. commands
end
with
;
or
\g.
your mariadb
connection
id
is
4
server version: 5.5.65-mariadb mariadb server
copyright (c) 2000, 2018, oracle, mariadb corporation ab
and
others.
type
'help;'
or
'\h'
for
help. type
'\c'
to
clear the
current
input statement.
mariadb [(none)]> show slave status \g;
*************************** 1. row ***************************
slave_io_state: waiting
for
master
to
send event
master_host: 192.168.27.136
master_user: tom
master_port: 3306
connect_retry: 60
master_log_file: mysql-bin.000001
read_master_log_pos: 199126
relay_log_file: mysql-relay.000006
relay_log_pos: 3950
relay_master_log_file: mysql-bin.000001
slave_io_running: yes
slave_sql_running: yes
replicate_do_db:
replicate_ignore_db:
replicate_do_table:
replicate_ignore_table:
replicate_wild_do_table:
replicate_wild_ignore_table:
last_errno: 0
last_error:
skip_counter: 0
exec_master_log_pos: 199126
relay_log_space: 4240
until_condition: none
until_log_file:
until_log_pos: 0
master_ssl_allowed:
no
master_ssl_ca_file:
master_ssl_ca_path:
master_ssl_cert:
master_ssl_cipher:
master_ssl_key:
seconds_behind_master: 0
master_ssl_verify_server_cert:
no
last_io_errno: 0
last_io_error:
last_sql_errno: 0
last_sql_error:
replicate_ignore_server_ids:
master_server_id: 1
1 row
in
set
(0.00 sec)
|
到此这篇关于zabbix 监控mysql的方法的文章就介绍到这了,更多相关zabbix 监控mysql内容请搜索我以前的文章或继续浏览下面的相关文章希望大家以后多多支持我! 。
最后此篇关于zabbix 监控mysql的方法的文章就讲到这里了,如果你想了解更多关于zabbix 监控mysql的方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我已经在 ubuntu 14.0 上成功安装了 Zabbix 3.2 服务器主机上的 Z 是绿色的。不幸的是,JMX 是红色的。 Zabbix 服务器:192.168.1.112 带有 tomcat
我想制作一个仪表板,显示我们的 Azure 服务总线队列的状态,并显示“添加到队列的消息”、“队列长度”和“已处理的消息”等的历史记录。使用 Azure 管理门户,我可以看到,这些统计信息大部分是手动
我的 MYSQL 每天晚上都有事件,但我不太确定发生了什么,因为即使我将其设置得早于其他事件,它仍然在早上运行。 问题是,我如何检查运行事件的历史记录或日志,哪一个晚上锁了,哪一个是跑了没跑? 谢谢
1、监控log文件大小超过10g的server 和db 复制代码代码如下: create procedure db_sendmail_mssqllogsize as&n
本教程讨论如何使用 AspectJ 开源框架监控 Spring 应用程序在方法执行方面的性能。 传统上,监控每个 Java 方法所花费的时间的最简单方法是在方法的开头和结尾包含一些跟踪行: publi
有什么可以帮助 msmq 监控的吗?当消息出现在队列中并且在休假时相同时,我想获得一些事件/监视器。 最佳答案 查看 Windows 管理性能计数器。 如果您查看管理工具并找到“性能计数器”,您将能够
我的 Tomcat 中的一个巨大的 web 应用程序有时会开始使用过多的 DBCP 连接,从而导致问题。 为了进行调查,我想在每个时间点准确地知道什么线程/方法持有池的连接。不需要是实时的,事后分析就
在浏览器的整个页面生命周期中监视 cookie 并在 cookie 更改时触发事件的最佳 JS 或 JQuery 特定方法是什么? 最佳答案 据我所知,不可能将 change (或类似)事件直接绑定(
我想尽可能详细地报告我的笔记本的执行情况。简而言之,我想实时查看我的笔记本正在执行的每个操作。例如,我的一个函数有一个 sleep 周期为 5 秒的循环,我希望看到程序实际上正在 sleep 并且循环
Azure 容器服务是否与 Azure Monitor 集成?想知道对 kubernetes 集群进行日志记录/监控的最佳方法是什么? 最佳答案 如果您正在 Azure 上寻找监视工具,您可能需要使用
我一直在尝试使用 erlang:monitor/2 来监视 gen_server。不幸的是,每次我尝试这个时,Erlang shell 都会进入无限循环。 这是我为测试这一点而编写的测试程序。 -mo
Azure 容器服务是否与 Azure Monitor 集成?想知道对 kubernetes 集群进行日志记录/监控的最佳方法是什么? 最佳答案 如果您正在 Azure 上寻找监视工具,您可能需要使用
我想使用 编写一个 shell 脚本来监控集群中的消费者滞后 bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zkconnect
在 .NET 中,假设 thread A 锁定了一个对象。同时,线程B和线程C被阻塞,等待线程A解锁对象。 现在,线程 A 解锁了对象。接下来将选择哪个线程(B 或 C)?它是如何确定的? 最佳答案
我搜索过这个主题,但发现很少有有用的细节。有了这些细节,我尝试编写一些代码如下。 注意:在将此帖子标记为重复之前,请将此帖子中共享的详细信息与其他帖子进行比较,而不仅仅是按主题。 - (NSArray
目录 1、指标监控 2、常用的监控端点 3、定制EndPoint 4、spring boot admin(可以使用)
我们使用 Prometheus 和 Grafana 来监控我们的 Kafka 集群。 在我们的应用程序中,我们使用 Kafka 流,Kafka 流有可能因异常而停止。我们正在记录事件 setUnCau
我正在建立一个复杂的网络仿真,并试图捕捉一些重要的性能测量。 我在服务器上运行了 mininet,并且我将视频从一个 mininet 主机流式传输到另一个(使用 -nodisp 选项,因为我没有 GU
Jenkins 的 openstack-plugin 使用 openstack4j 与 openstack 云对话。我正在寻找一种方法,我们可以从客户端的角度监控 openstack4j 所做的 ht
我正在处理一项需要监控 Thunderbolt 端口连接变化的要求。 (当连接或断开 Thunderbolt 电缆时)。 我尝试使用 IOServiceMatching(kIOUSBInterface
我是一名优秀的程序员,十分优秀!