Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Monitor System Performance on Raspberry Pi

Monitoring system performance is crucial for maintaining the health and efficiency of your Raspberry Pi. This article will guide you through setting up system monitoring on a Raspberry Pi using various tools and scripts. These tools will help you keep track of CPU usage, memory consumption, disk space, and network activity.

Examples:

  1. Using top and htop for Real-Time Monitoring:

    • top Command: This is a built-in command-line tool that provides a dynamic view of running processes. To use it, simply open a terminal and type:

      top

      This will display a list of processes, along with CPU and memory usage.

    • htop Command: htop is an enhanced version of top with a more user-friendly interface. First, install it using:

      sudo apt-get update
      sudo apt-get install htop

      Then, run it by typing:

      htop
  2. Using vcgencmd for Temperature Monitoring:

    The Raspberry Pi has a built-in command to check the CPU temperature:

    vcgencmd measure_temp

    This command will output the current temperature of the CPU.

  3. Setting Up a Python Script for Periodic Monitoring:

    You can create a Python script to log system performance metrics periodically. Here's a simple example:

    import os
    import time
    
    def log_system_stats():
       while True:
           # Log CPU usage
           os.system("top -bn1 | grep 'Cpu(s)' >> system_log.txt")
           # Log Memory usage
           os.system("free -m >> system_log.txt")
           # Log Disk usage
           os.system("df -h >> system_log.txt")
           # Log CPU temperature
           os.system("vcgencmd measure_temp >> system_log.txt")
           # Wait for 60 seconds before logging again
           time.sleep(60)
    
    if __name__ == "__main__":
       log_system_stats()

    Save this script as monitor.py and run it with:

    python3 monitor.py &
  4. Using nmon for Comprehensive Monitoring:

    nmon is a powerful tool for monitoring system performance. To install it, use:

    sudo apt-get install nmon

    Run it by typing:

    nmon

    Use the keyboard to navigate and toggle different metrics like CPU, memory, disk, and network usage.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.