2021-06-16 11:00:15 -06:00
|
|
|
#!/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
|
|
|
|
2021-05-26 11:41:28 -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():
|
2021-06-19 10:03:02 -06:00
|
|
|
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
|
2021-06-27 13:07:32 -06:00
|
|
|
log_tail = os.popen(f"tail -n 100 {redis_log_path}").read()
|
2021-06-16 10:12:59 -06:00
|
|
|
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()
|