Skip to content

Instantly share code, notes, and snippets.

@remitaffin
Last active December 6, 2019 20:42
Show Gist options
  • Save remitaffin/942070bbda784531784eea695381b694 to your computer and use it in GitHub Desktop.
Save remitaffin/942070bbda784531784eea695381b694 to your computer and use it in GitHub Desktop.
python tail_mongos.py
import os
import subprocess
import statsd
filename = '/var/log/mongo/mongos.log'
graphite_host = 'statsd.hostedgraphite.com'
graphite_api_key = os.environ['GRAPHITE_API_KEY']
f = subprocess.Popen(
['tail', '-F', filename],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
statsd_client = statsd.StatsClient(
host=graphite_host,
port=8125,
prefix='{}.logs'.format(graphite_api_key)
)
while True:
try:
line = f.stdout.readline()
if 'DBException in process: socket exception [SEND_ERROR]' in line:
statsd_client.incr(stat='mongos.exception.socket')
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment