當前位置:首頁 » 編程語言 » 慢sql監控zabbix
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

慢sql監控zabbix

發布時間: 2022-09-09 03:05:57

❶ 如何從Zabbix資料庫中獲取監控數據

Zabbix可以通過兩種方式獲取歷史數據:
1.通過Zabbix前台獲取歷史數據
通過Zabbix前台查看歷史數據非常簡單,可以通過Monitoring->Lastest data的方式查看。也可以點擊右上角的As plain test按鈕保存成文本文件。

2.通過前台獲取的數據進行處理和二次查詢有很多限制,因此可以通過sql語句直接從後台DB查詢數據。
首先大家應該熟悉SQL語句Select 常用用法:
SELECT [ALL | DISTINCT] Select_List [INTO [New_Table_name]
FROM { Table_name | View_name} [ [,{table2_name | view2_name}
[,...] ]
[ WHERE Serch_conditions ]
[ GROUP BY Group_by_list ]
[ HAVING Serch_conditions ]
[ ORDER BY Order_list [ASC| DEsC] ]

說明:
1)SELECT子句指定要查詢的特定表中的列,它可以是*,表達式,列表等。
2)INTO子句指定要生成新的表。
3)FROM子句指定要查詢的表或者視圖。
4)WHERE子句用來限定查詢的范圍和條件。
5)GROUP BY子句指定分組查詢子句。
6)HAVING子句用於指定分組子句的條件。
7)ORDER BY可以根據一個或者多個列來排序查詢結果,在該子句中,既可以使用列名,也可以使用相對列號,ASC表示升序,DESC表示降序。
8)mysql聚合函數:sum(),count(),avg(),max(),avg()等都是聚合函數,當我們在用聚合函數的時候,一般都要用到GROUP BY 先進行分組,然後再進行聚合函數的運算。運算完後就要用到Having子句進行判斷了,例如聚合函數的值是否大於某一個值等等。
從Zabbix資料庫中查詢監控項目方法,這里已查詢主機的網卡流量為例子:
1)通過hosts表查找host的ID。
mysql> select host,hostid from hosts where host="WWW05";
+-------+--------+
| host | hostid |
+-------+--------+
| WWW05 | 10534 |
+-------+--------+
1 row in set (0.00 sec)

2)通過items表查找主的監控項和key以及itemid。
mysql> select itemid,name,key_ from items where hostid=10534 and key_="net.if.out[eth0]";
+--------+-----------------+------------------+
| itemid | name | key_ |
+--------+-----------------+------------------+
| 58860 | 發送流量: | net.if.out[eth0] |
+--------+-----------------+------------------+
1 row in set (0.00 sec)

3)通過itemid查詢主機的監控項目(history_uint或者trends_uint),單位為M。
主機流入流量:
mysql> select from_unixtime(clock) as DateTime,round(value/1024/1024,2) as Traffic_in from history_uint where itemid="58855" and from_unixtime(clock)>='2014-09-20' and from_unixtime(clock)<'2014-09-21' limit 20;
+---------------------+------------+
| DateTime | Traffic_in |
+---------------------+------------+
| 2014-09-20 00:00:55 | 0.10 |
| 2014-09-20 00:01:55 | 0.09 |
| 2014-09-20 00:02:55 | 0.07 |
| 2014-09-20 00:03:55 | 0.05 |
| 2014-09-20 00:04:55 | 0.03 |
| 2014-09-20 00:05:55 | 0.06 |
| 2014-09-20 00:06:55 | 0.12 |
| 2014-09-20 00:07:55 | 0.05 |
| 2014-09-20 00:08:55 | 0.10 |
| 2014-09-20 00:09:55 | 0.10 |
| 2014-09-20 00:10:55 | 0.12 |
| 2014-09-20 00:11:55 | 0.12 |
| 2014-09-20 00:12:55 | 0.13 |
| 2014-09-20 00:13:55 | 3.16 |
| 2014-09-20 00:14:55 | 0.23 |
| 2014-09-20 00:15:55 | 0.24 |
| 2014-09-20 00:16:55 | 0.26 |
| 2014-09-20 00:17:55 | 0.23 |
| 2014-09-20 00:18:55 | 0.14 |
| 2014-09-20 00:19:55 | 0.16 |
+---------------------+------------+
20 rows in set (0.82 sec)

