# README
check-http-status
check-http-status
is a CLI tool written in Go that monitors the HTTP status code of a specified website at regular intervals. It can log the results to a file and supports configurable timeouts and intervals.
Features
- Monitors HTTP status codes of a target URL.
- Configurable interval for sending requests.
- Optional logging of results to a file.
- Supports request timeouts to avoid hanging on unresponsive servers.
- Gracefully handles termination via
Ctrl+C
.
Sample output
Timestamp=2024-12-17_22-44-18, Response time=223.767ms, Status=200 OK
Timestamp=2024-12-17_22-44-28, Response time=99.739ms, Status=200 OK
Timestamp=2024-12-17_22-44-38, Response time=87.543ms, Status=200 OK
After interrupting by command+c
, we can get summary:
----------Summary----------
Total Requests: 3
Successful Responses: 3 (100.00%)
Failed Responses: 0 (0.00%)
Average Response Time: 207.722333ms
Installation
Install via go install
You can install the command directly using go install
:
go install github.com/supermarine1377/check-http-status@latest
Ensure your GOPATH/bin
is in your system's PATH
to run the command directly.
Build from Source
-
Clone the repository:
git clone https://github.com/supermarine1377/monitoring-scripts.git cd monitoring-scripts/go/check-http-status
-
Build the CLI:
go build -o check-http-status
-
Add the built binary to your
PATH
or execute it directly.
Usage
check-http-status <URL> [flags]
Example
Monitor the HTTP status code of https://example.com
every 30 seconds and log results to a file:
check-http-status https://example.com -i 30 -c
Flags
Flag | Shorthand | Description | Default |
---|---|---|---|
--interval-seconds | -i | Interval in seconds between HTTP requests. | 10 |
--create-log-file | -c | Create a log file to save the results. The log file name format is check-http-status_<timestamp>.log . | false |
--timeout-seconds | -t | Timeout in seconds for each HTTP request. If no response is received within this time, the request is considered failed. | 30 |
Handling Interruptions
The tool handles interruptions gracefully. Press Ctrl+C
to terminate the monitoring process.
Output
- On the console, the tool prints the HTTP status code and the timestamp for each request.
- If logging is enabled (
--create-log-file
), the results are written to a log file in the working directory.
Development
Prerequisites
- Go 1.20 or later.
Directory Structure
├── cmd
│ ├── root.go # Main command logic.
├── internal
│ ├── http_status # Package for monitoring HTTP status.
│ ├── log_files # Package for managing log files.
Testing
To run tests:
go test ./...
Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE
file for details.
Contact
For questions or feedback, please contact NAME HERE
at <EMAIL ADDRESS>
. Replace placeholders in this README as necessary.