转 zabbix debug and zabbix使用percona插件监控mysql
##########
https://www.cnblogs.com/keithtt/p/8542987.html
zabbix使用percona插件监控mysql
1、添加percona仓库。
# yum install -y https://mirrors.tuna.tsinghua.edu.cn/percona/yum/percona-release-latest.noarch.rpm
2、安装插件。
# yum -y install percona-zabbix-templates
# rpm -ql percona-zabbix-templates
/var/lib/zabbix/percona
/var/lib/zabbix/percona/scripts
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
/var/lib/zabbix/percona/templates
/var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf
/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml
3、这个项目是php写的,需要安装php和php-mysql。(这个在官网有说明)
# yum install -y php php-mysql
4、拷贝配置文件到配置目录,并重启zabbix-agent。
# cp -a /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
# rm -f /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
# service zabbix-agent restart
5、授权监控用户,使其能获取数据。
# mysql -uroot -p
> grant all privileges on *.* to zabbix@localhost identified by 'PASS';
> flush privileges;
> quit;
6、修改程序里面的用户密码,使其能连接到mysql。
# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'zabbix';
$mysql_pass = 'PASS';
7、修改监控脚本。脚本里面是直接执行mysql命令获取数据的,但是没有指定用户名和密码,导致连不上数据库。为mysql命令加上用户名密码参数即可。
# vim /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
RES=`HOME=~zabbix mysql -uzabbix -pPASS -e 'SHOW SLAVE STATUS\G' 2> /dev/null | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
或者更简单一点,直接添加一个mysql的客户端验证配置。
# vim ~zabbix/.my.cnf
[client]
user = zabbix
password = PASS
8、测试脚本是否能获取到数据。
# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
16
# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jg
0
# sudo -u zabbix -H /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slave
1
# sudo -u zabbix zabbix_get -s 10.0.1.61 -k 'proc.num[mysqld]'
1
# sudo -u zabbix zabbix_get -s 10.0.1.61 -k 'mysql.ping'
1
9、导入模板。在这里踩到坑,安装包提供的插件版本是1.1.8,导入过程中报错。经过一番查询,可以使用1.1.6。
可以从这里下载1.1.6版本的文件:https://www.percona.com/downloads/percona-monitoring-plugins/
按理说,导入模板之后,链接到主机就可以查看到数据了。不过,等了很久一直没数据,又是经过一番查询...
插件创建了一个状态文件,然后从中读取数据,但是这个文件第一次启动的时候所属用户是root,而zabbix的启动用户是zabbix,没有权限读取这个文件,所以页面上一直没有数据。
解决办法很简单,删除这个文件即可,程序会自动创建一个权限正确的新文件。
# rm -f /tmp/localhost-mysql_cacti_stats.txt
10、到这里就可以看到数据了。
补充:
如果把默认端口3306改成了别的端口,也会造成报错读取不到数据。
在/var/lib/zabbix/percona/scripts目录下有两个脚本,经过仔细查看,发现get_mysql_stats_wrapper.sh在指定读取的状态文件时路径是写的是CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt"
,而在/tmp/目录下是一个带端口的文件localhost-mysql_cacti_stats.txt:3310,这样肯定就读不到了。然后去找文件是在哪里生成的,查看另一个php脚本,果然做了判断处理,端口不是3306的话就在文件名后面加上端口号。
问题找到了,将源码中的判断部分去掉就好了。
# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$cache_file = "$cache_dir/$sanitized_host-mysql_cacti_stats.txt" . ($port != 3306 ? ":$port" : '');
改成:
$cache_file = "$cache_dir/$sanitized_host-mysql_cacti_stats.txt";
参考:
https://www.percona.com/doc/percona-monitoring-plugins/LATEST/zabbix/index.html
https://blog.csdn.net/liang_operations/article/details/81868668
######sample 3 小bug
http://www.manongjc.com/article/18964.html
Percona Monitoring Plugins for Zabbix模板 用于Mysql Replication的Slave Running和Slave Stopped监控项的数据不正确
今天小试了一把Percona Monitoring Plugins for Zabbix模板,自己辛辛苦苦写的那一大堆Python脚本,貌似用这个模板全都覆盖到了。
但是,我也发现最新的版本percona-monitoring-plugins_1.1.8也还是存在一个问题,那就是用于Mysql Replication的Slave Running和Slave Stopped监控项的数据不正确(一般情况下,两项数据均维持在0)。
经检查相关模板的脚本文件ss_get_mysql_stats.php,发现用于获取Slave Running和Slave Stopped监控项的脚本逻辑有问题。
相关脚本内容为:
$status['slave_lag'] = $row['seconds_behind_master'];
......
$status['slave_running'] = ($row['slave_sql_running'] == 'Yes')
? $status['slave_lag'] : 0;
$status['slave_stopped'] = ($row['slave_sql_running'] == 'Yes')
? 0 : $status['slave_lag'];
可见当slave_sql_running为Yes时,slave_running的取值是seconds_behind_master,slave_stopped的取值是0。
当slave_sql_running为No时,slave_running的取值是0,slave_stopped的取值是seconds_behind_master。
这里我将脚本中$status['slave_lag']更改为了1:
$status['slave_lag'] = $row['seconds_behind_master'];
......
$status['slave_running'] = ($row['slave_sql_running'] == 'Yes')
? 1 : 0;
$status['slave_stopped'] = ($row['slave_sql_running'] == 'Yes')
? 0 : 1;
修改后监控数据正常了。
############
https://blog.csdn.net/u011731378/article/details/79092259
Zabbix Agent Log
17-06-2013, 02:34Dear All,All of my Windows hosts (Windows Server 2008 R2 & Windows Server 2012) both have no zabbix_agentd.log file at all. I don't know why. Below is configuration of one host:
# This is a config file for Zabbix Agent (Windows)
# To get more information about Zabbix, go to http://www.zabbix.com############ GENERAL PARAMETERS #################
### Option: LogFile
# Name of log file.
# If not set, Windows Event Log is used.
#
# Mandatory: no
# Default:
# LogFile=LogFile=C:\Program Files\Zabbix Agent\Zabbix_agentd.log
### Option: LogFileSize
# Maximum size of log file in MB.
# 0 - disable automatic log rotation.
#
# Mandatory: no
# Range: 0-1024
# Default:
# LogFileSize=1### Option: DebugLevel
# Specifies debug level
# 0 - no debug
# 1 - critical information
# 2 - error information
# 3 - warnings
# 4 - for debugging (produces lots of information)
#
# Mandatory: no
# Range: 0-4
# Default:
# DebugLevel=3
DebugLevel=0### Option: SourceIP
# Source IP address for outgoing connections.
#
# Mandatory: no
# Default:
# SourceIP=### Option: EnableRemoteCommands
# Whether remote commands from Zabbix server are allowed.
# 0 - not allowed
# 1 - allowed
#
# Mandatory: no
# Default:
EnableRemoteCommands=1### Option: LogRemoteCommands
# Enable logging of executed shell commands as warnings.
# 0 - disabled
# 1 - enabled
#
# Mandatory: no
# Default:
# LogRemoteCommands=0##### Passive checks related
### Option: Server
# List of comma delimited IP addresses (or hostnames) of Zabbix servers.
# Incoming connections will be accepted only from the hosts listed here.
# No spaces allowed.
# If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally.
#
# Mandatory: no
# Default:
# Server=Server=10.10.20.85
### Option: ListenPort
# Agent will listen on this port for connections from the server.
#
# Mandatory: no
# Range: 1024-32767
# Default:
ListenPort=10050### Option: ListenIP
# List of comma delimited IP addresses that the agent should listen on.
# First IP address is sent to Zabbix server if connecting to it to retrieve list of active checks.
#
# Mandatory: no
# Default:
# ListenIP=0.0.0.0### Option: StartAgents
# Number of pre-forked instances of zabbix_agentd that process passive checks.
# If set to 0, disables passive checks and the agent will not listen on any TCP port.
#
# Mandatory: no
# Range: 0-100
# Default:
# StartAgents=3##### Active checks related
### Option: ServerActive
# List of comma delimited IPort (or hostnameort) pairs of Zabbix servers for active checks.
# If port is not specified, default port is used.
# IPv6 addresses must be enclosed in square brackets if port for that host is specified.
# If port is not specified, square brackets for IPv6 addresses are optional.
# If this parameter is not specified, active checks are disabled.
# Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1]
#
# Mandatory: no
# Default:
# ServerActive=ServerActive=127.0.0.1
### Option: Hostname
# Unique, case sensitive hostname.
# Required for active checks and must match hostname as configured on the server.
# Value is acquired from HostnameItem if undefined.
#
# Mandatory: no
# Default:
Hostname=NI-HOST01### Option: HostnameItem
# Item used for generating Hostname if it is undefined.
# Ignored if Hostname is defined.
#
# Mandatory: no
# Default:
# HostnameItem=system.hostname### Option: RefreshActiveChecks
# How often list of active checks is refreshed, in seconds.
#
# Mandatory: no
# Range: 60-3600
# Default:
# RefreshActiveChecks=120### Option: BufferSend
# Do not keep data longer than N seconds in buffer.
#
# Mandatory: no
# Range: 1-3600
# Default:
# BufferSend=5### Option: BufferSize
# Maximum number of values in a memory buffer. The agent will send
# all collected data to Zabbix server or Proxy if the buffer is full.
#
# Mandatory: no
# Range: 2-65535
# Default:
# BufferSize=100### Option: MaxLinesPerSecond
# Maximum number of new lines the agent will send per second to Zabbix Server
# or Proxy processing 'log', 'logrt' and 'eventlog' active checks.
# The provided value will be overridden by the parameter 'maxlines',
# provided in 'log', 'logrt' or 'eventlog' item keys.
#
# Mandatory: no
# Range: 1-1000
# Default:
# MaxLinesPerSecond=100############ ADVANCED PARAMETERS #################
### Option: Alias
# Sets an alias for parameter. It can be useful to substitute long and complex parameter name with a smaller and simpler one.
# For example, if you wish to retrieve paging file usage in percents from the server,
# you may use parameter "perf_counter[\Paging File(_Total)\% Usage]", or you may define an alias by adding the following line to configuration file
# Alias = pg_usageerf_counter[\Paging File(_Total)\% Usage]
# After that you can use parameter name "pg_usage" to retrieve the same information.
# You can specify as many "Alias" records as you wish.
# Aliases cannot be used for parameters defined in "PerfCounter" configuration file records.
#
# Mandatory: no
# Range:
# Default:### Option: Timeout
# Spend no more than Timeout seconds on processing
#
# Mandatory: no
# Range: 1-30
# Default:
# Timeout=3### Option: PerfCounter
# Syntax: <parameter_name>,"<perf_counter_path>",<period>
# Defines new parameter <parameter_name> which is an average value for system performance counter <perf_counter_path> for the specified time period <period> (in seconds).
# For example, if you wish to receive average number of processor interrupts per second for last minute, you can define new parameter "interrupts" as following:
# PerfCounter = interrupts,"\Processor(0)\Interrupts/sec",60
# Please note double quotes around performance counter path.
# Samples for calculating average value will be taken every second.
# You may run "typeperf -qx" to get list of all performance counters available in Windows.
#
# Mandatory: no
# Range:
# Default:### Option: Include
# You may include individual files in the configuration file.
#
# Mandatory: no
# Default:
# Include=# Include=c:\zabbix\zabbix_agentd.userparams.conf
# Include=c:\zabbix\zabbix_agentd\####### USER-DEFINED MONITORED PARAMETERS #######
### Option: UnsafeUserParameters
# Allow all characters to be passed in arguments to user-defined parameters.
# 0 - do not allow
# 1 - allow
#
# Mandatory: no
# Range: 0-1
# Default:
# UnsafeUserParameters=0### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=<key>,<shell command>
# Note that shell command must not return empty string or EOL only.
# Example: UserParameter=system.test,echo 1
#UserParameter=system.test,echo 1Tags: None- 18-06-2013, 07:25Believe it or not, Zabbix is case sensitive, even on Windows. So your log directory and file name: C:\Program Files\Zabbix Agent\Zabbix_agentd.log need to be cased appropriately.
I don't know if that is your issue or not, but I ran into that when I was first starting out with Zabbix.
And you have DebugLevel=0 Put that at 3 and you will start seeing a log, I suspect.
Last edited by tchjts1; 18-06-2013, 07:27. - 18-06-2013, 08:25Originally posted by tchjts1 View PostBelieve it or not, Zabbix is case sensitive, even on Windows. So your log directory and file name: C:\Program Files\Zabbix Agent\Zabbix_agentd.log need to be cased appropriately.
I don't know if that is your issue or not, but I ran into that when I was first starting out with Zabbix.
And you have DebugLevel=0 Put that at 3 and you will start seeing a log, I suspect.
Thanks. The problem is solved with set value for parameter DebugLevel
#########sampl 2 (主动轮询 和 被动接受 )https://blog.csdn.net/adparking/article/details/7825183怎么知道zabbix server是主动轮询收集信息还是被动接受zabbix agent的信息
zabbix_agent [TCP 主动轮询]
zabbix_sender [UDP 被动接受代理收集的系统信息]一、从网上下载相应脚本与XML定义文件。
Template_MySQL_Server.xml
Template_MySQL_Replication_Master.xml
Template_MySQL_Replication_Slave.xml
和执行脚本:mysql.php
二、把mysql.php上传至配置文件目录/etc/zabbix/
chmod 755 mysql.php
三、修改mysql.php文件
根据本机环境。
第一行加入:#!/usr/bin/php
在最后一行加入:?>
关闭调试:define('DEBUG',true); 为 define('DEBUG',False);
修改日志、数据文件路径:
define('LOG',"/tmp/zabbix_".SYSTEM.".log");
define('DAT',"/tmp/zabbix_".SYSTEM.".dat");
define('UTIME',"/tmp/.zabbix_".SYSTEM.".utime");
define('DTIME',"/tmp/.zabbix_".SYSTEM.".dtime");修改:define('SYSTEM','mysql'.(DEBUG ? "-debug" : "")); 为:define('SYSTEM','mysql');
打开系统日志功能://system("zabbix_sender -z $server -i ".DAT." >> ".LOG); 为:system("zabbix_sender -z $server -i ".DAT." >> ".LOG);
注释file_put_contents(DAT,"$server $host 10051 ".SYSTEM.".$var $val\n",FILE_APPEND);且
下面增加以下文字:
$cmd = "zabbix_sender -c $config_path -k ".SYSTEM.".$var -o $val -vv";
file_put_contents(DAT,"$cmd\n",FILE_APPEND);
exec($cmd);四、在zabbix_agentd.conf配置文件中加入
UserParameter=mysql.daily,php /etc/zabbix/mysql.php daily 用户名 密码
UserParameter=mysql.live,php /etc/zabbix/mysql.php live 用户名 密码daily:每天执行一次。【由zabbix_server轮询发起,默认86640秒即一天 zabbix agent类型 UDP协议】
live:按指定时间执行一次。【由zabbix_server轮询发起,默认120秒 zabbix agent类型 UDP协议】
php :执行php文件
/etc/zabbix/mysql.php:mysql.php文件所在的文件路径
用户名 密码:登录mysql数据库的账户与密码
重启zabbix_agentd
切记修改/etc/profile 或者 /home/zabbix/.bash_profile 在文件尾部添加以下文字
/home/zabbix/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/webserver/mysql/bin:/usr/local/webserver/php/bin:/usr/local/webserver/zabbix_agents/bin
export PATH/etc/profile
PATH=$PATH:/usr/local/webserver/mysql/bin:/usr/local/webserver/php/bin:/usr/local/webserver/zabbix_agents/bin
export PATHmysql.php 监控文件里面的命令执行失败【/tmp下的日志文件属主权限、用户的.bash_profile是否导入 php zabbix_sender mys】
问题:
Zabbix agent (active) 走 UDP 协议 NGINX 添加的 zabbix_agentd 服务后,且通过zabbix_get可以获取数据,但是无法入库。解决方法看下面大红字修改防火墙设置 vi /etc/sysconfig/iptables
【zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper
】
-A INPUT -p tcp -s 110.80.20.XXX-m multiport --dports 10050,10051 -j ACCEPT
-A INPUT -p udp -s 110.80.20.XXXX-m multiport --dports 10050,10051 -j ACCEPT五、在zabbix web管理界面导入xml文件
配置-导入/导出-浏览
六、在主机内增加指定模板
配置-主机-具体主机名-Link with Template-新增-刚导入的模板。
模板分为三种:
template MYSQL_server:监控项最全【下载文件有备注信息、且若干个tigger有重复会导致导入失败】
由于监控的item很多所以必须修改 Timeout 系统最大值 30秒。默认3秒。范围 1-30秒 否则服务端测试时会
Timeout while executing a shell script 当然如果项目在30秒无法发送完毕也将停止,所以导致发送不全面
### Option: Timeout
# Spend no more than Timeout seconds on processing
#
# Mandatory: no
# Range: 1-30
# Default:
Timeout=30template MYSQL_Replication_Master:只监控主要参数,监控功能相对最少
template MYSQL_Replication_Slave:主要针对性能方面的监控。
七、测试监控是否成功
删除 定时文件
rm /tmp/.zabbix_mysql-debug.dtime;
取的每天的监控数据
php /etc/zabbix/mysql.php daily root *****
取即时数据
php /etc/zabbix/mysql.php live root *****
查看日志
cat /tmp/zabbix_mysql.log
Info from server: "Processed 1 Failed 0 Total 1 Seconds spent 0.006261"
sent: 1; skipped: 0; total: 1
Info from server: "Processed 1 Failed 0 Total 1 Seconds spent 0.004047"
sent: 1; skipped: 0; total: 1
Info from server: "Processed 0 Failed 106 Total 106 Seconds spent 0.045790"
sent: 106; skipped: 0; total: 106看到上述为成功
查看DAT的文件。上传的数据
cat /tmp/zabbix_mysql.dat
八、最后查看zabbix 的最新数据
这时会看到新增加的监控项。
接下去就是绘制图形。
####sample 3
https://www.cnblogs.com/guoyishen/p/6891953.html
Zabbix 3.2.6-Mysql多实例监控-Percona Monitoring Plugins自动发现
mysql多实例监控实录系统环境:cat /etc/redhat-releaseCentOS Linux release 7.3.1611 (Core)内核版本:uname -r3.10.0-514.el7.x86_64docker版本:docker -vDocker version 1.12.6, build 3a094bd/1.12.6docker 相关镜像版本:docker.io/zabbix/zabbix-web-nginx-mysql latestdocker.io/zabbix/zabbix-server-mysql latestdocker.io/mysql 5.7被监控mysql应用版本:mysql-5.7.17-linux-glibc2.5-x86_64Percona Monitoring Plugins版本:写在最前:如果zabbix server和zabbix agent已经通过其他方式安装,可以直接跳过1、2步,直接从第3步开始看。1、zabbix服务端我们运行在docker容器内所以服务器端先安装docker服务yum install -y epel-releaseyum install -y docker #centos6.x版本的命令是yum install -y docker-io然后运行docker服务systemctl start dockerdocker加入开机自启动systemctl enable docker查看docker是否成功启动systemctl status docker注:使用docker需要使用加速器,否则那龟速,自己体会吧。加速器daocloud和阿里云都可以,我使用的前者。2.安装相关容器2.1. mysql 容器docker run --name mysql-server -t \-e MYSQL_DATABASE="zabbix" \-e MYSQL_USER="zabbix" \-e MYSQL_PASSWORD="ywwd.net" \-e MYSQL_ROOT_PASSWORD="ywwd.net" \-v /data/container/mysql/zabbix:/var/lib/mysql \-v /etc/localtime:/etc/localtime:ro \--restart=always \-d mysql:5.7 \--character-set-server=utf8 --collation-server=utf8_general_ci --sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"2.2. zabbix-server 容器docker run --name zabbix-server-mysql -t \-e DB_SERVER_HOST="mysql-server" \-e MYSQL_DATABASE="zabbix" \-e MYSQL_USER="zabbix" \-e MYSQL_PASSWORD="ywwd.net" \-e MYSQL_ROOT_PASSWORD="ywwd.net" \--link mysql-server:mysql \-p 10051:10051 --restart=always \-v /etc/localtime:/etc/localtime:ro \-d zabbix/zabbix-server-mysql:latest2.3. zabbix-web 容器(nginx)docker run --name zabbix-web-nginx-mysql -t \-e DB_SERVER_HOST="mysql-server" \-e MYSQL_DATABASE="zabbix" \-e MYSQL_USER="zabbix" \-e MYSQL_PASSWORD="ywwd.net" \-e MYSQL_ROOT_PASSWORD="ywwd.net" \--link mysql-server:mysql \--link zabbix-server-mysql:zabbix-server \-v /etc/localtime:/etc/localtime:ro \-p 80:80 \--restart=always \-d zabbix/zabbix-web-nginx-mysql:latest注意:这里有个小问题,zabbix-web-nginx-mysql的启动脚本/run_zabbix_component.sh中,指定了时区,不是中国的Asia/Shanghai,所以我们要进入zabbix-web-nginx-mysql进行修改2.4. 修改zabbix-web的时区docker exec -it zabbix-web-nginx-mysql /bin/bashTZ=${TZ:-"Asia/Shanghai"} 这里改为Asia/Shanghai,否则zabbix-web端的时间会慢5个小时sed -in 's#Europe/Riga#Asia/Shanghai#g' /run_zabbix_component.sh修改时区后,需要重启容器docker restart zabbix-web-nginx-mysql2.5. 在firewall防火墙放开zabbix-server和zabbix-agent的服务端口号firewall-cmd --permanent --add-port=10050-10051/tcp#--permanent永久生效,10050zabbix-agent服务端口,10051zabbix-server服务端口firewall-cmd --reload#更改后需要重新加载firewall防火墙firewall-cmd --list-all#最后查看配置是否生效这样zabbix-server端就已经安装完毕接下来客户端我们采用rpm包进行安装rpm -ivh zabbix-agent-3.2.6-1.el7.x86_64.rpm同样需要放开zabbix-agent端口firewall-cmd --permanent --add-port=10050/tcpfirewall-cmd --reload然后对zabbix-agent端进行配置egrep -v '^$|^#' /etc/zabbix/zabbix_agentd.confPidFile=/var/run/zabbix/zabbix_agentd.pidLogFile=/var/log/zabbix/zabbix_agentd.logServer=10.0.0.106 # <====zabbix-server端的IP地址ServerActive=10.0.0.106 #<====zabbix-server端的IP地址,主动方式Hostname=10.0.0.107 #<====zabbix-agent端的IP地址或者主机名Include=/etc/zabbix/zabbix_agentd.d/*.conf然后在zabbix-server端的web界面进行主机添加1)修改主机名称,要跟zabbix-agent的配置文件中的Hostname相对应2)选择你想设置的群组,如果群组不存在,可以在下面一栏新的群组中进行添加3)指定zabbix-agent端的IP地址或者域名(端口号一般变)其他保持默认,点击添加即可https://github.com/hc-dba/Mysql_Multiport_monitor_used_zabbix3、利用Percona Monitoring Plugins插件进行MySQL多实例的监控1)percona监控zabbix的脚本是使用php写的,所以需要准备好php运行环境,这里直接用yum安装就可以满足要求了:yum install -y php php-mysql2)安装percona-zabbix-templates也可配置Percona yum仓库后安装,建议配置percona的yum源,因为作为一个DBA你肯定会用到percona toolkit套件。 注:我没有用这种方式,percona toolkit我是通过源码包安装的。yum install -y https://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-3.noarch.rpmyum install -y percona-zabbix-templates4、yum安装的shell为单实例版,所以我们要进行相关修改,这里已经有小伙伴进行了修改,我们直接克隆,进行对比,需要先安装gitgit clone https://github.com/lianghx7123/Mysql_Multiport_monitor_used_zabbix.git mysql_monitor1)对比后,我们发现在get_mysql_stats_wrapper.sh脚本中,添加了相关参数PORT=$2HOST=127.0.0.12)CMD="/usr/bin/php -q $DIR/ss_get_mysql_stats.php --host $HOST --items $ITEM --port $PORT"CMD变量的php路径一定要指定正确,否则会报错,我们在后面添加了 --port $PORTCACHEFILE改为判断if [ $PORT == 3306 ];thenCACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt"elseCACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt":$PORTfi3)running-slave进行如下修改,此处报警跟模板中的另一个Slave Stopped是重叠的,不过这个比Slave Stopped要灵敏,大概提前3分钟左右报警,不过需要在/etc/my.cnf以及脚本中添加mysql的账号和密码等信息,各有利弊吧if [ "$ITEM" = "running-slave" ]; then# Check for running slaveRES=`HOME=~zabbix /usr/local/mysql/bin/mysql -P$PORT -h127.0.0.1 -uzabbix -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | grep -i yes|wc -l `if [ "$RES" -ne 2 ]; thenecho 1elseecho 0fiexit并在/etc/my.cnf中添加[mysql]password=123456 #存在安全隐患,但是如果把权限改小,可能会获取不到值,因为是通过zabbix用户去运行的脚本,里面只是密码,而且账号只能本机登录,所以问题也不大,但是要严格控制其他3个shell脚本的权限。##sampleRES=`HOME=~zabbix /db/mysql/app/mysql/bin/mysql -uuser-puseroprommo11 -e 'SHOW SLAVE STATUS\G' 2>/dev/null | egrep '(Slave_IO_Running|Slave_SQL_Running):' | grep -i yes|wc -l`
if [ "$RES" -ne 2 ]; then
echo 1
else
RES1=`HOME=~zabbix /db/mysql/app/mysql/bin/mysql -uuser-puseroprommo11 -e 'SHOW SLAVE STATUS\G' 2>/dev/null | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
if [ "$RES1" = " Yes, Yes," ]; then
echo 1
else
echo 0
fi
fi
exit
4)#cat $CACHEFILE | sed 's/ /\n/g; s/-1/0/g'| grep $ITEM | awk -F: '{print $2}'这一列改为:cat $CACHEFILE | sed 's/ /\n/g'| grep $ITEM | awk -F: '{print $2}' 或者cat $CACHEFILE | sed 's/ /\n/g; s/-1/1/g'| grep $ITEM | awk -F: '{print $2}'改为第一个,在zabbix-server的web端配置报警阈值为小于0,或者等于1的时候报警,改为第二行,可以统一设置报警阈值为等于1,因为这个问题,困扰了我好久5、修改自动发现脚本cat mysql_low_discovery.sh#!/bin/bash#Fucation:mysql low-level discovery#Script_name mysql_low_discovery.shdiscovery() {port=($(sudo ss -tpln | awk -F "[ :]+" '/[m]ysql/ {print $4}'))printf '{\n'printf '\t"data":[\n'for key in ${!port[@]}doif [[ "${#port[@]}" -gt 1 && "${key}" -ne "$((${#port[@]}-1))" ]];thensocket=`ps aux|grep ${port[${key}]}|grep -v grep|awk -F '=' '{print $9}'|cut -d ' ' -f 1`printf '\t {\n'printf "\t\t\t\"{#MYSQLPORT}\":\"${port[${key}]}\"},\n"else [[ "${key}" -eq "((${#port[@]}-1))" ]]socket=`ps aux|grep ${port[${key}]}|grep -v grep|awk -F '=' '{print $9}'|cut -d ' ' -f 1`printf '\t {\n'printf "\t\t\t\"{#MYSQLPORT}\":\"${port[${key}]}\"}\n"fidoneprintf '\t ]\n'printf '}\n'}discovery注意:由于此处使用了 sudo ,所以要把zabbix用户加上sudo权限,且只能执行 ss命令echo 'zabbix ALL=(ALL) NOPASSWD:/usr/sbin/ss'>>/etc/sudoers修改ss_get_mysql_stats.php脚本$mysql_user = 'zabbix'; <=====此为php登录mysql的用户$mysql_pass = 123456; <=====此为php登录mysql的密码$mysql_port = NULL; <=====端口和socket要改为NULL$mysql_socket = NULL;修改userparameter_percona_mysql.conf 配置文件把每行中的逗号',' 替换为[*],sed -in 's#,#[*],#g' userparameter_percona_mysql.conf在每行后面添加 $1sed -in 's#$#$1#g' userparameter_percona_mysql.conf最后在首行添加端口自动发现脚本sed -in '1i UserParameter=MySQL.discovery,/bin/bash /var/lib/zabbix/percona/scripts/mysql_low_discovery.sh' userparameter_percona_mysql.conf6、复制脚本文件并执行权限mkdir -p /var/lib/zabbix/percona/scripts/cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/cp get_mysql_stats_wrapper.sh /var/lib/zabbix/percona/scripts/cp mysql_low_discovery.sh /var/lib/zabbix/percona/scripts/cp ss_get_mysql_stats.php /var/lib/zabbix/percona/scripts/chmod 700 /var/lib/zabbix/percona/scripts/*chown -R zabbix. /var/lib/zabbix/7、最后一定要在所有的库上面做授权操作,否则拿不到监控数据GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT ON *.* TO 'zabbix'@'localhost' identified by '123456';flush privileges;8、最后把模板Mysql_Multiport.xml导入到zabbix-server内,所有用到的脚本文件都已经添加到附件中,大家可以下载使用。创建触发器原型在zabbix-server端,添加触发器依次点击 主机===>自动发现===>触发器类型===>点击右上角的创建触发器原型分配报警级别,点击表达式栏的添加,选择选择原型然后选择 例如:MySQL.slave-stopped[{#MYSQLPORT}]选择最新的T值小于NN为0注:如果在第4.4中指定的是cat $CACHEFILE | sed 's/ /\n/g; s/-1/1/g'| grep $ITEM | awk -F: '{print $2}'选择最新的T值等于NN为1然后我们可以手动停止主从复制,稍等片刻,就会发了报警信息博客园不允许放附件,所以我只能把附件放在百度云了http://pan.baidu.com/s/1slFGVoT参考文章:https://github.com/hc-dba/Mysql_Multiport_monitor_used_zabbix另外可以添加微信和邮件告警,这里推荐下面的博文############sample 监控单节点多实例的mysql1.多实例
1台server 多个实例(即这些实例都绑定到同一个机器ip和不同端口)的问题,主要体现在采集端 需要适配多个server 进程
多个实例的监控用户和密码必须保持一致
在这个例子里
Ip 为10.241.94.15
Port 为 3306 和 3307
(以下修改是基于单实例监控的脚本进行更改的)
1.1.-> zabbix 脚本文件 get_mysql_stats_wrapper.sh
12 行加入
PORT=$2
13 行 host 修改localhost为IP
HOST=”10.241.94.15”
15 行更改为 加入 --port $PORT
CMD="/usr/bin/php -q $DIR/ss_get_mysql_stats.php --host $HOST --items gg --port $PORT"
16行修改为:
将 CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt”
修改为
if [ $PORT == 3306 ];then
CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt"
else
CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt":$PORT
fi
如下2行修改为 加入-P$PORT
RES=`HOME=~zabbix /db/mysql/app/mysql/bin/mysql -uuseropr -puseroprommo11 -P$PORT -e 'SHOW SLAVE STATUS\G' 2>/dev/null | egrep '(Slave_IO_Running|Slave_SQL_Running):' | grep -i yes|wc -l`
RES1=`HOME=~zabbix /db/mysql/app/mysql/bin/mysql -uuseropr -puseroprommo11 -P$PORT -e 'SHOW SLAVE STATUS\G' 2>/dev/null | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
1.2 用户授权
(如下4个授权grant 命令都需要执行,一台服务器多个实例 监控 需要允许 监控账号远程登陆)
> GRANT PROCESS,SUPER,REPLICATION CLIENT ON *.* TO zabbix@'localhost' IDENTIFIED BY '123456';
> grant all privileges on *.* to zabbix@localhost;
> grant all privileges on *.* to zabbix@'%' identified by "123456";
> grant PROCESS,SUPER,REPLICATION CLIENT on *.* to zabbix@'%' identified by "123456";
> flush privileges;
--查询权限:
> select user,host from mysql.user;
>SELECT Repl_slave_priv,Repl_client_priv,super_priv,host FROM mysql.USER WHERE USER='zabbix ';
> quit;
测试5.1
(使用如下带IP,端口,用户名,密码的登陆方式必须成功 )
mysql -uroot –p123456 -h10.241.94.15 –P3307
mysql -uroot -p123456 -h10.241.94.15 -P3306
测试5.2:
(3306 和3307 分别对应着一台主机多个mysql 对外提供服务的 端口号,具体以实际为主,如下命令应该有数字返就是正常),
sh get_mysql_stats_wrapper.sh gg 3306
sh get_mysql_stats_wrapper.sh gg 3307
如果返回值为空的话,使用-x 进行调试:
sh –x get_mysql_stats_wrapper.sh gg 3306
2. zabbix 自动发现脚本文件mysql_low_discovery.sh
2.1 cp mysql_low_discovery.sh /var/lib/zabbix/percona/scripts/
chmod 755 /var/lib/zabbix/percona/scripts/*
2.2
(Use root) 注意:由于此处使用了 sudo ,所以要把zabbix用户加上sudo权限,且只能执行 ss命令
echo 'zabbix ALL=(ALL) NOPASSWD:/usr/sbin/ss'>>/etc/sudoers
echo 'zabbix ALL=(ALL) NOPASSWD:/bin/netstat'>>/etc/sudoers
3. 修改ss_get_mysql_stats.php脚本
<=====端口和socket要改为NULL
$mysql_port = NULL;
$mysql_socket = NULL;
测试5.3
以下2条命令应该返回 数值
php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host 10.241.94.15 --items gg --port 3306
php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host 10.241.94.15 --items gg --port 3307
4. 修改userparameter_percona_mysql.conf 配置文件
4.1 把每行中的逗号',' 替换为[*],
sed -in 's#,#[*],#g' userparameter_percona_mysql.conf
4.2 在每行后面添加 $1
sed -in 's#$# $1#g' userparameter_percona_mysql.conf
4.3 最后在 首行添加端口自动发现脚本 (以下为一行)
sed -in '1i UserParameter=MySQL.discovery,/bin/bash /var/lib/zabbix/percona/scripts/mysql_low_discovery.sh' userparameter_percona_mysql.conf
验证结果如下:
cat userparameter_percona_mysql.conf
测试6:zabbix 用户下执行mysql_low_discovery.sh
返回结果应该如下端口号,那就是正常:
测试7
(该测试是在zabbix server上做,等待5分钟,进行测试,返回结果应该出现 端口号 就是正确)
cd /usr/local/zabbix/bin/
->Server:
./zabbix_get -s 10.241.94.15 -k MySQL.discovery
Issue :
有的时候,在 网页端 主机监控 ,自动发现里 的 percona 多实例模板 会报错 监控出现 unsupported key 报错
解决方法:
1.确认4.3 已经做,并且测试7 通过
2.然后重启zabbix agent
pkill zabbix
/usr/local/zabbix/sbin/*
3.一般10分钟,zabbix 才会重新检测 unsupported key 的定义
(实际情况,过了将近20分钟,unsupported key的报错才会取消)
-> Administration/General/通过右上角下拉框选择不同的项目完成相关配置和管理。
-> 如下图2-36所示。
5.导入模板
5.1 Zabbix 管理网页 模板 导入功能 (Mysql_Multiport.xml)
确认是否导入成功
1.显示已成功导入
2. 自动发现规则如下
注意: 所有的监控项目 都在自动发现规则 下
5.2 将主机 链接到这个新模板
Mysql_Multiport
注意:如果原有的主机已经添加了mysql 单机监控模板,
需要在网页端 删除掉原来的主机。 在重新添加 新加的监控模板(template/percona multiport template) 即可
附件:
mysql_low_discovery.sh
Mysql_Multiport
####sample
监控单节点单实例
-〉1配置agent 配置
rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm
Scripts are installed to /var/lib/zabbix/percona/scripts
Templates are installed to /var/lib/zabbix/percona/templates
yum install percona-zabbix-templates php php-mysql -y
Installed:
php.x86_64 0:5.3.3-47.el6 php-mysql.x86_64 0:5.3.3-47.el6
Dependency Installed:
php-cli.x86_64 0:5.3.3-47.el6 php-common.x86_64 0:5.3.3-47.el6
php-pdo.x86_64 0:5.3.3-47.el6
Complete!
[root@devops-mysql-node1 ~]# rpm -ql percona-zabbix-templates
/var/lib/zabbix/percona
/var/lib/zabbix/percona/scripts
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
/var/lib/zabbix/percona/templates
/var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf
/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml 为MYSQL监控模板
-〉zabbix配置文件
将配置文件拷贝到/etc/zabbix/zabbix_agentd.d/目录
cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf
/usr/local/zabbix/etc/zabbix_agentd.conf.d/
More /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_percona_mysql.conf
(这里是支持扩展的脚本位置)
Useparameter=Mysql.rows-updated,****/get_mysql_stats_wrapper.sh ix
**
(Ensure zabbix_agentd.conf contains the line: Include=/etc/zabbix_agentd.conf.d/ )
->2。建立本地用户
(如下2个授权grant 命令都需要执行)
> GRANT PROCESS,SUPER,REPLICATION CLIENT ON *.* TO zabbix@'localhost' IDENTIFIED BY '123456';
> grant all privileges on *.* to zabbix@localhost;
> flush privileges;
> select user,host from mysql.user;
> quit;
-〉3。zabbix 脚本文件 ss_get_mysql_stats.php
(重要,测试mysql 联通性 ,配置项目 使用用户/密码/本地socket连接)
1).vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'root';
$mysql_pass = '123456';
$mysql_port = 3306;
$mysql_socket = '/db/mysql/data/mysqltmp/mysql.sock';
$mysql_flags = 0;
测试环境root密码为空,如果生产环境会创建专门只读账号。
2).同时注意:/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
以下参数定义缓存文件的具体位置
(如果port变量定义一个非默认的3306 端口,就会往/tmp 写入一个文件 t-mysql_cacti_stats.txt:$port)
$cache_file = "$cache_dir/$sanitized_host-mysql_cacti_stats.txt" . ($port != 3306 ? ":$port" : '');
注意:
测试1:(zabzabbix 用户下)
如果 密码 配置错误,
/usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host localhost --items gg
会出现如下报错 :
root@centos6 ~]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
ERROR: run the command manually to investigate the problem: /usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host localhost --items gg
[root@centos6 ~]# /usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host localhost --items gg
ERROR: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)[root@centos6 ~]#
如果连接失败,可以使用如下PHP 测试下
#######
<?php
$i = 10000;
$host= 'localhost';
$user = 'dbmonopr';
$pass = 'dbmonoprommo11';
$port = 3307;
$socket = '/db/mysql/data/mysqltmp/mysql.sock';
$flags = 0;
while($i>=0) {
$conn = mysqli_init();
$link =mysqli_real_connect($conn, $host, $user, $pass, NULL, $port, $socket, $flags) or die(mysqli_connect_error());
$info = mysqli_get_host_info($conn);
$i--;
mysqli_close($conn);
unset($conn);
}
?>
###
4.-> zabbix 脚本文件 get_mysql_stats_wrapper.sh
(如果mysql 端口 不是3306,而是3503。这个也需要修改)
修改1:第15行,如果是默认端口,不需要修改这一项,如果不是默认端口
change
CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt"
to
CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt:3503"
修改2: 第19行 到25行,变量里加入“mysql 的绝对路径”和“用户和密码” 和 “2〉/dev/null”
change
19 行 到 25行修改如下:
to
RES=`HOME=~zabbix /db/mysql/app/mysql/bin/mysql -uuser-pdbmonoprommo11 -e 'SHOW SLAVE STATUS\G' 2>/dev/null | egrep '(Slave_IO_Running|Slave_SQL_Running):' | grep -i yes|wc -l`
if [ "$RES" -ne 2 ]; then
echo 1
else
RES1=`HOME=~zabbix /db/mysql/app/mysql/bin/mysql -uuser-pdbmonoprommo11 -e 'SHOW SLAVE STATUS\G' 2>/dev/null | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
if [ "$RES1" = " Yes, Yes," ]; then
echo 1
else
echo 0
fi
fi
exit
测试2:(root 用户下)
sudo -u zabbix -H /usr/local/zabbix/bin/get_mysql_stats_wrapper.sh running-slave
0
(正常情况下,应该返回0或者1,而不是“Access denied” 报错 )
/usr/local/zabbix/bin/get_mysql_stats_wrapper.sh running-slave
0
(正常情况下,应该返回0或者1,而不是“Access denied” 报错 )
需要改配置文件需要重启
/etc/init.d/zabbix-agent restart
或者
pkill zabbix
/usr/local/zabbix/sbin/*
测试3:(zabzabbix 用户下)
进行测试会返回测试结果
cd /var/lib/zabbix/percona/scripts/
./get_mysql_stats_wrapper.sh gm
0
./get_mysql_stats_wrapper.sh gw
20060
3.打开 Debug (zabbix 用户下修改ss_get_mysql_stats.php,确保/tmp/1.log zabbix 用户有写的权限)
ss_get_mysql_stats.php
$debug = true;
$debug_log = '/tmp/1.log';
关闭debug
$debug = FALSE; # Define whether you want debugging behavior.
$debug_log = FALSE; # If $debug_log is a filename, it'll be used.
ss_get_mysql_stats.php 解读:
-〉首先判断语法 是否正确
ss_get_mysql_stats.php --host localhost --items gg
-〉 其次 语法正确,就会在输出 runquery SHOW /*!50000 ENGINE*/ INNODB STATUS,
'SHOW /*!50002 GLOBAL */ STATUS'
-> 其次判断 如果cache_file 超过300秒,就会删除,重写一遍,如果不超过300秒,就不重写一遍。
->最后 如果有写的权限,就会写入一个临时文件 类似 localhost-mysql_cacti_stats.txt.port
转 zabbix debug and zabbix使用percona插件监控mysql的更多相关文章
- zabbix通过percona插件监控mysql
percona zabbix mysql-plugin是percona发布的一个使用zabbix监控mysql数据库的工具,这款工具比zabbix自带的监控模板要强大的多,毕竟percona是Mysq ...
- zabbix使用percona插件监控mysql
1.添加percona仓库. # yum install -y http://www.percona.com/downloads/percona-release/redhat/0.1-4/percon ...
- zabbix4.2学习笔记--安装percona插件监控MySQL
percona-monitoring-plugins是percona专门为MySQL监控的工具,支持Nagios,cacti,zabibx,本文主要介绍percona-monitoring-plugi ...
- 011-通过安装percona插件监控MySQL
percona-monitoring-plugins是percona专门为MySQL监控的工具,支持Nagios,cacti,zabibx,本文主要介绍percona-monitoring-plugi ...
- 使用Percona监控插件监控MySQL
1.使用Percona监控插件监控MySQL yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/per ...
- 总zabbix配置-搭建-邮件报警-微信报警-监控mysql
Centos7安装Zabbix4.0步骤 官方搭建zabbix4.0的环境要求: 1. 环境搭建LAMP 前提Centos系统安装完成: 确认一下: 1 2 cat /etc/redhat-rele ...
- 天兔插件监控mysql
Lepus3.8-天兔mysql数据库监控系统搭建 原创ixhao2016-08-24 02:36:23评论(11)3183人阅读 Lepus3.8-天兔mysql数据库监控系统搭建 lepus是一款 ...
- OEM12C(12.1.0.5)安装插件监控mysql(linux)
目录结构: 文章参考论坛:https://blog.csdn.net/u010719917/article/details/78128200 环境说明: oms:12.1.0.5 os:centos ...
- 分布式监控系统Zabbix--完整安装记录(7)-使用percona监控MySQL
前面已经介绍了分布式监控系统Zabbix-3.0.3-完整安装记录(2)-添加mysql监控,但是没有提供可以直接使用的Key,太过简陋,监控效果不佳.要想更加仔细的监控Mysql,业内同学们都会选择 ...
随机推荐
- svn checkout不带根文件夹方法
checkout url/ .url后边加一个空格一个点(英文句号) svn checkout svn://10.177.261.128/mall/ .
- CVE-2019-0708:RDP终极EXP复现
0x00 前言 每次复现都会遇到各种各样的问题,这次也不例外,经过多次尝试才复现成功,因此把可能的解决方法也和大家分享一下,有想要一起复现学习/投稿的可以联系我哈 0x01 影响版本 Windows ...
- Echo团队Alpha冲刺随笔 - 第十天
项目冲刺情况 进展 对Web端和小程序端进行各项功能的测试 问题 bug无穷无尽 心得 debug使人秃头,希望明天能挑好 今日会议内容 黄少勇 今日进展 测试小程序,对发现的bug进行处理 存在问题 ...
- Appache Flume 中文介绍(转)
Flume 是什么 Apache Flume是一个高可靠.高可用的分布式的海量日志收集.聚合.传输系统.它可以从不同的日志源采集数据并集中存储. Flume也算是Hadoop生态系统的一 ...
- django-获取购物车商品数量-redis
视图函数views.py中 from django_redis import get_redis_connection # 连接redis class IndexView(View): '''首页'' ...
- Windows10安装Redis过程
下载 Redis下载地址:https://github.com/microsoftarchive/redis/releases 以3.2.100版本为例,下载Redis-x64-3.2.100.zip ...
- LeetCode 731. My Calendar II
原题链接在这里:https://leetcode.com/problems/my-calendar-ii/ 题目: Implement a MyCalendarTwo class to store y ...
- shell随机数比较
#!/bin/bash a=$(expr $RANDOM % ) #生成一到一百的随机数 echo $a #打印随机数 b= while true do let b++ echo "比较了第 ...
- LOJ P10002 喷水装置 题解
每日一题 day35 打卡 Analysis 先将不符合条件的区间去掉(即半径小于W,不然宽度无法符合),将符合条件的按区间存入节点中.区间的左边界是x-sqrt(r*r-W*W/4.0),要计算x轴 ...
- Windbg命令脚本流程控制语句详解
在Windbg命令脚本一文里,我们介绍了命令脚本语言的的组成要素,在本文里将对语句进行展开的讲解.这些语句主要是流程控制的语句,比如我们常见的条件分子和循环语句等. ; (命令分隔符) 分号(:)字符 ...