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:
- Basic understanding of Linux command-line interface.
- Access to a Linux system ssh to your instance same as before.
Part 1: Basic Host Monitoring
Step 1: CPU Monitoring
- Open a terminal on the Linux host.
- Use the
top
command to monitor CPU usage. - Observe the processes, CPU usage percentages, and overall system metrics.
Step 2: Memory Monitoring
- Use the
free
command to display memory usage information. - Identify total, used, and free memory.
- Use the
vmstat
command to report virtual memory statistics.
Step 3: Disk Monitoring
- Use the
df
command to display disk space usage. - Identify the filesystems and their respective usage.
Step 4: Network Monitoring
- Use the
netstat
command to display network statistics. - Identify active network connections and listening ports.
Part 2: Advanced Monitoring with System Logs
Step 1: Accessing System Logs
- Explore system logs using the
journalctl
command. - Identify log entries related to system events, errors, and warnings.
Step 2: Real-time Monitoring
- Use the
tail
command to monitor a specific log file in real-time. - Observe new log entries as they occur.
Part 3: Process Monitoring
Step 1: List Running Processes
- Use the
ps
command to list running processes. - Identify key information such as process ID, CPU usage, and memory usage.
Step 2: Process Resource Monitoring
- Use the
htop
command to interactively monitor processes. - Observe CPU and memory usage in real-time.
Part 4: Monitoring with Shell Scripts
Step 1: Create a Monitoring Script
- Write a simple shell script that combines the commands used in the exercise.
-
In our exercise, we will use the exit status 0 = Successful and 1 = Failed due to an error.“
-
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.
-