2020-06-03 12:38:11 -04:00
|
|
|
#!/srv/newsblur/venv/newsblur/bin/python
|
|
|
|
|
|
|
|
import sys
|
|
|
|
sys.path.append('/srv/newsblur')
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import requests
|
2020-12-05 17:23:31 -05:00
|
|
|
from newsblur import settings
|
2020-06-03 12:38:11 -04:00
|
|
|
import socket
|
2021-01-18 17:44:19 -05:00
|
|
|
import redis
|
2020-06-03 12:38:11 -04:00
|
|
|
import pymongo
|
|
|
|
|
|
|
|
def main():
|
|
|
|
df = subprocess.Popen(["df", "/"], stdout=subprocess.PIPE)
|
|
|
|
output = df.communicate()[0]
|
|
|
|
device, size, used, available, percent, mountpoint = output.split("\n")[1].split()
|
|
|
|
hostname = socket.gethostname()
|
|
|
|
percent = int(percent.strip('%'))
|
|
|
|
admin_email = settings.ADMINS[0][1]
|
|
|
|
failed = False
|
|
|
|
feeds_fetched = 0
|
2021-01-18 17:43:18 -05:00
|
|
|
FETCHES_DROP_AMOUNT = 0
|
2021-01-18 17:45:35 -05:00
|
|
|
redis_task_fetches = 0
|
2021-01-18 17:43:18 -05:00
|
|
|
monitor_key = "Monitor:task_fetches"
|
|
|
|
r = redis.Redis(connection_pool=settings.REDIS_ANALYTICS_POOL)
|
|
|
|
|
2020-06-03 12:38:11 -04:00
|
|
|
try:
|
|
|
|
client = pymongo.MongoClient('mongodb://%s' % settings.MONGO_DB['host'])
|
|
|
|
feeds_fetched = client.newsblur.statistics.find_one({"key": "feeds_fetched"})['value']
|
2021-01-18 17:47:17 -05:00
|
|
|
redis_task_fetches = int(r.get(monitor_key))
|
2020-06-03 12:38:11 -04:00
|
|
|
except Exception, e:
|
|
|
|
failed = e
|
|
|
|
|
2021-01-18 17:43:18 -05:00
|
|
|
if feeds_fetched < 5000000 and feeds_fetched <= (redis_task_fetches - FETCHES_DROP_AMOUNT):
|
2020-06-03 12:38:11 -04:00
|
|
|
failed = True
|
2021-01-18 17:43:18 -05:00
|
|
|
|
2020-06-03 12:38:11 -04:00
|
|
|
if failed:
|
|
|
|
requests.post(
|
|
|
|
"https://api.mailgun.net/v2/%s/messages" % settings.MAILGUN_SERVER_NAME,
|
|
|
|
auth=("api", settings.MAILGUN_ACCESS_KEY),
|
2020-06-08 15:11:42 -04:00
|
|
|
data={"from": "NewsBlur Task Monitor: %s <admin@%s.newsblur.com>" % (hostname, hostname),
|
2020-06-03 12:38:11 -04:00
|
|
|
"to": [admin_email],
|
2021-01-18 17:49:12 -05:00
|
|
|
"subject": "%s feeds fetched falling: %s (from %s)" % (hostname, feeds_fetched, redis_task_fetches),
|
|
|
|
"text": "Feed fetches are falling: %s (from %s)" % (feeds_fetched, redis_task_fetches)})
|
2021-01-18 17:45:35 -05:00
|
|
|
|
|
|
|
r.set(monitor_key, feeds_fetched)
|
|
|
|
r.expire(monitor_key, 60*60*3) # 3 hours
|
|
|
|
|
2021-01-18 17:46:52 -05:00
|
|
|
print(" ---> Feeds fetched falling! %s %s" % (feeds_fetched, failed))
|
2020-06-03 12:38:11 -04:00
|
|
|
else:
|
|
|
|
print(" ---> Feeds fetched OK: %s" % (feeds_fetched))
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|