in redshift_monitoring.py [0:0]
def run_external_commands(command_set_type, file_name, cursor, cluster):
if not os.path.exists(file_name):
return []
external_commands = None
try:
external_commands = json.load(open(file_name, 'r'))
except ValueError as e:
# handle a malformed user query set gracefully
if e.message == "No JSON object could be decoded":
return []
else:
raise
output_metrics = []
for command in external_commands:
if command['type'] == 'value':
cmd_type = "Query"
else:
cmd_type = "Canary"
print("Executing %s %s: %s" % (command_set_type, cmd_type, command['name']))
try:
t = datetime.datetime.now()
interval = run_command(cursor, command['query'])
value = cursor.fetchone()[0]
if value is None:
value = 0
# append a cloudwatch metric for the value, or the elapsed interval, based upon the configured 'type' value
if command['type'] == 'value':
output_metrics.append({
'MetricName': command['name'],
'Dimensions': [
{'Name': 'ClusterIdentifier', 'Value': cluster}
],
'Timestamp': t,
'Value': value,
'Unit': command['unit']
})
else:
output_metrics.append({
'MetricName': command['name'],
'Dimensions': [
{'Name': 'ClusterIdentifier', 'Value': cluster}
],
'Timestamp': t,
'Value': interval,
'Unit': 'Milliseconds'
})
except Exception as e:
print("Exception running external command %s" % command['name'])
print(e)
return output_metrics