主機流出流量:
mysql> select from_unixtime(clock) as DateTime,round(value/1024/1024,2) as Traffic_out from history_uint where itemid="58860" and from_unixtime(clock)>='2014-09-20' and from_unixtime(clock)<'2014-09-21' limit 20;
+---------------------+-------------+
| DateTime | Traffic_out |
+---------------------+-------------+
| 2014-09-20 00:00:00 | 4.13 |
| 2014-09-20 00:01:00 | 3.21 |
| 2014-09-20 00:02:00 | 2.18 |
| 2014-09-20 00:03:01 | 1.61 |
| 2014-09-20 00:04:00 | 1.07 |
| 2014-09-20 00:05:00 | 0.92 |
| 2014-09-20 00:06:00 | 1.23 |
| 2014-09-20 00:07:00 | 2.76 |
| 2014-09-20 00:08:00 | 1.35 |
| 2014-09-20 00:09:00 | 3.11 |
| 2014-09-20 00:10:00 | 2.99 |
| 2014-09-20 00:11:00 | 2.68 |
| 2014-09-20 00:12:00 | 2.55 |
| 2014-09-20 00:13:00 | 2.89 |
| 2014-09-20 00:14:00 | 4.98 |
| 2014-09-20 00:15:00 | 6.56 |
| 2014-09-20 00:16:00 | 7.34 |
| 2014-09-20 00:17:00 | 6.81 |
| 2014-09-20 00:18:00 | 7.67 |
| 2014-09-20 00:19:00 | 4.11 |
+---------------------+-------------+
20 rows in set (0.74 sec)

4)如果是兩台設備,匯總流量,假如公司出口有兩台設備,可以用下面的SQL語句匯總每天的流量。下面SQL語句是匯總上面主機網卡的進出流量的。
mysql> select from_unixtime(clock,"%Y-%m-%d %H:%i") as DateTime,sum(round(value/1024/1024,2)) as Traffic_total from history_uint where itemid in (58855,58860) and from_unixtime(clock)>='2014-09-20'and from_unixtime(clock)<'2014-09-21' group by from_unixtime(clock,"%Y-%m-%d %H:%i") limit 20;
+------------------+---------------+
| DateTime | Traffic_total |
+------------------+---------------+
| 2014-09-20 00:00 | 4.23 |
| 2014-09-20 00:01 | 3.30 |
| 2014-09-20 00:02 | 2.25 |
| 2014-09-20 00:03 | 1.66 |
| 2014-09-20 00:04 | 1.10 |
| 2014-09-20 00:05 | 0.98 |
| 2014-09-20 00:06 | 1.35 |
| 2014-09-20 00:07 | 2.81 |
| 2014-09-20 00:08 | 1.45 |
| 2014-09-20 00:09 | 3.21 |
| 2014-09-20 00:10 | 3.11 |
| 2014-09-20 00:11 | 2.80 |
| 2014-09-20 00:12 | 2.68 |
| 2014-09-20 00:13 | 6.05 |
| 2014-09-20 00:14 | 5.21 |
| 2014-09-20 00:15 | 6.80 |
| 2014-09-20 00:16 | 7.60 |
| 2014-09-20 00:17 | 7.04 |
| 2014-09-20 00:18 | 7.81 |
| 2014-09-20 00:19 | 4.27 |
+------------------+---------------+
20 rows in set (1.52 sec)

5)查詢一天中主機流量的最大值,最小值和平均值。
mysql> select date as DateTime,round(min(traffic)/2014/1024,2) as TotalMinIN,round(avg(traffic)/1024/1024,2) as TotalAvgIN,round(max(traffic)/1024/1024,2) as TotalMaxIN from (select from_unixtime(clock,"%Y-%m-%d") as date,sum(value) as traffic from history_uint where itemid in (58855,58860) and from_unixtime(clock)>='2014-09-20' and from_unixtime(clock)<'2014-09-21' group by from_unixtime(clock,"%Y-%m-%d %H:%i") ) tmp;
+------------+------------+------------+------------+
| DateTime | TotalMinIN | TotalAvgIN | TotalMaxIN |
+------------+------------+------------+------------+
| 2014-09-20 | 0.01 | 4.63 | 191.30 |
+------------+------------+------------+------------+
1 row in set (1.74 sec)

6)查詢主機組裡面所有主機CPU Idle平均值(原始值)。
mysql> select from_unixtime(hi.clock,"%Y-%m-%d %H:%i") as DateTime,g.name as Group_Name,h.host as Host, hi.value as Cpu_Avg_Idle from hosts_groups hg join groups g on g.groupid = hg.groupid join items i on hg.hostid = i.hostid join hosts h on h.hostid=i.hostid join history hi on i.itemid = hi.itemid where g.name='上海機房--項目測試' and i.key_='system.cpu.util[,idle]' and from_unixtime(clock)>='2014-09-24' and from_unixtime(clock)<'2014-09-25' group by h.host,from_unixtime(hi.clock,"%Y-%m-%d %H:%i") limit 10;
+------------------+----------------------------+----------+--------------+
| DateTime | Group_Name | Host | Cpu_Avg_Idle |
+------------------+----------------------------+----------+--------------+
| 2014-09-24 00:02 | 上海機房--項目測試 | testwb01 | 94.3960 |
| 2014-09-24 00:07 | 上海機房--項目測試 | testwb01 | 95.2086 |
| 2014-09-24 00:12 | 上海機房--項目測試 | testwb01 | 95.4308 |
| 2014-09-24 00:17 | 上海機房--項目測試 | testwe01 | 95.4580 |
| 2014-09-24 00:22 | 上海機房--項目測試 | testwb01 | 95.4611 |
| 2014-09-24 00:27 | 上海機房--項目測試 | testwb01 | 95.2939 |
| 2014-09-24 00:32 | 上海機房--項目測試 | testwb01 | 96.0896 |
| 2014-09-24 00:37 | 上海機房--項目測試 | testwb01 | 96.5286 |
| 2014-09-24 00:42 | 上海機房--項目測試 | testwb01 | 96.8086 |
| 2014-09-24 00:47 | 上海機房--項目測試 | testwb01 | 96.6854 |
+------------------+----------------------------+----------+--------------+
10 rows in set (0.75 sec)

7)查詢主機組裡面所有主機 CPU Idle平均值(匯總值)。
mysql> select from_unixtime(hi.clock,"%Y-%m-%d %H:%i") as Date,g.name as Group_Name,h.host as Host, hi.value_avg as Cpu_Avg_Idle from hosts_groups hg join groups g on g.groupid = hg.groupid join items i on hg.hostid = i.hostid join hosts h on h.hostid=i.hostid join trends hi on i.itemid = hi.itemid where g.name='上海機房--項目測試' and i.key_='system.cpu.util[,idle]' and from_unixtime(clock)>='2014-09-10' and from_unixtime(clock)<'2014-09-11' group by h.host,from_unixtime(hi.clock,"%Y-%m-%d %H:%i") limit 10;
+------------------+----------------------------+----------+--------------+
| Date | Group_Name | Host | Cpu_Avg_Idle |
+------------------+----------------------------+----------+--------------+
| 2014-09-10 00:00 | 上海機房--項目測試 | testwb01 | 99.9826 |
| 2014-09-10 01:00 | 上海機房--項目測試 | testwb01 | 99.9826 |
| 2014-09-10 02:00 | 上海機房--項目測試 | testwb01 | 99.9825 |
| 2014-09-10 03:00 | 上海機房--項目測試 | testwb01 | 99.9751 |
| 2014-09-10 04:00 | 上海機房--項目測試 | testwb01 | 99.9843 |
| 2014-09-10 05:00 | 上海機房--項目測試 | testwb01 | 99.9831 |
| 2014-09-10 06:00 | 上海機房--項目測試 | testwb01 | 99.9829 |
| 2014-09-10 07:00 | 上海機房--項目測試 | testwb01 | 99.9843 |
| 2014-09-10 08:00 | 上海機房--項目測試 | testwb01 | 99.9849 |
| 2014-09-10 09:00 | 上海機房--項目測試 | testwb01 | 99.9849 |
+------------------+----------------------------+----------+--------------+
10 rows in set (0.01 sec)

8)其它與Zabbix相關的SQL語句。
查詢主機已經添加但沒有開啟監控主機:
select host from hosts where status=1;

查詢NVPS的值:
mysql> SELECT round(SUM(1.0/i.delay),2) AS qps FROM items i,hosts h WHERE i.status='0' AND i.hostid=h.hostid AND h.status='0' AND i.delay<>0;
+--------+
| qps |
+--------+
| 503.40 |
+--------+
1 row in set (0.11 sec)

望採納

❷ zabbix 如何監控 mysql 主從同步 延遲差多少時間

正值 - 表示主從已經出現延時.
0 - 該值為零,是我們極為渴望看到的情況,也就是該線程的Running狀態是No,這是一個BUG值,該參數是不支持負值的可以通過監控show slave status\G命令輸出的Seconds_Behind_Master參數的值來判斷,表示主從復制良好,可以認為lag不存在,是否有發生主從延時。
其值有這么幾種,數字越大表示從庫落後主庫越多。
負值 - 幾乎很少見:
NULL - 表示io_thread或是sql_thread有任何一個發生故障,而非Yes,只是聽一些資深的DBA說見過,其實

