fix disk usage sanity checker to check host machine and pass the data into the container to evaluate the disk usage and send an email

This commit is contained in:
Jonathan Math 2021-06-18 14:57:29 -06:00
parent 7394517a40
commit bf140f1aea
6 changed files with 56 additions and 37 deletions

View file

@ -20,9 +20,16 @@
notify:
- reload consul
- name: Link disk usage sanity checker
- name: Add sanity checkers cronjob for disk usage
become: yes
file:
src: "/srv/newsblur/utils/monitor_disk_usage.py"
dest: "/etc/cron.daily/monitor_disk_usage"
state: link
cron:
name: disk_usage_sanity_checker
special_time: daily
job: docker pull newsblur/newsblur_python3:latest;
docker run --rm
output=$(eval sudo df / | head -n 2 | tail -1);
-v /srv/newsblur:/srv/newsblur
--network=newsblurnet --hostname {{ ansible_hostname }}
newsblur/newsblur_python3 /srv/newsblur/utils/monitor_disk_usage.py $output
tags:
- sanity-checker

View file

@ -52,9 +52,16 @@
notify:
- reload consul
- name: Link disk usage sanity checker
- name: Add sanity checkers cronjob for disk usage
become: yes
file:
src: "/srv/newsblur/utils/monitor_disk_usage.py"
dest: "/etc/cron.daily/monitor_disk_usage"
state: link
cron:
name: disk_usage_sanity_checker
special_time: daily
job: docker pull newsblur/newsblur_python3:latest;
docker run --rm
output=$(eval sudo df / | head -n 2 | tail -1);
-v /srv/newsblur:/srv/newsblur
--network=newsblurnet --hostname {{ ansible_hostname }}
newsblur/newsblur_python3 /srv/newsblur/utils/monitor_disk_usage.py $output
tags:
- sanity-checker

View file

@ -95,9 +95,14 @@
- reload consul
when: item.target_host in inventory_hostname and disable_consul_services_ie_staging is not defined
- name: Link disk usage sanity checker
- name: Add sanity checkers cronjob for disk usage
become: yes
file:
src: "/srv/newsblur/utils/monitor_disk_usage.py"
dest: "/etc/cron.daily/monitor_disk_usage"
state: link
cron:
name: disk_usage_sanity_checker
special_time: daily
job: docker pull newsblur/newsblur_python3:latest;
docker run --rm
output=$(eval sudo df / | head -n 2 | tail -1);
-v /srv/newsblur:/srv/newsblur
--network=newsblurnet --hostname {{ ansible_hostname }}
newsblur/newsblur_python3 /srv/newsblur/utils/monitor_disk_usage.py $output

View file

@ -24,9 +24,14 @@
notify:
- reload consul
- name: Link disk usage sanity checker
- name: Add sanity checkers cronjob for disk usage
become: yes
file:
src: "/srv/newsblur/utils/monitor_disk_usage.py"
dest: "/etc/cron.daily/monitor_disk_usage"
state: link
cron:
name: disk_usage_sanity_checker
special_time: daily
job: docker pull newsblur/newsblur_python3:latest;
docker run --rm
output=$(eval sudo df / | head -n 2 | tail -1);
-v /srv/newsblur:/srv/newsblur
--network=newsblurnet --hostname {{ ansible_hostname }}
newsblur/newsblur_python3 /srv/newsblur/utils/monitor_disk_usage.py $output

View file

@ -23,13 +23,6 @@
notify:
- reload consul
- name: Link disk usage sanity checker
become: yes
file:
src: "/srv/newsblur/utils/monitor_disk_usage.py"
dest: "/etc/cron.daily/monitor_disk_usage"
state: link
- name: Add sanity checkers cronjob for disk usage
become: yes
cron:
@ -37,10 +30,10 @@
special_time: daily
job: docker pull newsblur/newsblur_python3:latest;
docker run --rm
output=$(eval sudo df / | head -n 2 | tail -1);
-v /srv/newsblur:/srv/newsblur
--network=newsblurnet newsblur/newsblur_python3 /srv/newsblur/utils/monitor_disk_usage.py
tags:
- sanity-checker
--network=newsblurnet --hostname {{ ansible_hostname }}
newsblur/newsblur_python3 /srv/newsblur/utils/monitor_disk_usage.py $output
- name: Make docker network for newsblurnet
become: yes
@ -50,8 +43,11 @@
- name: Get log file location for redis
become: yes
shell: docker inspect --format='{{.LogPath}}' redis
shell: docker inspect --format="{{ '{{' }}.LogPath {{ '}}' }}" redis
register: redis_log_path
- name: show redis_log_path
debug:
msg: "{{ redis_log_path.stdout }}"
- name: Add sanity checkers cronjob for redis bg_save
become: yes
@ -59,7 +55,7 @@
name: redis_bg_save_sanity_checker
special_time: daily
job: docker pull newsblur/newsblur_python3:latest;
docker run --rm -e redis_log_path={{redis_log_path}} -v {{redis_log_path}}:{{redis_log_path}} -v /srv/newsblur:/srv/newsblur --network=newsblurnet newsblur/newsblur_python3 /srv/newsblur/utils/monitor_redis_bgsave.py
docker run --rm -e redis_log_path={{redis_log_path.stdout}} -v {{redis_log_path.stdout}}:{{redis_log_path.stdout}} -v /srv/newsblur:/srv/newsblur --network=newsblurnet newsblur/newsblur_python3 /srv/newsblur/utils/monitor_redis_bgsave.py
when: "'redis' in inventory_hostname"
tags:
- sanity-checker
- sanity-checker

View file

@ -8,9 +8,8 @@ from newsblur_web import settings
import socket
def main():
df = subprocess.Popen(["df", "/"], stdout=subprocess.PIPE)
output = df.communicate()[0].decode('utf-8')
device, size, used, available, percent, mountpoint = output.split("\n")[1].split()
disk_usage_output = sys.argv[1]
device, size, used, available, percent = disk_usage_output.split()
hostname = socket.gethostname()
percent = int(percent.strip('%'))
admin_email = settings.ADMINS[0][1]
@ -22,7 +21,7 @@ def main():
data={"from": "NewsBlur Disk Monitor: %s <admin@%s.newsblur.com>" % (hostname, hostname),
"to": [admin_email],
"subject": "%s hit %s%% disk usage!" % (hostname, percent),
"text": "Usage on %s: %s" % (hostname, output)})
"text": "Usage on %s: %s" % (hostname, disk_usage_output)})
print(" ---> Disk usage is NOT fine: %s / %s%% used" % (hostname, percent))
else:
print(" ---> Disk usage is fine: %s / %s%% used" % (hostname, percent))