Table of Contents

Easily Monitor Website Response Time – a Nagios XI Plugin for 2025

Picture of Louie Mattia
Louie Mattia
Person writing a plugin

What is this for?

Nagios XI is equipped with a variety of wizards and plugins designed to monitor various systems, including operating systems, routers, devices, and websites. While many of these plugins are designed to track different services, none specifically monitor website traffic or track how frequently a website is visited.

Why it was made

This plugin was created to fill that gap. The goal is to monitor how often a website is visited based on response time. Although not every user may need this functionality, there are specific use cases where it can be highly beneficial. For example, marketing teams can use this plugin to assess how frequently their online products are being viewed, while schools or organizations may wish to track how often certain websites are being accessed. The core idea is simple: the more frequently a website is visited, the slower its response time becomes. By monitoring response times, we can infer the frequency of website visits.

Overview of Plugin

This Nagios XI plugin is written in Python and requires minimal setup. The only additional piece of information required from the user is the URL of the website you wish to monitor. Once configured, the plugin tracks website response time and provides insights into its visit frequency.

Nagios XI Website Time Plugin Code

#!/usr/bin/env python3
import sys
import requests
import time
import argparse

'''
This website is to monitor the usage of websites
This is done by measuring the response time
Louie Mattia Jan 2025
'''

parser = argparse.ArgumentParser()

# Add the website name when calling
parser.add_argument( '-H',
                    '--host',
                    required=True,
                    type=str,
                    help='The website that will be checked')

args = parser.parse_args()

# Assign website name as variable fo use
website = args.host

# Set timeout timer (allow the program to give up)
TIMEOUT = 10 # Seconds

# Threshold times for Warning and Critical
### Try to add for editable values in XI later, get this working first
WARN_START = 2
CRIT_START = 5

# Output parameters, defaults for Nagios
# DONT CHANGE, IT WILL NOT WORK OTHERWISE
OK = 0
WARNING = 1
CRITICAL = 2
UNKNOWN = 3

def check_response():
    # Make sure it can grab the time properly
    try:
        start = time.time()
        response = requests.get(website, timeout=TIMEOUT)
        # How long did it take to respond
        response_time = time.time() - start

        # Status code 200 means its reachable
        if response.status_code == 200:
            # At this point, check if the repsonse time is critial
            if response_time >= CRIT_START:
                print(f"Response time {response_time:.2f}s exceeds {CRIT_START}s, this site is busy")
                return CRITICAL
            # If not, is it at the warning?
            elif response_time >= WARN_START:
                print(f"Response time {response_time:.2f}s exceeds {WARN_START}s, this site is getting active")
                return WARNING
            # Looks like its fine if it makes it here
            else:
                print(f"This website is calm for now, response time is {response_time:.2f}")
                return OK
        # If different status code, something is up
        else:
            code = response.status_code
            print(f"Status code returned {code:.2f}")
            return CRITICAL
    except requests.exceptions.RequestException as e:
        print("Website cannot be reached")
        return CRITICAL

if __name__ == "__main__":
        exit = check_response()
        sys.exit(exit)

You can access the code through Github using this link: https://github.com/NagiosEnterprises/plugins-extra/blob/website_time/website_time.py

Output on Nagios XI

Screenshot 2025 02 06 103411
Website Time Output

As you can see, it gives us the time it took for the website to respond along with a little message about how often it was visited.

Integrating into Nagios XI

  1. Integrate into Nagios XI
    1. Navigate to Admin>System Extensions>Manage Plugins
    2. Click browse, locate the plugin file, and hit upload
  2. Define Plugin as Nagios Command
    1. Go to Configure>Core Config Manager>Commands>Add New
    2. Enter the following details
      • Command Name: website_time(or any name you prefer, as long as you can identify the command)
      • Command Line: python3 $USER1$/website_time.py -H https://$HOSTADDRESS$
        • Ensure the https:// prefix is included for the command to work correctly
      • Command Type: Check Command
    3. After filling in the details, save the command.
  3. Configure for a service
    1. Go to Configure>Core Config Manager>Services>Add New
    2. Fill in the required fields
      • Service Name: Website Time
      • Host: Any applicable website
      • Check Command: website_time
    3. Save service and apply configuration

AI Assistance Acknowledged

This plugin was developed with the assistance of AI, highlighting how AI can streamline the development process. We encourage developers to leverage AI tools to enhance their IT operations and improve efficiency.

Conclusion

While it doesn’t directly track visits, slower response times can provide valuable insights into how often a website is being accessed. This can be especially useful for organizations wanting to understand traffic patterns or measure the performance impact of high traffic levels. Whether for marketing teams analyzing engagement or IT teams tracking website performance, this plugin helps users gain useful data based on inferred visit frequency, ultimately supporting better decision-making and resource management.

Share this post

Tags: