2021-06-19 09:56:35 -06:00
|
|
|
#!/usr/local/bin/python3
|
2020-06-03 12:38:11 -04:00
|
|
|
|
|
|
|
import sys
|
|
|
|
sys.path.append('/srv/newsblur')
|
|
|
|
|
|
|
|
import requests
|
2021-05-26 11:41:28 -04:00
|
|
|
from newsblur_web 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():
|
|
|
|
hostname = socket.gethostname()
|
|
|
|
admin_email = settings.ADMINS[0][1]
|
|
|
|
failed = False
|
|
|
|
feeds_fetched = 0
|
2021-10-06 10:46:29 -04:00
|
|
|
FETCHES_DROP_AMOUNT = 100000
|
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:
|
2021-07-14 22:09:47 -04:00
|
|
|
client = pymongo.MongoClient(f"mongodb://{settings.MONGO_DB['username']}:{settings.MONGO_DB['password']}@{settings.MONGO_DB['host']}/?authSource=admin")
|
2020-06-03 12:38:11 -04:00
|
|
|
feeds_fetched = client.newsblur.statistics.find_one({"key": "feeds_fetched"})['value']
|
2021-01-22 19:31:49 -05:00
|
|
|
redis_task_fetches = int(r.get(monitor_key) or 0)
|
2020-06-19 02:27:48 -04:00
|
|
|
except Exception as e:
|
2020-06-03 12:38:11 -04:00
|
|
|
failed = e
|
|
|
|
|
2021-07-14 22:09:47 -04:00
|
|
|
if feeds_fetched < 5000000 and not failed:
|
2021-06-24 11:19:45 -04:00
|
|
|
if redis_task_fetches > 0 and feeds_fetched < (redis_task_fetches - FETCHES_DROP_AMOUNT):
|
2021-03-09 17:04:01 -05:00
|
|
|
failed = True
|
2021-10-06 10:07:21 -04:00
|
|
|
# Ignore 0's below, as they simply imply low number, not falling
|
|
|
|
# elif redis_task_fetches <= 0:
|
|
|
|
# failed = True
|
2021-06-24 11:24:59 -04:00
|
|
|
if failed:
|
2020-06-03 12:38:11 -04:00
|
|
|
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),
|
2021-01-20 21:25:01 -05:00
|
|
|
"text": "Feed fetches are falling: %s (from %s) %s" % (feeds_fetched, redis_task_fetches, failed)})
|
2021-01-18 17:45:35 -05:00
|
|
|
|
|
|
|
r.set(monitor_key, feeds_fetched)
|
2021-07-08 15:39:29 -04:00
|
|
|
r.expire(monitor_key, 60*60*12) # 3 hours
|
2021-01-18 17:45:35 -05:00
|
|
|
|
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()
|