❸ zabbix的作用是什麼,怎麼監控

zabbix是一個基於WEB界面的提供分布式系統監視以及網

絡監視功能的企業級的開源解決方案。

zabbix能監視各種網路參數,保證伺服器系統的安全運營;並提供靈活的通知機制以讓系統管理員快速定位/解決存在的各種問題。

zabbix由2部分構成,zabbix server與可選組件zabbix agent。

zabbix server可以通過SNMP,zabbix agent,ping,埠監視等方法提供對遠程伺服器/網路狀態的監視,數據收集等功能,它可以運行在Linux, Solaris, HP-UX, AIX, Free BSD, Open BSD, OS X等平台上。

zabbix agent需要安裝在被監視的目標伺服器上,它主要完成對硬體信息或與操作系統有關的內存,CPU等信息的收集。zabbix agent可以運行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD, OS X, Tru64/OSF1, Windows NT4.0, Windows (2000/2003/XP/Vista)等系統之上。

zabbix server可以單獨監視遠程伺服器的服務狀態;同時也可以與zabbix agent配合,可以輪詢zabbix agent主動接收監視數據(agent方式),同時還可被動接收zabbix agent發送的數據(trapping方式)。

另外zabbix server還支持SNMP (v1,v2),可以與SNMP軟體(例如:net-snmp)等配合使用。[1]
2特點
zabbix的主要特點:

- 安裝與配置簡單,學習成本低

- 支持多語言(包括中文)

- 免費開源

- 自動發現伺服器與網路設備

- 分布式監視以及WEB集中管理功能

- 可以無agent監視

- 用戶安全認證和柔軟的授權方式

- 通過WEB界面設置或查看監視結果

- email等通知功能

等等

Zabbix主要功能:

- CPU負荷

- 內存使用

-磁碟使用

- 網路狀況

- 埠監視
- 日誌監視。[1]

❹ 如何從zabbix監控mysql

有兩種方法,一種方法使用mysql的check table和repair table 的sql語句,另一種方法是使用MySQL提供的多個myisamchk, isamchk數據檢測恢復工具。前者使用起來比較簡便。推薦使用。 1. check table 和 repair table 登陸mysql 終端: mysql -uxxxxx -p dbname check table tabTest; 如果出現的結果說Status是OK,則不用修復,如果有Error,可以用: repair table tabTest; 進行修復,修復之後可以在用check table命令來進行檢查。在新版本的phpMyAdmin裡面也可以使用check/repair的功能。 2. myisamchk, isamchk 其中myisamchk適用於MYISAM類型的數據表,而isamchk適用於ISAM類型的數據表。這兩條命令的主要參數相同,一般新的系統都使用MYISAM作為預設的數據表類型,這里以myisamchk為例子進行說明。當發現某個數據表出現問題時可以使用: myisamchk tablename.MYI 進行檢測,如果需要修復的話,可以使用: myisamchk -of tablename.MYI 關於myisamchk的詳細參數說明,可以參見它的使用幫助。需要注意的時在進行修改時必須確保MySQL伺服器沒有訪問這個數據表,保險的情況下是最好在進行檢測時把MySQL伺服器Shutdown掉。

❺ 運維監控 zabbix可以做哪些監控

1、監控windows進程內存。在C盤中創建腳本a.bat,內容tasklist。

❻ 如何通過Zabbix獲取監控數據

歷史數據:history相關表,從history_uint表裡面可以查詢到設備監控項目的最大,最小和平均值,即存儲監控數據的原始數據。
趨勢數據:trends相關表,趨勢數據是經過Zabbix計算的數據,數據是從history_uint裡面匯總的,從trends_uint可以查看到監控數據每小時最大,最小和平均值,即存儲監控數據的匯總數據。
Zabbix可以通過兩種方式獲取歷史數據:
1.通過Zabbix前台獲取歷史數據
通過Zabbix前台查看歷史數據非常簡單,可以通過Monitoring->Lastest data的方式查看。也可以點擊右上角的As plain test按鈕保存成文本文件。
2.通過前台獲取的數據進行處理和二次查詢有很多限制,因此可以通過SQL語句直接從後台DB查詢數據。
首先大家應該熟悉SQL語句Select 常用用法:

