說明此處配置針對的是zabbix3.0版本正則表達式
利用zabbix的自動發現(LLD)功能結合腳本能夠實現上面的需求,實現對IIS站點的動態添加,動態監控。express
效果圖:json
具體配置步驟:windows
一、 zabbix服務端配置服務器
配置過濾正則表達式:app
依次選擇Administration->General->Regular expressions。建立新的正則表達式「IISSite for discovery」,會在後面的模板中引用。正則表達式的名字不能有錯,不然導入模板報錯。ide
導入模塊性能
將內容拷貝到文本文件後綴名改成」.xml」,如:Template IIS Web Site3.0.xml 也能夠下載附件!測試
而後在WEB頁面分別選擇:配置è模版è導入,選擇編輯的文件TemplateIIS Web Site3.0.xml,提示導入成功就OK了flex
<?xmlversion="1.0" encoding="UTF-8"?> <zabbix_export> <version>3.0</version> <date>2016-09-22T03:55:42Z</date> <groups> <group> <name>Templates</name> </group> </groups> <templates> <template> <template>Template IIS WebSite</template> <name>Template IIS WebSite</name> <description/> <groups> <group> <name>Templates</name> </group> </groups> <applications> <application> <name>IIS WebSite</name> </application> </applications> <items/> <discovery_rules> <discovery_rule> <name>IIS Web Sitediscovery</name> <type>0</type> <snmp_community/> <snmp_oid/> <key>iis.site.discovery</key> <delay>600</delay> <status>0</status> <allowed_hosts/> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <delay_flex/> <params/> <ipmi_sensor/> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <filter> <evaltype>0</evaltype> <formula/> <conditions> <condition> <macro>{#WEB_SERVICE}</macro> <value>@IIS Site for discovery</value> <operator>8</operator> <formulaid>A</formulaid> </condition> </conditions> </filter> <lifetime>0</lifetime> <description/> <item_prototypes> <item_prototype> <name>{#WEB_SERVICE} Current Connections</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>perf_counter[\{#WEB_SERVICE}\Current Connections]</key> <delay>30</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units/> <delta>0</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>IIS Web Site</name> </application> </applications> <valuemap/> <logtimefmt/> <application_prototypes/> </item_prototype> <item_prototype> <name>{#WEB_SERVICE} Service Uptime</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>perf_counter[\{#WEB_SERVICE}\Service Uptime]</key> <delay>30</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units>s</units> <delta>0</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>IIS Web Site</name> </application> </applications> <valuemap/> <logtimefmt/> <application_prototypes/> </item_prototype> <item_prototype> <name>{#WEB_SERVICE} Bytes Received/sec</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>perf_counter[\{#WEB_SERVICE}\Total BytesReceived]</key> <delay>30</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>0</value_type> <allowed_hosts/> <units>B/s</units> <delta>1</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>IIS Web Site</name> </application> </applications> <valuemap/> <logtimefmt/> <application_prototypes/> </item_prototype> <item_prototype> <name>{#WEB_SERVICE} Bytes Sent/sec</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>perf_counter[\{#WEB_SERVICE}\Total Bytes Sent]</key> <delay>30</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>0</value_type> <allowed_hosts/> <units>B/s</units> <delta>1</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>IIS Web Site</name> </application> </applications> <valuemap/> <logtimefmt/> <application_prototypes/> </item_prototype> <item_prototype> <name>{#WEB_SERVICE} Bytes Total/sec</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>perf_counter[\{#WEB_SERVICE}\Total BytesTransferred]</key> <delay>30</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>0</value_type> <allowed_hosts/> <units>B/s</units> <delta>1</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>IIS Web Site</name> </application> </applications> <valuemap/> <logtimefmt/> <application_prototypes/> </item_prototype> <item_prototype> <name>{#WEB_SERVICE} Get Requests/sec</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>perf_counter[\{#WEB_SERVICE}\Total Get Requests]</key> <delay>30</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>0</value_type> <allowed_hosts/> <units>req/s</units> <delta>1</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>IIS WebSite</name> </application> </applications> <valuemap/> <logtimefmt/> <application_prototypes/> </item_prototype> <item_prototype> <name>{#WEB_SERVICE} Post Requests/sec</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>perf_counter[\{#WEB_SERVICE}\Total Post Requests]</key> <delay>30</delay> <history>90</history> <trends>365</trends> <status>0</status> <value_type>0</value_type> <allowed_hosts/> <units>req/s</units> <delta>1</delta> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>IIS Web Site</name> </application> </applications> <valuemap/> <logtimefmt/> <application_prototypes/> </item_prototype> </item_prototypes> <trigger_prototypes> <trigger_prototype> <expression>{Template IIS WebSite:perf_counter[\{#WEB_SERVICE}\ServiceUptime].change(0)}<0</expression> <name>{#WEB_SERVICE} on {HOST.NAME} has just beenrestarted</name> <url/> <status>0</status> <priority>2</priority> <description/> <type>0</type> <dependencies/> </trigger_prototype> </trigger_prototypes> <graph_prototypes> <graph_prototype> <name>{#WEB_SERVICE} Bytes/sec</name> <width>900</width> <height>200</height> <yaxismin>0.0000</yaxismin> <yaxismax>100.0000</yaxismax> <show_work_period>1</show_work_period> <show_triggers>1</show_triggers> <type>0</type> <show_legend>1</show_legend> <show_3d>0</show_3d> <percent_left>0.0000</percent_left> <percent_right>0.0000</percent_right> <ymin_type_1>0</ymin_type_1> <ymax_type_1>0</ymax_type_1> <ymin_item_1>0</ymin_item_1> <ymax_item_1>0</ymax_item_1> <graph_items> <graph_item> <sortorder>0</sortorder> <drawtype>0</drawtype> <color>C80000</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template IIS Web Site</host> <key>perf_counter[\{#WEB_SERVICE}\Total BytesTransferred]</key> </item> </graph_item> <graph_item> <sortorder>1</sortorder> <drawtype>0</drawtype> <color>00C800</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template IIS Web Site</host> <key>perf_counter[\{#WEB_SERVICE}\Total BytesReceived]</key> </item> </graph_item> <graph_item> <sortorder>2</sortorder> <drawtype>0</drawtype> <color>0000C8</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template IIS Web Site</host> <key>perf_counter[\{#WEB_SERVICE}\Total Bytes Sent]</key> </item> </graph_item> </graph_items> </graph_prototype> <graph_prototype> <name>{#WEB_SERVICE} Requests/sec</name> <width>900</width> <height>200</height> <yaxismin>0.0000</yaxismin> <yaxismax>100.0000</yaxismax> <show_work_period>1</show_work_period> <show_triggers>1</show_triggers> <type>0</type> <show_legend>1</show_legend> <show_3d>0</show_3d> <percent_left>0.0000</percent_left> <percent_right>0.0000</percent_right> <ymin_type_1>0</ymin_type_1> <ymax_type_1>0</ymax_type_1> <ymin_item_1>0</ymin_item_1> <ymax_item_1>0</ymax_item_1> <graph_items> <graph_item> <sortorder>0</sortorder> <drawtype>0</drawtype> <color>C80000</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template IIS Web Site</host> <key>perf_counter[\{#WEB_SERVICE}\Total Get Requests]</key> </item> </graph_item> <graph_item> <sortorder>1</sortorder> <drawtype>0</drawtype> <color>00C800</color> <yaxisside>0</yaxisside> <calc_fnc>2</calc_fnc> <type>0</type> <item> <host>Template IIS Web Site</host> <key>perf_counter[\{#WEB_SERVICE}\Total Post Requests]</key> </item> </graph_item> </graph_items> </graph_prototype> </graph_prototypes> <host_prototypes/> </discovery_rule> </discovery_rules> <macros/> <templates/> <screens/> </template> </templates> </zabbix_export>
查看模版內容:
監控項:
這裏使用了windows性能計數器來監控IIS站點各項指標。下面介紹下各監控項的含義:
{#WEB_SERVICE} Bytes Received/sec:IIS站點接收數據字節的速率
{#WEB_SERVICE} Bytes Sent/sec:IIS站點發送數據字節的速率
{#WEB_SERVICE} Bytes Total/sec:IIS站點的總傳輸數據字節的速率,是Received/sec和Sent/sec的和。
{#WEB_SERVICE} Get Requests/sec:IIS站點的GET請求速率
{#WEB_SERVICE} Post Requests/sec:IIS站點的POST請求速率
以上5個監控項是取的平均值,使監控數據更加準確、平滑。
{#WEB_SERVICE} Current Connections:當前與IIS站點創建鏈接的數量
{#WEB_SERVICE} Service Uptime:IIS站點的啓動時間
以上2個監控項是取的當前瞬時值。
觸發器:
{#WEB_SERVICE}on {HOST.NAME} has just been restarted:重啓IIS站點的報警
圖形:
{#WEB_SERVICE} Bytes/sec:數據傳輸速率圖形,包括數據接收速率、發送速率、總的速率。
{#WEB_SERVICE} Requests/sec:http請求速率圖形,包括GET請求速率和POST請求速率。
zabbix server會根據以上原型對發現出來的每個站點建立相應的監控項、觸發器、圖形。
二、zabbix客戶端配置
下面要在被監控的IIS服務器上作配置。
首先上傳IIS站點自動發現腳本LLD_Web_Service.bat到C盤根目錄。
腳本內容以下:
C:\ LLD_Web_Service.bat
@echo off SETLOCAL ENABLEDELAYEDEXPANSION echo { echo "data":[ for /F "tokens=* delims=" %%i IN ('typeperf -qx^|find "Web Service"^|find "CurrentConnections"') DO ( set j=%%i for /F "tokens=1 delims=\" %%k in("%%i") DO ( echo { echo "{#WEB_SERVICE}":"%%k" echo }, ) ) echo { echo "{#WEB_SERVICE}":"none" echo } echo ] echo }
而後修改zabbixagent的配置文件,增長自定義參數:
UnsafeUserParameters=1 #開啓用戶自定義腳本功能
UserParameter=iis.site.discovery,C:\LLD_Web_Service.bat #創建客戶機監控項
修改完畢重啓zabbix agent使配置生效。
在zabbix server服務器上測試下客戶端是否配置成功:使用zabbix_get命令獲取腳本執行結果,腳本返回一段json數據就算成功了:
將模版應用到主機,查看監控結果: