NewsBlur-viq/utils/monitor_redis_bgsave.py

42 lines
1.2 KiB
Python
Raw Permalink Normal View History

#!/usr/local/bin/python3
2015-08-18 08:51:49 -07:00
import sys
2024-04-24 09:43:56 -04:00
sys.path.append("/srv/newsblur")
2015-08-18 08:51:49 -07:00
import datetime
2024-04-24 09:50:42 -04:00
import os
import socket
2015-08-18 08:51:49 -07:00
import requests
2024-04-24 09:50:42 -04:00
from newsblur_web import settings
2015-08-18 08:51:49 -07:00
2024-04-24 09:43:56 -04:00
2015-08-18 08:51:49 -07:00
def main():
redis_log_path = sys.argv[1]
2024-04-24 09:43:56 -04:00
t = os.popen("stat -c%Y /srv/newsblur/docker/volumes/redis/")
timestamp = t.read().split("\n")[0]
2015-08-18 08:51:49 -07:00
modified = datetime.datetime.fromtimestamp(int(timestamp))
hostname = socket.gethostname()
modified_minutes = datetime.datetime.now() - modified
log_tail = os.popen(f"tail -n 100 {redis_log_path}").read()
if True:
2024-04-24 09:43:56 -04:00
# if modified < ten_min_ago:
2015-08-18 08:51:49 -07:00
requests.post(
2024-04-24 09:43:56 -04:00
"https://api.mailgun.net/v2/%s/messages" % settings.MAILGUN_SERVER_NAME,
auth=("api", settings.MAILGUN_ACCESS_KEY),
data={
"from": "NewsBlur Redis Monitor: %s <admin@%s.newsblur.com>" % (hostname, hostname),
"to": [settings.ADMINS[0][1]],
"subject": "%s hasn't bgsave'd redis in %s!" % (hostname, modified_minutes),
"text": "Last modified %s: %s ago\n\n----\n\n%s" % (hostname, modified_minutes, log_tail),
},
)
2015-08-18 08:51:49 -07:00
else:
2020-06-19 02:27:48 -04:00
print(" ---> Redis bgsave fine: %s / %s ago" % (hostname, modified_minutes))
2024-04-24 09:43:56 -04:00
if __name__ == "__main__":
2015-08-18 08:51:49 -07:00
main()