1. Introduction
Monitoring the performance of web endpoints is essential to ensure optimal user experience.
This Bash script collects detailed HTTP timing metrics for a given URL, allowing network engineers to identify potential bottlenecks in the web request lifecycle.
Example Use Cases:
- Measure Time To First Byte (TTFB) to evaluate server responsiveness
- Monitor DNS lookup, connection, and SSL handshake times
- Track total page load performance for web monitoring
2. Overview of the Script
This Bash script:
- Accepts a target URL (defaulting to
https://example.com
if none is provided) - Uses
curl
to retrieve HTTP timing metrics - Outputs key measurements including:
- DNS lookup time
- TCP connect time
- SSL handshake time
- Time to first byte (TTFB)
- Total load time
Prerequisites:
- Linux-based NetBeez agent
- Bash shell
Expected Output:
- Metrics reported in seconds with decimal precision for easy monitoring
3. Script Code
#!/usr/bin/env bash
# URL to measure (default if not provided)
URL="${1:-https://example.com}"
# Use curl to get timing metrics
read -r namelookup connect appconnect starttransfer total < <(
curl -o /dev/null -s -w "%{time_namelookup} %{time_connect} %{time_appconnect} %{time_starttransfer} %{time_total}\n" "$URL"
)
# Print results in a format compatible with NetBeez metrics
echo "dns_lookup_time=$namelookup"
echo "connect_time=$connect"
echo "ssl_handshake_time=$appconnect"
echo "ttfb=$starttransfer"
echo "total_load_time=$total"
4. Sample Output
dns_lookup_time=0.012
connect_time=0.034
ssl_handshake_time=0.056
ttfb=0.123
total_load_time=0.245
5. Closing Remarks
This script provides a quick way to monitor HTTP performance metrics from a NetBeez agent, enabling you to pinpoint slow components in the request lifecycle.
Extensions you could try:
-
Automate testing multiple URLs and log metrics over time
-
Alert if any metric exceeds a threshold
-
Integrate with dashboards for real-time web performance monitoring
Share your enhancements in the comments so the community can benefit!