DEV Community

Cover image for MID INTERNSHIP TASK: Building devopsfetch for Server Information Retrieval and Monitoring.
Efosa Oviawe
Efosa Oviawe

Posted on • Edited on

MID INTERNSHIP TASK: Building devopsfetch for Server Information Retrieval and Monitoring.

Introduction

Welcome to the documentation for DevOpsFetch, a powerful yet straightforward monitoring tool designed to meet the requirements of HNG Internship Task 5. At first glance, the task of creating a system to monitor various aspects of a server environment may seem simple. However, achieving this requires close attention to detail and a comprehensive understanding of different system components.

DevOpsFetch encapsulates this challenge, providing an intuitive solution that monitors:

  • Active network ports
  • Docker container statuses
  • Nginx configurations and domains
  • User login activities
  • System activities within specified time ranges

This documentation will guide you through the installation, configuration, and usage of DevOpsFetch. With clear instructions and practical examples, you'll find that what initially seemed complex can be managed efficiently with the right approach and tools. Let's dive in and simplify your monitoring tasks with DevOpsFetch.

Installation and Configuration

Prerequisites

Ensure your system has the necessary dependencies:

  • net-tools
  • nginx
  • docker.io

Installation Steps

  1. Clone and Run the Installer Script:
git clone https://github.com/Oviawe007/HNG-Task-5.git
cd HNG-Task-5.git
Enter fullscreen mode Exit fullscreen mode

Make the script executable:

chmod +x devopsfetch.sh
chmod +x install.sh
Enter fullscreen mode Exit fullscreen mode

Run the script:

sudo ./install.sh
Enter fullscreen mode Exit fullscreen mode

2. Check the Installation:

  • Verify that the devopsfetch.sh script is installed in > /opt/devopsfetch/ and is executable.
  • Confirm that a symbolic link to devopsfetch.sh is created at > /usr/local/bin/devopsfetch.
  • Ensure the devopsfetch.service file is created in > /etc/systemd/system/.

3. Check the Service:

sudo systemctl status devopsfetch.service
Enter fullscreen mode Exit fullscreen mode

service info

Configuration

The service is configured to run devopsfetch.sh every hour by default. You can modify the service configuration in

/etc/systemd/system/devopsfetch.service if needed.

Usage Examples

Run devopsfetch.sh as a root user with the appropriate flags to fetch the desired information.

  • Show Help:
sudo ./devopsfetch.sh -h
Enter fullscreen mode Exit fullscreen mode

devopsfetch help

  • Get Active Ports:
sudo ./devopsfetch.sh -p
Enter fullscreen mode Exit fullscreen mode

port info

  • Get Specific Port Info:
sudo ./devopsfetch.sh -p [PORT]
# Example: sudo devopsfetch -p 4369
Enter fullscreen mode Exit fullscreen mode

port info

  • Get Docker Info:
sudo ./devopsfetch.sh -d
Enter fullscreen mode Exit fullscreen mode

docker info

  • Get Specific Docker Container Info:
sudo ./devopsfetch.sh -d [CONTAINER_NAME]
# Example: sudo ./devopsfetch.sh -d my_container
Enter fullscreen mode Exit fullscreen mode
  • Get Nginx Info:
sudo ./devopsfetch.sh -n
Enter fullscreen mode Exit fullscreen mode
  • Get Specific Nginx Domain Info:
sudo ./devopsfetch.sh -n [DOMAIN]
# Example: sudo ./devopsfetch.sh -n example.com
Enter fullscreen mode Exit fullscreen mode

nginx info

  • Get User Logins:
sudo ./devopsfetch.sh -u
Enter fullscreen mode Exit fullscreen mode

login info

  • Get Specific User Info:
sudo ./devopsfetch.sh -u [USER]
# Example: sudo ./devopsfetch.sh -u ubuntu
Enter fullscreen mode Exit fullscreen mode

ubuntu info

  • Get Activities in Time Range:
sudo ./devopsfetch.sh -t [START_TIME] [END_TIME]
# Example: sudo ./devopsfetch.sh -t "2024-07-22 10:00:00" "2024-07-22 11:00:00"
Enter fullscreen mode Exit fullscreen mode

Time info

Logging Mechanism

  • Log Rotation Configuration The installation script sets up log rotation for > /var/log/syslog to ensure logs do not consume excessive disk space. The log rotation configuration is defined in > /etc/logrotate.d/devopsfetch.

View Logs

To retrieve and view logs, you can use the tail -f command:

tail -f /var/log/devopsfetch.log
Enter fullscreen mode Exit fullscreen mode

This command will display the logs for the DevOpsFetch service, allowing you to monitor its activities and debug if necessary.

Summary

DevOpsFetch provides a comprehensive solution for monitoring various system and application metrics, including active ports, Docker containers, Nginx configurations, and user logins. By following the installation steps and using the provided command-line flags, you can effectively gather and analyze the information needed to maintain and troubleshoot your system. The logging mechanism ensures that you have a record of all activities for further analysis and auditing.

Leave your questions and feedback in the comments.
Thank you.

Top comments (0)