ubuntu

ubuntu minimal系统监控与报警

小樊
50
2025-11-08 21:07:46
栏目: 智能运维

System Monitoring Tools for Ubuntu Minimal
Ubuntu Minimal systems require lightweight, efficient monitoring tools that minimize resource usage while providing critical insights. Below are top choices categorized by type:

Command-Line Tools (Lightweight, No GUI Required)

Graphical Tools (Requires Desktop Environment)

Script-Based Monitoring (Customizable, Automated)

For minimal systems, bash scripts with cron are ideal for scheduled checks. Below is a sample script to monitor CPU, memory, and disk usage, with alerts sent via email when thresholds are exceeded:

#!/bin/bash
# System Monitoring Script with Alert
CPU_THRESHOLD=80
MEMORY_THRESHOLD=85
DISK_THRESHOLD=90
EMAIL="your_email@example.com"

# Get current usage
CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4}')
MEMORY_USAGE=$(free | awk '/Mem/ {printf("%.1f", ($3/$2) * 100)}')
DISK_USAGE=$(df -h / | awk '/\// {print $(NF-1)}')
DISK_USAGE=${DISK_USAGE%\%} # Remove % sign

# Alert function
send_alert() {
    SUBJECT="System Alert: $1 Usage Exceeded Threshold"
    BODY="Current $1 usage: ${2}% (Threshold: ${3}%)\n\n$(date)"
    echo -e "$BODY" | mail -s "$SUBJECT" "$EMAIL"
}

# Check thresholds
if (( $(echo "$CPU_USAGE > $CPU_THRESHOLD" | bc -l) )); then
    send_alert "CPU" "$CPU_USAGE" "$CPU_THRESHOLD"
fi
if (( $(echo "$MEMORY_USAGE > $MEMORY_THRESHOLD" | bc -l) )); then
    send_alert "Memory" "$MEMORY_USAGE" "$MEMORY_THRESHOLD"
fi
if (( $DISK_USAGE > $DISK_THRESHOLD )); then
    send_alert "Disk" "$DISK_USAGE" "$DISK_THRESHOLD"
fi

Setup Instructions:

  1. Save the script as ~/monitor_system.sh.
  2. Make it executable: chmod +x ~/monitor_system.sh.
  3. Install mailutils for email alerts: sudo apt install mailutils.
  4. Add to cron for hourly checks: crontab -e and append 0 * * * * ~/monitor_system.sh.

This script checks CPU (threshold: 80%), memory (85%), and disk (90%) usage every hour. If any metric exceeds the threshold, it sends an email alert with the current usage and timestamp.

Advanced Tools (Scalable, Full-Featured)

For larger setups or advanced needs, consider these tools (may require more resources but offer comprehensive features):

Each tool caters to different needs—choose based on your system’s complexity and monitoring goals. For minimal systems, command-line tools and scripts are recommended to avoid unnecessary overhead.

0
看了该问题的人还看了