0% found this document useful (0 votes)
21 views

System Monitoring

The document provides documentation for a system monitoring script including installation instructions, usage examples, design considerations, test results, and conclusions. The bash script monitors various system metrics and outputs logs and HTML reports. It utilizes modular functions and logging for flexibility and maintainability.

Uploaded by

djcqicr057
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

System Monitoring

The document provides documentation for a system monitoring script including installation instructions, usage examples, design considerations, test results, and conclusions. The bash script monitors various system metrics and outputs logs and HTML reports. It utilizes modular functions and logging for flexibility and maintainability.

Uploaded by

djcqicr057
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

System Monitoring Script Documentation

a) Installation and Usage

Prerequisites:

● A Linux system with a bash shell.


● The following standard Unix commands installed: free, atq, lscpu, df, uptime, find, and
dpkg. You can verify their installation using command -v <command_name>. If any are
missing, use your distribution's package manager to install them (e.g., apt install
<package_name> on Debian/Ubuntu).

Installation:

● Save the Script: Save the script content as system_monitor.sh. You can use a text editor
of your choice.
● Make it Executable: Open a terminal window and navigate to the directory where you
saved the script using the cd command. Then, grant the script execution permission
using the following command:

chmod +x system_monitor.sh

Usage:

Run the Script: Execute the script from the terminal with the following command:

./system_monitor.sh

This will run the script with the default log level (standard).

Specify a Log Level (Optional): The script supports four log levels: verbose, debug, standard,
and key-details. You can specify a desired log level when running the script using the following
syntax:

./system_monitor.sh -l <log_level>

Replace <log_level> with your preferred level (verbose, debug, standard, or key-details). For
example:

./system_monitor.sh -l debug

This will run the script with the debug log level.

Output:

The script will generate two files: output.log that contains log messages based on the chosen
log level and output.html which is a HTML file presents the logged information in a user-friendly
format for viewing in a web browser.

b) Design consideration - what commands you used, how you constructed your script(s)

Shebang and Script Execution: The script begins with a shebang line #!/bin/bash,
indicating the interpreter required to execute the script (Bash shell).

Variable Declarations: The script utilizes variables to store configuration details like the log file
path (LOG_FILE) and default log level (LOG_LEVEL). This improves readability and
maintainability.

Modular Functions for Specific Tasks: The script employs well-defined functions for various
monitoring activities:

● get_datetime(): Retrieves the current date and time.


● log_info(): Logs messages to the designated file with appropriate formatting based
on the chosen log level.
● monitor_* functions: Each function focuses on monitoring a specific system aspect like
memory usage, scheduled tasks, hardware information, system logs, system load, file
changes, and installed packages.
● generate_html_output(): Creates an HTML file presenting the logged information.
● main(): Orchestrates the execution of all monitoring functions and HTML output
generation.

Command-Line Argument Parsing for Flexibility: The script leverages getopts to parse
command-line arguments, allowing users to specify the log level (-l). This empowers them to
control the detail level of logged information (verbose, debug, standard, or key-details).

Justification for Design Choices:

● Bash Scripting: Bash is a prevalent scripting language pre-installed on most Linux


distributions, making the script portable and readily executable.
● Modular Design: Separating functionalities into functions promotes code reusability,
simplifies maintenance, and facilitates testing/debugging of individual components.
● Persistent Logging: Logging data to a file (output.log) enables centralized storage
and historical analysis of system monitoring information.
● Configurable Log Levels: The script offers configurable log levels, granting users
control over the amount of detail logged, and enhancing its adaptability to various needs.
● HTML Output for User-Friendliness: Generating an HTML report (output.html)
provides a user-friendly format for viewing system monitoring data in a web browser.
● Standard Unix Commands: The script utilizes widely available and well-documented
Unix commands for system information gathering, ensuring compatibility across diverse
Unix-like systems.
c) Test Results

The script generates two types of output: a log file (output.log) and an HTML file (output.html).
The log file contains the monitoring information logged by the script, while the HTML file
presents the log output in a web browser-friendly format.

The log level specified when running the script will determine the verbosity of the log output.

Here's an example of what the log file might contain:

Log file (output.log, standard log level):

HTML File Output (output.html):


The HTML file will contain the same log output as the log file, but enclosed within HTML tags for
easier viewing in a web browser. The output will be wrapped in <pre> tags to preserve the
formatting.
Example HTML output:
d) Conclusion/Reflection

Advantages:

Cross-Platform Compatibility: Leveraging Bash ensures seamless execution across Linux


and macOS environments, enhancing its applicability.

Modular Design: The script's modular structure promotes maintainability, reusability, and
efficient troubleshooting.

Configurable Logging: Users can tailor the logging verbosity to their needs, enabling focused
analysis.

Standard Unix Commands: By employing well-documented and ubiquitous Unix commands,


the script minimizes external dependencies.

HTML Output: The script generates HTML reports, facilitating data visualization in web
browsers and fostering collaboration.

Scheduling Automation: Integration with cron allows for automated, periodic monitoring,
eliminating manual intervention.

Disadvantages:

Functionality: While comprehensive, the script might require additional tools or features for in-
depth monitoring of specific system aspects.

Command-Line Interface: The script operates solely in a command-line environment, which


may be less intuitive for GUI-oriented users.

Error Handling: The script's error handling capabilities could be enhanced to ensure more
robust operation in diverse scenarios.

Platform Nuances: While leveraging standard commands, minor variations across Unix-like
systems might necessitate script adjustments.

Scalability: Designed for single-system monitoring, it may not be optimal for large-scale
deployments. Additional solutions might be needed.

Data Analysis/Visualization: The script primarily focuses on log and HTML output. Advanced
data analysis or visualizations might require further processing or external tools.

e) Bibliography
For Bash Scripting:
Bash Guide for Beginners. Available at https://www.freecodecamp.org/news/bash-scripting-
tutorial-linux-shell-script-and-command-line-for-beginners/
Advanced Bash Scripting Guide. Available at https://tldp.org/LDP/abs/html/

For System Monitoring Concepts:


https://www.linode.com/docs/guides/linux-system-monitoring-fundamentals/

For HTML Basics:


HTML Tutorial. Available at https://www.w3schools.com/html/
Bash Guide: https://www.gnu.org/software/bash/manual/ - A comprehensive guide to the
Bash scripting language, covering basic syntax, control flow, functions, and more.
Advanced Bash Scripting Guide: https://tldp.org/LDP/abs/html/ - A more in-depth resource
that delves into advanced topics like parameter parsing, process management, and working
with files.

Linux Shell Scripting Tutorial: https://www.tutorialspoint.com/complete-bash-shell-


scripting/index.asp - A tutorial with examples that covers basic and intermediate concepts of
shell scripting.
The Shell Scripting Tutorial: https://www.shellscript.sh/ - Another interactive tutorial that
introduces scripting concepts through exercises.
Stack Overflow: https://stackoverflow.com/questions/tagged/linux - A great resource for
finding solutions and asking questions related to Linux scripting.
"The Linux Command Line" by William Shotts - A classic book that covers not only basic shell
commands but also scripting fundamentals.
"Learning Bash" by Cameron Newham - An introductory book that teaches scripting concepts
through practical examples.
"Automate the Boring Stuff with Python" by Al Sweigart (While this book focuses on Python, it
introduces scripting concepts applicable to Bash as well)

You might also like