Skip to content

Practice Exercise 1

Practice Exericise 1: Linux Host Monitoring

Objective: The goal of this exercise is to provide interns with hands-on experience in monitoring a Linux host using various tools and commands. Upon completing this exercise, interns should be able to create scripts that can monitor any linux host.

Prerequisites:

  1. Basic understanding of Linux command-line interface.
  2. Access to a Linux system ssh to your instance same as before.

Part 1: Basic Host Monitoring

Step 1: CPU Monitoring

  1. Open a terminal on the Linux host.
  2. Use the top command to monitor CPU usage.
  3. Observe the processes, CPU usage percentages, and overall system metrics.

Step 2: Memory Monitoring

  1. Use the free command to display memory usage information.
  2. Identify total, used, and free memory.
  3. Use the vmstat command to report virtual memory statistics.

Step 3: Disk Monitoring

  1. Use the df command to display disk space usage.
  2. Identify the filesystems and their respective usage.

Step 4: Network Monitoring

  1. Use the netstat command to display network statistics.
  2. Identify active network connections and listening ports.

Part 2: Advanced Monitoring with System Logs

Step 1: Accessing System Logs

  1. Explore system logs using the journalctl command.
  2. Identify log entries related to system events, errors, and warnings.

Step 2: Real-time Monitoring

  1. Use the tail command to monitor a specific log file in real-time.
  2. Observe new log entries as they occur.

Part 3: Process Monitoring

Step 1: List Running Processes

  1. Use the ps command to list running processes.
  2. Identify key information such as process ID, CPU usage, and memory usage.

Step 2: Process Resource Monitoring

  1. Use the htop command to interactively monitor processes.
  2. Observe CPU and memory usage in real-time.

Part 4: Monitoring with Shell Scripts

Step 1: Create a Monitoring Script

  1. Write a simple shell script that combines the commands used in the exercise.
  2. In our exercise, we will use the exit status 0 = Successful and 1 = Failed due to an error.“

  3. The script will do the following:

    • It will monitor a specific host resource.

    • Will have an exit status.

    • Will notify through email.

    • Will have to log every time the script runs.

    • The script will run every 5 minutes.