Last active
December 6, 2019 20:42
-
-
Save remitaffin/942070bbda784531784eea695381b694 to your computer and use it in GitHub Desktop.
python tail_mongos.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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