Monitoring - marco1475/linux-htpc GitHub Wiki

E-mail Forwarder

  1. Install msmtp and msmtp-mta:

     pacman -S msmtp msmtp-mta
    
  2. Create the /etc/msmtprc configuration file:

     # Example for a system wide configuration file
     
     # A system wide configuration file is optional.
     # If it exists, it usually defines a default account.
     # This allows msmtp to be used like /usr/sbin/sendmail.
     account default
     
     # The SMTP smarthost.
     host     smtp.gmail.com
     port     587
     from     [email protected]
     user     [email protected]
     password <password>
     
     # Construct envelope-from addresses of the form "[email protected]".
     #auto_from on
     #maildomain oursite.example
     
     # Use TLS.
     auth           on
     tls            on
     tls_starttls   on
     tls_trust_file /etc/ssl/certs/ca-certificates.crt
     
     # Syslog logging with facility LOG_MAIL instead of the default LOG_USER.
     syslog LOG_MAIL
     
     # Aliases
     aliases /etc/aliases
    
    • Set the correct file permissions for /etc/msmtprc, otherwise msmtp will fail:

        chmod 644 /etc/msmtprc
      
    • To be able to use GMail's SMTP server you either need to allow "Less Secure Apps" in Settings > Security or enable 2-factor authentication and use an app password.

  3. Create the /etc/aliases configuration file:

  4. Test the functionality by sending an e-mail:

     echo "Hello there from Babylon 5 Server." | msmtp -a default [email protected]
    

CPU Monitoring

  1. Install the lm_sensors package:

     pacman -S lm_sensors
    
  2. Run sensors-detect and hit Enter to accept all the defaults, which will generate the following /etc/conf.d/lm_sensors file:

     HWMON_MODULES="coretemp nct6775"
    
  3. You can run the sensors command to test whether the sensors work.

HDD Monitoring

  1. Install the smartmontools and hddtemp packages:

     pacman -S smartmontools hddtemp
    
  2. You can run the hddtemp /dev/sd(b|c) command to make sure the spinning drives' sensors work and the smartctl -a /dev/sda command to get the S.M.A.R.T. information, including the temperature, of the SSD.

  3. Set up the smartd daemon to monitor the drives' S.M.A.R.T. attributes:

    1. Edit the /etc/smartd.conf configuration file:

       DEVICESCAN -a -m [email protected] -n standby,24,q -o on -s (S/../../1/12|L/../01/./09) -S on -W 4,40,45
      
      • -a monitor all attributes
      • -m send alert e-mails to [email protected] (add -M test to send a test e-mail when the service starts)
      • -n do not check attributes when the disk is in standby mode (or any lower mode, such as off or sleep), unless it happened 24 times, but be quiet about missing the attribute checks (do not log them)
      • -o automatic offline data collection is on
      • -s schedule a short test every Monday at noon and a long test every 1st of the month at 9am (T/MM/DD/d/HH, i.e. type, month, day, day of the week, hour)
      • S automatic attribute autosave is on
      • W warn about temperature changes of 4 degrees or more between runs, log when the temperature reaches 40 degrees, and log and e-mail if the temperature reaches 45 degrees
    2. Create the /etc/default/smartmontools file to change the default frequency of status checks from 1800 seconds (30 minutes) to 3600 seconds (1 hour):

       SMARTD_ARGS="-i 21600"  Check status every 21600 seconds (3 hours)
      
    3. Run the daemon:

       systemctl start smartd.service
      
    4. Check the status of the service and the log for any errors:

       systemctl status smartd.service
       journalctl -u smartd
      
    5. Add the smartd daemon to the startup sequence:

       systemctl enable smartd.service
      

Reporting

  1. Copy compose_email.sh, cpu_temperature.sh, hdd_temperature.sh, raid_check.sh, send_interval_email.sh, send_timed_email.sh, and tmp_usage.sh to /usr/local/bin and make them executable (chmod +x).

  2. Create .service and .timer files in /etc/systemd/system for each of the scripts you wish to run repeatedly:

    • .service files:

      [Unit] Description=<description>

      [Service] Type=oneshot ExecStart=/usr/local/bin/<script>.sh

    • .timer files:

      [Unit] Description=<description>

      [Timer] OnUnitActivateSec=<time> -or- OnCalendar=<time>

      [Install] WantedBy=timers.target

  3. Notify systemd that new services were added:

     systemctl daemon-reload
    
  4. Start and enable services using systemctl:

     systemctl start <service_name>.timer
     systemctl enable <service_name>.timer
    
  5. You check active timers by calling systemctl list-timers.

⚠️ **GitHub.com Fallback** ⚠️