You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Nagios中检查磁盘空间?含主机管理界面手动检查方法

Hey there, let's break down how to check disk space in Nagios—both setting up automated monitoring (the standard Nagios workflow) and manually triggering checks right from the web interface.

一、配置Nagios自动监控磁盘空间

Nagios uses its built-in check_disk plugin for disk space checks, and getting this set up is pretty straightforward.

1. 确认插件已安装

First off, make sure the plugin exists on your Nagios server (or the remote host if you're using NRPE for remote checks):

# 检查本地Nagios服务器的插件路径,默认是这个
ls /usr/lib/nagios/plugins/check_disk

If it's missing, install the Nagios plugins package for your distro—like nagios-plugins-disk on Debian/Ubuntu, or nagios-plugins-all on RHEL/CentOS.

2. 定义可复用的检查命令

Fire up your Nagios commands config file (usually commands.cfg in /usr/local/nagios/etc/objects/ or your custom config directory) and add this command definition:

define command{
    command_name    check_disk
    command_line    $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
}

Let's break down the parameters:

  • -w: Warning threshold (e.g., 10% means alert when only 10% space is left, or 1000M for 1GB remaining)
  • -c: Critical threshold (stricter than warning—e.g., 5% or 500M)
  • -p: The partition you want to monitor (like / for root, /home for user home directories)

3. 给目标主机添加磁盘监控服务

Next, add a service definition to your target host's config file (or a dedicated services config file) to enable monitoring:

define service{
    use                     generic-service
    host_name               YourTargetHost
    service_description     Root Disk Space
    check_command           check_disk!10%!5%!/
}

Swap out YourTargetHost with the actual hostname in your Nagios setup, and adjust the thresholds/partition path to match your needs.

4. 验证配置并重启Nagios

Pro tip: Always validate your config before restarting to avoid breaking Nagios:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If no errors pop up, restart the Nagios service:

systemctl restart nagios

二、在Nagios主机管理界面手动检查磁盘空间

If you need an on-demand check (instead of waiting for the scheduled interval), here's how to do it via the web UI:

  1. 登录Nagios Web界面:Open your browser, navigate to your Nagios URL (usually http://your-nagios-server/nagios), and log in with your admin credentials.
  2. 定位目标主机:
    • Click Hosts in the left sidebar under the "Monitoring" section.
    • From the host list, click the name of the machine you want to check (e.g., YourTargetHost).
  3. 找到磁盘空间服务:On the host details page, scroll down to the "Services" table. Look for the disk space service you set up (like "Root Disk Space").
  4. 手动触发检查:
    • Click the Check Now link (it's usually in the "Actions" column next to the service).
    • A pop-up will confirm the check is being initiated—hit OK.
  5. 查看最新结果:Wait a few seconds, then refresh the page. You'll see the latest check result in the "Status Information" column, showing current disk usage, free space, and whether it's in OK/Warning/Critical status.

额外小技巧

If you need to check a partition that isn't set up as a service yet, use the Custom Commands feature (if enabled):

  • Head to Core Config Manager (for Nagios XI) or the External Commands page in Nagios Core.
  • Select Schedule immediate check and specify the check_disk command with your parameters—for example: check_disk -w 10% -c 5% -p /var

内容的提问来源于stack exchange,提问作者Dinesh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:48:06