Skip to content

Commit

Permalink
add docker-compose for monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
vijayabharathib committed May 4, 2024
1 parent 4aa4f0b commit 5ea17e7
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
21 changes: 21 additions & 0 deletions monitor/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# DOCKER IMAGE
MONITOR_DOCKER_IMAGE_VERSION="v0.0.1"

#
# DO S3 ACCESS
#
S3_ACCESS_KEY_ID="<KEY_ID>"
S3_SECRET_ACCESS_KEY="<SECRET KEY>"
S3_BUCKET="jemo"
S3_ENDPOINT="https://sgp1.digitaloceanspaces.com"
# S3_PREFIX="wiki/testing"
S3_PREFIX="wiki/production"


# NOTIFICATION CHANNEL
DISCORD_NOTIFICATION_URL="<DISCORD NOTIFICATION URL>"

#
# CRON FREQ
# CHECK EVERY 45 MINUTES
CRON_MONITOR_TIME="*/45 * * * *"
23 changes: 23 additions & 0 deletions monitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
= Tamil Wiki Backup Monitoring

Tamil wiki database and images are backed up every hour through a cron job. Daily, weekly, monthly backups are also maintained. There has been instances where the backup failed to run. This monitor is to check s3 for the latest backups uploaded and alert if the houly backup is delayed for more than 1.5 hours.

== Build

```
docker build -t tamilwiki/monitor:v0.0.1 .
```

This will build the docker image, with tag `v0.0.1`. This version should be used within the `.env` file, as the value for `MONITOR_DOCKER_IMAGE_VERSION`.

== Run

1. Update the `.env.example` with the right values
2. Rename `.env.example` to `.env` within the `monitor` folder
3. Do not mutate the `.env` file in any other folder, especially if you have `compose-deployment`
4. Start the container from `monitor` folder

```
docker-compose up -d
```

2 changes: 1 addition & 1 deletion monitor/cron_monitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ sql_backup_delayed=$(echo "$hours_since_sql_dump > $minimum_backup_time_requirem

# if not, notify
if [[ $((mediawiki_backup_delayed + sql_backup_delayed)) > 0 ]] ; then
curl -X POST $DISCORD_NOTIFICATION_URL -H 'Content-Type: application/json' -d '{"embeds":[{"color":"14365807","title":"MediaWiki Backup","type":"rich","description":"Backup Cron Testing","fields":[{"name":"Mediawiki Backup Time","value":"'"$hours_since_mediawiki_dump hours ago"'"},{"name":"DB Bakup Time","value":"'"$hours_since_sql_dump hours ago"'"},{"name":"frequency","value":"hourly"},{"name":"S3 Bucket","value":"'"$S3_PREFIX"'"}]}]}'
curl -X POST $DISCORD_NOTIFICATION_URL -H 'Content-Type: application/json' -d '{"embeds":[{"color":"14365807","title":"MediaWiki Backup","type":"rich","description":"Hourly Backup Failed","fields":[{"name":"Mediawiki Backup Time","value":"'"$hours_since_mediawiki_dump hours ago"'"},{"name":"DB Bakup Time","value":"'"$hours_since_sql_dump hours ago"'"},{"name":"frequency","value":"hourly"},{"name":"S3 Bucket","value":"'"$S3_PREFIX"'"}]}]}'
echo "Notified the delay in backup cron"
else
echo "No delay in hourly backup. Hence, no notification sent."
Expand Down
34 changes: 34 additions & 0 deletions monitor/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '2.4'

networks:
# This networks defined in main yaml docker-compose.yml file
# Since both are refering common project the network defined here will refer the same.
default:
ipam:
driver: default

# YAML aliases
x-default: &default
dns:
- 1.1.1.1
- 1.0.0.1

services:

monitor:
<<: *default
image: tamilwiki/monitor:${MONITOR_DOCKER_IMAGE_VERSION}
restart: on-failure
mem_limit: 128M
mem_reservation: 64M
environment:
DISCORD_NOTIFICATION_URL: ${DISCORD_NOTIFICATION_URL}
CRON_MONITOR_TIME: ${CRON_MONITOR_TIME}
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID}
S3_BUCKET: ${S3_BUCKET}
S3_ENDPOINT: ${S3_ENDPOINT}
S3_LIFECYCLE_EXPIRATION_DAYS: ${S3_LIFECYCLE_EXPIRATION_DAYS}
S3_PREFIX: ${S3_PREFIX}
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY}
networks:
- default

0 comments on commit 5ea17e7

Please sign in to comment.