NewsBlur-viq/utils/monitor_task_fetches.py
Samuel Clay b89e7dc429 Merge branch 'django1.11' into django2.0
* django1.11: (152 commits)
  request.raw_post_data -> request.body (django 1.6)
  Upgrading pgbouncer to 1.15.0.
  Finishing off Postgresql 13 upgrade.
  Upgrading to Postgresql 13.
  Ubuntu 20.04
  Fixing supervisor path issues
  Upgrading setuptools
  Fixing flask
  Handling over capacity for twitter.
  Max length for image_urls.
  Properly filtering newsletter feeds.
  Fixing issue with text importer on feed-less urls.
  Removing dependency, fixing encoding issue for pages.
  Fixing DB Monitor.
  Updating User Agent for all fetchers.
  Ignoring VSCode.
  Fixing DB Monitor.
  Updating User Agent for all fetchers.
  Ignoring VSCode.
  Fixing Statistics by fixing how timezones are handled.
  ...
2020-12-03 14:04:26 -05:00

44 lines
1.5 KiB
Python
Executable file

#!/srv/newsblur/venv/newsblur/bin/python
import sys
sys.path.append('/srv/newsblur')
import subprocess
import requests
import settings
import socket
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
try:
client = pymongo.MongoClient('mongodb://%s' % settings.MONGO_DB['host'])
feeds_fetched = client.newsblur.statistics.find_one({"key": "feeds_fetched"})['value']
except Exception as e:
failed = e
if feeds_fetched < 5000000:
failed = True
if failed:
requests.post(
"https://api.mailgun.net/v2/%s/messages" % settings.MAILGUN_SERVER_NAME,
auth=("api", settings.MAILGUN_ACCESS_KEY),
data={"from": "NewsBlur Task Monitor: %s <admin@%s.newsblur.com>" % (hostname, hostname),
"to": [admin_email],
"subject": "%s feeds fetched falling: %s" % (hostname, feeds_fetched),
"text": "Feed fetches are falling: %s" % (feeds_fetched)})
print(" ---> Feeds fetched falling! %s" % (feeds_fetched))
else:
print(" ---> Feeds fetched OK: %s" % (feeds_fetched))
if __name__ == '__main__':
main()