SELECT [ALL | DISTINCT] Select_List [INTO [New_Table_name]
FROM { Table_name | View_name} [ [,{table2_name | view2_name}
[,…] ]
[ WHERE Serch_conditions ]
[ GROUP BY Group_by_list ]
[ HAVING Serch_conditions ]
[ ORDER BY Order_list [ASC| DEsC] ]
說明:
1)SELECT子句指定要查詢的特定表中的列,它可以是*,表達式,列表等。
2)INTO子句指定要生成新的表。
3)FROM子句指定要查詢的表或者視圖。
4)WHERE子句用來限定查詢的范圍和條件。
5)GROUP BY子句指定分組查詢子句。
6)HAVING子句用於指定分組子句的條件。
7)ORDER BY可以根據一個或者多個列來排序查詢結果,在該子句中,既可以使用列名,也可以使用相對列號,ASC表示升序,DESC表示降序。
8)mysql聚合函數:sum(),count(),avg(),max(),avg()等都是聚合函數,當我們在用聚合函數的時候,一般都要用到GROUP BY 先進行分組,然後再進行聚合函數的運算。運算完後就要用到Having子句進行判斷了,例如聚合函數的值是否大於某一個值等等。

❼ 請問zabbix如何通過iis監控sql server需要配置什麼

2.1 服務端環境准備
Zabbix Server需要運行在CentOS、RedHat Linux、Den等Linux系統上,這里以RHEL作為部署環境。
Root用戶安裝必須的包,建議配置好yum,通過yum安裝下列包,解決包的依賴關系。
LAMP環境
#yum install mysql-server (mysql可以單獨安裝高版本)
yum install httpd php
其他需要用到的包:
#yum install mysql-devel gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml
下載最新的Zabbix安裝包(官網:http://www.zabbix.com)到本地,解壓
#tar zxvf zabbix-2.4.7.tar.gz
增加zabbix用戶和組
#groupadd zabbix
# useradd -g zabbix -m zabbix
2.2 資料庫准備
啟動MySQL資料庫:
#service mysqld start
修改MySQL root用戶密碼(默認密碼為空)
# mysqladmin -uroot -p password root
測試能否正常登陸資料庫
#mysql –uroot –proot
創建Zabbix資料庫
Mysql> create database zabbix character set utf8;
導入資料庫sql腳本
#cd zabbix-2.4.7
# mysql -uroot -proot zabbix < database/mysql/schema.sql
# mysql -uroot -proot zabbix < database/mysql/images.sql
# mysql -uroot -proot zabbix < database/mysql/data.sql

2.3 編譯安裝
配置編譯,prefix是安裝後程序目錄
# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-unixodbc --with-libcurl -enable-proxy
# make install
2.4 配置文件及web前端文件修改
添加服務埠,添加後如下
# grep zabbix /etc/services
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper
添加配置文件
# mkdir -p /etc/zabbix
# cp conf/{zabbix_server.conf,zabbix_agentd.conf} /etc/zabbix
# chmod 400 /etc/zabbix/zabbix_server.conf
# chown zabbix /etc/zabbix/zabbix_server.conf
# chown -R zabbix:zabbix /etc/zabbix
修改Server配置文件
基本不用修改,用默認配置即可,只需修改一項DBPassword=密碼(此密碼是前面設置的資料庫密碼)
# vi /etc/zabbix/zabbix_server.conf
修改Agentd配置文件,更改HOST NAME 為本機的主機名
#vi /etc/zabbix/zabbix_agentd.conf
添加web前端php文件
# cd frontends/
# cp -rf php /var/www/html/
# cd /var/www/html
# mv php zabbix
# chown -R zabbix:zabbix zabbix
2.5 web前端安裝配置
修改php相關參數
# vi /etc/php.ini 找到如下幾項,改成下面的值,前面有;號的要刪掉
max_execution_time = 300
date.timezone = Asia/Shanghai
max_input_time = 600
post_max_size = 32M
memory_limit = 128M
mbstring.func_overload = 2
重啟apache
#service httpd restart
啟動zabbix_server
/etc/init.d/zabbix_server -c /etc/zabbix/zabbix_server.conf start

----------------------------------------------------------------------------------------unixODBC配置
4. MSSQL. The documentation is available on this page:
install necessary packages on Zabbix server:
# yum -y install freetds unixODBC unixODBC-devel
update ODBC driver configuration file:
$ vi /etc/odbcinst.ini
[FreeTDS]
Driver = /usr/lib64/libtdsodbc.so.0
update ODBC configuration file:
$ vi /etc/odbc.ini
[sql1] --為方便 這里最好用ip 表示,容易區分 和server ip 保持一致
Driver = FreeTDS
Server =
PORT = 1433
TDS_Version = 8.0
[sql2]
Driver = FreeTDS
Server =
PORT = 1433
TDS_Version = 8.0
isql -v sql1[sql2]
SQL> SELECT name FROM master..sysdatabases