zabbix监控redis

本文介绍如何使用Zabbix监控Redis服务。首先导入监控模板并配置客户端key,然后重启服务并验证通信是否正常。接着添加主机关联模板并验证数据是否正确显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

导入监控模板

点击【configuration】——>【templates】——>【import】,导入xml监控模板。

配置客户端key

在被监控的主机上,新建/etc/zabbix/zabbix_agentd.d/userparameter_redis.conf配置文件,在最后一行加入:

UserParameter=redis_stats[*],redis-cli -h 127.0.0.1 -p $1 info|grep $2|cut -d : -f2

重启服务应用最新的配置文件

#注意确认zabbix_agentd.conf文件UnsafeUserParameters=1 
service zabbix-agent restart 

服务端验证

在zabbix服务器上通过zabbix_get程序获取数据,能正常得到数据,证明通信正常。

zabbix_get -s 172.20.0.20 -k redis_stats[6379,total_connections_received]
2249669

添加主机关联模板

通过【configuration】——>【hosts】——>【create host】创建新主机,并在templates项中,查找Templates Redis_6379模板,并link该模板。

验证数据使用【monitoring】——>【lastest data】,打开刚刚添加的主机,查看是否有数据。



redis监控模板

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
    <version>2.0</version>
    <date>2014-02-20T12:21:39Z</date>
    <groups>
        <group>
            <name>Templates</name>
        </group>
    </groups>
    <templates>
        <template>
            <template>Templates Redis_6379</template>
            <name>Templates Redis_6379</name>
            <groups>
                <group>
                    <name>Templates</name>
                </group>
            </groups>
            <applications>
                <application>
                    <name>Redis_6379</name>
                </application>
            </applications>
            <items>
                <item>
                    <name>Blocked clients_6379</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>redis_stats[6379,blocked_clients]</key>
                    <delay>60</delay>
                    <history>7</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authpassphrase/>
                    <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>Redis_6379</name>
                        </application>
                    </applications>
                    <valuemap/>
                </item>
                <item>
                    <name>Connected clients_6379</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>redis_stats[6379,connected_clients]</key>
                    <delay>60</delay>
                    <history>7</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authpassphrase/>
                    <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>Redis_6379</name>
                        </application>
                    </applications>
                    <valuemap/>
                </item>
                <item>
                    <name>Connected slave_6380</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>redis_stats[6379,connected_slave]</key>
                    <delay>60</delay>
                    <history>7</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authpassphrase/>
                    <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>Redis_6379</name>
                        </application>
                    </applications>
                    <valuemap/>
                </item>
                <item>
                    <name>Connection rate_6379</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>redis_stats[6379,total_connections_received]</key>
                    <delay>60</delay>
                    <history>7</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>1</delta>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authpassphrase/>
                    <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>Redis_6379</name>
                        </application>
                    </applications>
                    <valuemap/>
                </item>
                <item>
                    <name>Evicted_keys_6379</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>redis_stats[6379,evicted_keys]</key>
                    <delay>60</delay>
                    <history>7</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authpassphrase/>
                    <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>Redis_6379</name>
                        </application>
                    </applications>
                    <valuemap/>
                </item>
                <item>
                    <name>Expired keys_6379</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>redis_stats[6379,expired_keys]</key>
                    <delay>60</delay>
                    <history>7</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authpassphrase/>
                    <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>Redis_6379</name>
                        </application>
                    </applications>
                    <valuemap/>
                </item>
                <item>
                    <name>Last save time_6379</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>redis_stats[6379,last_save_time]</key>
                    <delay>60</delay>
                    <history>3</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units>unixtime</units>
                    <delta>0</delta>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authpassphrase/>
                    <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>Redis_6379</name>
                        </application>
                    </applications>
                    <valuemap/>
                </item>
                <item>
                    <name>port status_6379</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>net.tcp.listen[6379]</key>
                    <delay>60</delay>
                    <history>7</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authpassphrase/>
                    <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>Redis_6379</name>
                        </application>
                    </applications>
                    <valuemap/>
                </item>
                <item>
                    <name>Request rate_6379</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>redis_stats[6379,total_commands_processed]</key>
                    <delay>60</delay>
                    <history>7</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>1</delta>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authpassphrase/>
                    <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>Redis_6379</name>
                        </application>
                    </applications>
                    <valuemap/>
                </item>
                <item>
                    <name>Role_6379</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>redis_stats[6379,role]</key>
                    <delay>60</delay>
                    <history>3</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>1</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authpassphrase/>
                    <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>Redis_6379</name>
                        </application>
                    </applications>
                    <valuemap/>
                </item>
                <item>
                    <name>Uptime in seconds_6379</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>redis_stats[6379,uptime_in_seconds]</key>
                    <delay>60</delay>
                    <history>7</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units>uptime</units>
                    <delta>0</delta>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authpassphrase/>
                    <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>Redis_6379</name>
                        </application>
                    </applications>
                    <valuemap/>
                </item>
                <item>
                    <name>Used memory_6379</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>redis_stats[6379,used_memory:]</key>
                    <delay>60</delay>
                    <history>7</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authpassphrase/>
                    <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>Redis_6379</name>
                        </application>
                    </applications>
                    <valuemap/>
                </item>
                <item>
                    <name>Used_memory_rss_6379</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>redis_stats[6379,used_memory_rss]</key>
                    <delay>60</delay>
                    <history>7</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authpassphrase/>
                    <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>Redis_6379</name>
                        </application>
                    </applications>
                    <valuemap/>
                </item>
            </items>
            <discovery_rules/>
            <macros/>
            <templates/>
            <screens/>
        </template>
    </templates>
    <triggers>
        <trigger>
            <expression>{Templates Redis_6379:net.tcp.listen[6379].count(#3,0,&quot;eq&quot;)}=3</expression>
            <name>Redis port 6379 is not running</name>
            <url/>
            <status>0</status>
            <priority>4</priority>
            <description/>
            <type>0</type>
            <dependencies/>
        </trigger>
    </triggers>
    <graphs>
        <graph>
            <name>Redis key_6379</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>Templates Redis_6379</host>
                        <key>redis_stats[6379,evicted_keys]</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>Templates Redis_6379</host>
                        <key>redis_stats[6379,expired_keys]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>Redis Last_save_time_6379</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>Templates Redis_6379</host>
                        <key>redis_stats[6379,last_save_time]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>Redis Port Connections_6379</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>0</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>EE0000</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>4</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Templates Redis_6379</host>
                        <key>redis_stats[6379,blocked_clients]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>1</sortorder>
                    <drawtype>0</drawtype>
                    <color>BBBB00</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>4</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Templates Redis_6379</host>
                        <key>redis_stats[6379,total_connections_received]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>2</sortorder>
                    <drawtype>0</drawtype>
                    <color>CC00CC</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>4</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Templates Redis_6379</host>
                        <key>redis_stats[6379,total_commands_processed]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>3</sortorder>
                    <drawtype>0</drawtype>
                    <color>00CCCC</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>4</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Templates Redis_6379</host>
                        <key>redis_stats[6379,connected_slave]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>4</sortorder>
                    <drawtype>0</drawtype>
                    <color>009900</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>4</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Templates Redis_6379</host>
                        <key>redis_stats[6379,connected_clients]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>Redis Port status_6379</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>Templates Redis_6379</host>
                        <key>net.tcp.listen[6379]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>Redis Uptime_in_seconds_6379</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>Templates Redis_6379</host>
                        <key>redis_stats[6379,uptime_in_seconds]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>Redis Used memory_6379</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>Templates Redis_6379</host>
                        <key>redis_stats[6379,used_memory:]</key>
                    </item>
                </graph_item>
                <graph_item>
                    <sortorder>1</sortorder>
                    <drawtype>0</drawtype>
                    <color>00C8C8</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>Templates Redis_6379</host>
                        <key>redis_stats[6379,used_memory_rss]</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
    </graphs>
</zabbix_export>

转载于:https://www.cnblogs.com/wangxin37/p/6398179.html

<think>首先,用户的问题是:“我想监控Redis性能和状态 请问如何使用Zabbix监控Redis性能指标和状态”。这涉及到使用Zabbix监控Redis的性能和状态指标。 根据系统级指令: - 所有行内数学表达式必须使用$...$格式。 - 独立公式必须使用$$...$$格式并单独成段。 - LaTeX语法正确。 - 使用中文回答。 - 生成相关问题。 - 在回答中引用的段落末尾自然地添加引用标识,例如[^1]。 用户可见层要求: - 回答结构清晰,帮助用户逐步解决问题。 - 尽量保证回答真实可靠。 参考站内引用: - 引用[1]: 关于Zabbix监控Redis状态,包括使用zabbix_get获取值。 - 引用[2]: 涉及自定义监控和shell脚本。 - 引用[3]: 描述Zabbix监控Redis状态,包括自动发现和脚本配置。 - 引用[4]: 另一个脚本示例监控Redis。 这些引用提供了背景信息,我需要基于此构建回答。用户想监控Redis的性能和状态,所以我会覆盖如何设置Zabbix监控Redis的关键指标,如内存使用、CPU、连接数等。 回答结构: 1. **引言**:简要解释为什么监控Redis重要,并介绍使用Zabbix的方法。 2. **步骤指南**:逐步描述如何配置Zabbix监控Redis。 - 安装和配置Redis。 - 创建监控脚本。 - 配置Zabbix agent。 - 设置Zabbix server监控项。 - 可选:使用自动发现。 3. **示例代码**:提供脚本示例。 4. **关键指标**:列出常见的Redis性能指标。 5. **测试和验证**:如何测试监控。 6. **生成相关问题**:在末尾添加相关问题。 生成相关问题:基于内容,提出3-4个相关问题。 在回答中,我会自然地引用参考内容。例如,当提到脚本时,可以引用[2]或[4]。 确保使用中文回答。 现在,规划具体内容: - **步骤1: 准备Redis环境** - 确保Redis已安装并运行。 - 允许Zabbix agent访问Redis信息。 - **步骤2: 创建监控脚本** - 编写一个shell脚本,使用redis-cli获取信息。 - 示例脚本:参考引用[2]和[4]。 - 脚本内容:如`redis_status.sh`,获取特定指标。 - **步骤3: 配置Zabbix Agent** - 在agent配置文件中添加UserParameter。 - 引用[3]提到配置文件路径。 - 设置权限和重启agent。 - **步骤4: 在Zabbix Server设置监控项** - 创建主机和监控项。 - 使用自定义键。 - 可选:使用自动发现模板。 - **步骤5: 测试** - 使用zabbix_get测试,如引用[1]所示。 关键指标:包括used_memory、connected_clients、instantaneous_ops_per_sec等。 相关问题: 1. 如何监控Redis的内存碎片率? 2. Zabbix监控Redis时如何设置触发器报警? 3. Redis监控中常见的问题有哪些? 4. 如何优化Zabbix监控Redis的性能? 最后,确保回答真实可靠:基于标准ZabbixRedis监控实践。</think>### 如何使用Zabbix监控Redis性能指标和状态 监控Redis的性能和状态是确保数据库高可用的关键。Redis提供丰富的运行时指标(如内存使用、连接数、吞吐量等),而Zabbix通过自定义脚本和监控项实现灵活采集。以下是基于最佳实践的逐步指南,结合了Zabbix的配置方法。所有步骤均参考了可靠的ZabbixRedis文档[^1][^2][^3][^4]。 --- #### **步骤1: 准备Redis环境** 确保Redis已安装并运行,且允许Zabbix agent访问Redis的`INFO`命令。 - 安装Redis(如未安装): ```bash sudo apt-get install redis-server # Debian/Ubuntu sudo systemctl start redis ``` - 验证Redis运行: ```bash redis-cli ping # 应返回 "PONG" ``` - 配置Redis绑定地址(可选):在`/etc/redis/redis.conf`中设置`bind 0.0.0.0`以允许远程访问(测试后恢复为安全设置)。 --- #### **步骤2: 创建监控脚本** 编写一个Shell脚本,使用`redis-cli`获取指标。脚本需返回指定参数的值,便于Zabbix采集。参考引用[2][^2]和[4][^4]的示例。 - 创建脚本文件`/etc/zabbix/scripts/redis_info.sh`: ```bash #!/bin/bash REDIS_CLI="/usr/bin/redis-cli" # 根据实际路径调整 HOST="127.0.0.1" # Redis IP,本地用127.0.0.1 PORT="6379" # Redis端口 METRIC="$1" # Zabbix传递的指标名 # 获取Redis INFO输出并过滤指标 VALUE=$($REDIS_CLI -h $HOST -p $PORT info | grep -w "$METRIC" | awk -F ':' '{print $2}') echo $VALUE ``` - 脚本说明: - 通过`$1`接收Zabbix传递的指标名(如`used_memory`)。 - 使用`grep -w`精确匹配指标行,`awk`提取值。 - 支持常见指标:内存使用(`used_memory`)、连接数(`connected_clients`)、吞吐量(`instantaneous_ops_per_sec`)等。 - 设置脚本权限: ```bash sudo chown zabbix:zabbix /etc/zabbix/scripts/redis_info.sh sudo chmod +x /etc/zabbix/scripts/redis_info.sh ``` --- #### **步骤3: 配置Zabbix Agent** 在Zabbix agent端定义UserParameter,使Zabbix server能调用脚本。参考引用[3][^3]。 - 编辑agent配置文件: ```bash sudo nano /etc/zabbix/zabbix_agentd.conf.d/redis.conf ``` - 添加以下内容: ```ini UserParameter=redis.info[*],/etc/zabbix/scripts/redis_info.sh "$1" ``` - `redis.info[*]`是自定义键,`*`表示动态指标名。 - 重启Zabbix agent应用更改: ```bash sudo systemctl restart zabbix-agent ``` --- #### **步骤4: 在Zabbix Server设置监控项** 登录Zabbix Web界面,添加监控项(支持手动添加或自动发现)。 - **手动添加监控项**(适合固定指标): 1. 导航到 **Configuration → Hosts → 选择目标主机**。 2. 点击 **Create item**: - **Name**: 如 "Redis Used Memory"。 - **Key**: `redis.info[used_memory]`。 - **Type**: Zabbix agent。 - **Update interval**: 如 `30s`(根据需求调整)。 3. 重复为其他关键指标创建监控项,例如: - `redis.info[connected_clients]`(当前连接数)。 - `redis.info[instantaneous_ops_per_sec]`(每秒操作数)。 - `redis.info[used_memory_rss]`(物理内存使用)。 - **使用自动发现模板**(推荐,动态发现指标): 1. 创建发现规则: - **Name**: "Redis Metrics Discovery"。 - **Key**: `redis.info.discovery`(需额外脚本,见下文)。 - **Type**: Zabbix agent。 2. 配置发现脚本(扩展步骤2的脚本): - 修改`redis_info.sh`支持JSON输出,或创建新脚本`redis_discovery.sh`: ```bash #!/bin/bash # 输出所有指标名的JSON数组 REDIS_CLI="/usr/bin/redis-cli" HOST="127.0.0.1" PORT="6379" echo '{"data":[' $REDIS_CLI -h $HOST -p $PORT info | grep -v '^#' | awk -F: '{print "\""$1"\""}' | sed 's/^/{ "{#METRIC}\":/g' | sed 's/$/ },/g' echo ']}' ``` - 在agent配置中添加:`UserParameter=redis.info.discovery,/etc/zabbix/scripts/redis_discovery.sh`。 3. 在Zabbix Web创建监控项原型: - 基于发现规则,为每个指标自动生成监控项。 --- #### **步骤5: 测试和验证** 确保监控项正常工作: - 在Zabbix server使用`zabbix_get`测试(参考引用[1][^1]): ```bash zabbix_get -s <Redis主机IP> -k redis.info[used_memory] # 示例输出: "1024000" (单位: bytes) ``` - 在Zabbix Web查看最新数据: - 导航到 **Monitoring → Latest data**,过滤Redis相关监控项。 - 设置触发器(可选):当指标异常时报警,如内存超过阈值: - 创建Trigger:`{HOST:redis.info[used_memory].last()}>1000000000`(内存超1GB报警)。 --- #### **关键Redis性能指标列表** 监控这些指标可全面覆盖Redis状态: - **内存相关**:`used_memory`, `used_memory_rss`, `mem_fragmentation_ratio`(碎片率)。 - **连接相关**:`connected_clients`, `rejected_connections`。 - **性能相关**:`instantaneous_ops_per_sec`, `keyspace_hits`, `keyspace_misses`。 - **持久化相关**:`rdb_last_save_time`, `aof_current_size`。 - **复制相关**(如适用):`master_link_status`, `slave_repl_offset`。 > **注意**:Redis的`INFO`命令输出所有指标,完整列表见[Redis文档](https://redis.io/docs/management/optimization/monitoring/)。监控频率建议30-60秒,避免过高负载[^3][^4]。 --- ### 相关问题 1. **如何监控Redis的内存碎片率?** 内存碎片率(`mem_fragmentation_ratio`)过高会影响性能,可通过监控项`redis.info[mem_fragmentation_ratio]`采集,并在Zabbix设置触发器报警(如>1.5时报警)[^2][^4]。 2. **Zabbix监控Redis时如何设置触发器报警?** 在Zabbix Web的Trigger配置中,基于监控项定义条件,例如当连接数超过阈值时触发动作(如发送邮件或Slack通知)[^1][^3]。 3. **Redis监控中常见的问题有哪些?** 常见问题包括内存泄漏(监控`used_memory`增长)、连接耗尽(监控`connected_clients`)、高延迟(监控`latency`指标)。Zabbix的图表和历史数据可帮助诊断[^3][^4]。 4. **如何优化Zabbix监控Redis的性能?** 优化方法包括减少监控频率、使用主动式检查、压缩历史数据。对于大型集群,可结合Zabbix proxy分担负载[^1][^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值