forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws_plot.py
89 lines (74 loc) · 2.45 KB
/
aws_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Copyright (c) Facebook, Inc. and its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""
Make plots on AWS as installing Matplotlib on macOS is a pain.
Then downloads parsed logs.
"""
from fabric.api import run, roles, execute, task, put, env, local, sudo, settings, get
from fabric.contrib import files
import boto3
from botocore.exceptions import ClientError
import os
ec2 = boto3.client('ec2')
region = os.environ.get("AWS_EC2_REGION")
env.user = 'ubuntu'
env.key_filename = '~/.ssh/aws-fb.pem' # SET PATH TO KEY FILE HERE
"""
Initialise hosts, this command is run in conjunction with other commands.
COMMANDS: fab -f aws_plot.py set_hosts <COMMAND>
"""
instances_id = [] # automatically filled by 'set_hosts'
env.roledefs = {'dev': [], } # automatically filled by 'set_hosts'
def set_hosts(value ='running', instance_type='dev', region=region):
ec2resource = boto3.resource('ec2')
instances = ec2resource.instances.filter(Filters=[{'Name': 'instance-state-name', 'Values': [value]}])
for instance in instances:
for tag in instance.tags or []:
if 'Name'in tag['Key']:
name = tag['Value']
if instance_type in name:
instances_id.append(instance.id)
env.roledefs['dev'].append(instance.public_ip_address)
"""
Print commands to ssh into hosts (debug).
COMMANDS: fab -f aws_plot.py info
"""
def info():
set_hosts()
print('\ndev:')
for dev in env.roledefs['dev']:
print('\t ssh -i '+env.key_filename+' '+env.user+'@'+dev)
"""
Parse logs and create plots; then donwloads plots and parsed logs.
COMMANDS: fab -f aws_plot.py set_hosts clean
fab -f aws_plot.py set_hosts throughput
fab -f aws_plot.py set_hosts latency
"""
tps_script = 'throughput.py'
tps_raw_logs = 'raw_logs/*'
latency_script = 'latency.py'
latency_raw_logs = 'latency_raw_logs/*'
subdir = 'fastpay/'
@roles('dev')
def clean():
run('rm -r '+subdir+'* || true')
#put(tps_raw_logs, subdir+'.')
#put(latency_raw_logs, subdir+'.')
@roles('dev')
def throughput():
put(tps_script, subdir+'.')
#put('aggregated_parsed_logs/*tps*', subdir+'.')
run('(cd '+subdir+' && python3 throughput.py)')
if files.exists(subdir+'*aggregated*'):
get(subdir+'*aggregated*', '.')
get(subdir+'*.pdf', '.')
local('open *.pdf')
@roles('dev')
def latency():
put(latency_script, subdir+'.')
#put(latency_raw_logs, subdir+'.')
run('(cd '+subdir+' && python3 %s plot)' % latency_script)
if files.exists(subdir+'*aggregated*'):
get(subdir+'*aggregated*', '.')
get(subdir+'*.pdf', '.')
local('open latency*.pdf')