Created
October 26, 2014 05:42
-
-
Save seckcoder/d68c6107766cee9ac60c to your computer and use it in GitHub Desktop.
send_mysql_metric
This file contains 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
__author__ = 'seckcoder' | |
import config | |
import boto.ec2.cloudwatch | |
import subprocess | |
import time | |
from datetime import datetime | |
region = "us-east-1" | |
cw = boto.ec2.cloudwatch.connect_to_region(region) | |
metric_base = { | |
"namespace" : 'SECK/EC2', | |
"name" : 'TPSUtilization', | |
"unit" : "Percent", | |
"dimensions" : {"AutoScalingGroupName" : "seck-asg"} | |
} | |
max_tps = 500 | |
def sendTPS(tps): | |
cf = metric_base.copy() | |
print tps | |
cf.update(value = (float(tps) / float(max_tps)) * 100, | |
timestamp = datetime.utcnow()) | |
cw.put_metric_data(**cf) | |
prev_queries = None | |
prev_uptime = None | |
while True: | |
try: | |
output = subprocess.check_output("mysql -u echo -p15319 -e \"show status like 'Queries'; show status like 'Uptime';\"", shell=True) | |
groups = output.split() | |
queries = int(groups[3]) | |
uptime = int(groups[7]) | |
if prev_queries is not None: | |
tps = (queries - 4 - prev_queries) / (uptime - prev_uptime) | |
sendTPS(tps) | |
prev_queries = queries | |
prev_uptime = uptime | |
# tps = int(output.split()[3]) | |
time.sleep(1) | |
except KeyboardInterrupt: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment