Adding additional metric gathering for failed sync operations. (#488)

This commit is contained in:
kevgliss 2016-11-11 13:28:01 -08:00 committed by GitHub
parent 953d3a08e7
commit 7af68c3cc0
1 changed files with 17 additions and 6 deletions

View File

@ -21,6 +21,7 @@ from flask.ext.migrate import Migrate, MigrateCommand, stamp
from flask_script.commands import ShowUrls, Clean, Server from flask_script.commands import ShowUrls, Clean, Server
from lemur import database from lemur import database
from lemur.extensions import metrics
from lemur.users import service as user_service from lemur.users import service as user_service
from lemur.roles import service as role_service from lemur.roles import service as role_service
from lemur.certificates import service as cert_service from lemur.certificates import service as cert_service
@ -888,6 +889,8 @@ class Sources(Command):
def sync(source): def sync(source):
start_time = time.time() start_time = time.time()
sys.stdout.write("[+] Staring to sync source: {label}!\n".format(label=source.label)) sys.stdout.write("[+] Staring to sync source: {label}!\n".format(label=source.label))
try:
source_service.sync(source) source_service.sync(source)
sys.stdout.write( sys.stdout.write(
"[+] Finished syncing source: {label}. Run Time: {time}\n".format( "[+] Finished syncing source: {label}. Run Time: {time}\n".format(
@ -895,6 +898,14 @@ class Sources(Command):
time=(time.time() - start_time) time=(time.time() - start_time)
) )
) )
except Exception as e:
current_app.logger.exception(e)
sys.stdout.write(
"[X] Failed syncing source {label}!\n".format(labe=source.label)
)
metrics.send('{0}_sync_failed'.format(source.label), 'counter', 1)
@staticmethod @staticmethod
def clean(source): def clean(source):