A Python-based service for monitoring HTTP endpoints and logging their status to Google Cloud Platform (GCP).
This service uses Docker Compose for easy deployment. Follow these steps to get started:
- Docker and Docker Compose installed
- GCP service account with logging permissions.
-
Config Directory Setup: The
configdirectory contains:config.json- Configuration of endpoints to monitor (uses JSON5 format)gcp-keyfile.json- GCP service account key (optional)
-
GCP Credentials:
- Rename
config/gcp-keyfile.json.exampletoconfig/gcp-keyfile.json - Fill it with your actual GCP service account credentials
- Rename
-
Environment Variables: The
.envfile contains:CONFIG_PATH- Path to the configuration file in the containerGCP_CREDENTIALS_PATH- Path to the GCP credentials in the containerCHECK_INTERVAL- How often to check endpoints (in minutes)
# Start the service
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the service
docker-compose downThe config.json file uses JSON5 format, which allows comments and other helpful features:
{
// Array of endpoint objects to monitor (required)
endpoints: [
{
id: "service-name", // Unique identifier for the endpoint (optional, defaults to URL)
url: "https://...", // URL to monitor (required)
method: "GET", // HTTP method to use (optional, defaults to GET)
headers: { // HTTP headers to include (optional)
Authorization: "Bearer token123"
},
timeout_seconds: 10, // Request timeout in seconds (optional)
success_status_codes: [200, 201], // Status codes considered successful (optional)
enabled: true // Whether this endpoint should be monitored (optional, defaults to true)
},
],
// Default timeout if not specified in endpoint
default_timeout_seconds: 30,
// Default status codes if not specified in endpoint
default_success_status_codes: [200]
}This configuration by default uses JSON5 format for configuration specification, which includes:
- Comments (both line and block comments)
- Trailing commas
- Unquoted property names
- Single-quoted strings
- Multi-line strings
To temporarily disable monitoring for an endpoint without removing it from the configuration:
- Add
"enabled": falseto the endpoint object - The service will skip disabled endpoints during checks
- To re-enable, either remove the "enabled" flag or set it to
trueNote: The container will have to restarted for these changes to take effect.
For each endpoint, the service produces a status object like:
{
"id": "service-name",
"url": "https://example.com/api/health",
"status": "OK", // or "UNAVAILABLE"
"response_code": 200,
"response_time_ms": 156,
"timestamp": "2023-06-15T12:34:56.789Z"
}