~veebers/juju-ci-tools/perf-initial-heatmap-details

« back to all changes in this revision

Viewing changes to assess_perf_test_simple.py

  • Committer: Christopher Lee
  • Date: 2016-07-25 05:15:13 UTC
  • Revision ID: chris.lee@canonical.com-20160725051513-gjdq2psihed0pkse
Start mongostat collection as different command. Work around lxd/mysql issue.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import argparse
7
7
from collections import defaultdict, namedtuple
8
8
from datetime import datetime
9
 
from jinja2 import Template
10
9
import logging
11
10
import os
12
11
import sys
15
14
from textwrap import dedent
16
15
 
17
16
import rrdtool
 
17
from jinja2 import Template
18
18
from fixtures import EnvironmentVariable
19
19
 
20
20
from deploy_stack import (
191
191
    with bs_manager.booted_context(upload_tools):
192
192
        try:
193
193
            client = bs_manager.client
 
194
            # Work around mysql charm wanting 80% memory.
 
195
            if client.env.get_cloud() == 'lxd':
 
196
                constraint_cmd = [
 
197
                    'lxc',
 
198
                    'profile',
 
199
                    'set',
 
200
                    'juju-{}'.format(client.env.environment),
 
201
                    'limits.memory',
 
202
                    '2GB'
 
203
                ]
 
204
                subprocess.check_output(constraint_cmd)
194
205
            admin_client = client.get_admin_client()
195
206
            admin_client.wait_for_started()
196
207
            bs_end = datetime.utcnow()
209
220
                 results_dir)
210
221
            )
211
222
 
212
 
            admin_client.juju(
213
 
                'scp', ('0:/tmp/mongodb-stats.log', results_dir)
214
 
            )
 
223
            try:
 
224
                admin_client.juju(
 
225
                    'scp', ('0:/tmp/mongodb-stats.log', results_dir)
 
226
                )
 
227
            except subprocess.CalledProcessError as e:
 
228
                log.error('Failed to copy mongodb stats: {}'.format(e))
215
229
            cleanup_start = datetime.utcnow()
216
230
    # Cleanup happens when we move out of context
217
231
    cleanup_end = datetime.utcnow()
381
395
 
382
396
def generate_mongo_graph_image(results_dir):
383
397
    dest_path = os.path.join(results_dir, 'mongodb')
384
 
    create_mongodb_rrd_file(results_dir, dest_path)
 
398
 
 
399
    if not create_mongodb_rrd_file(results_dir, dest_path):
 
400
        return None
385
401
    return generate_graph_image(
386
402
        results_dir, 'mongodb', create_mongodb_report_graph)
387
403
 
394
410
def create_mongodb_rrd_file(results_dir, destination_dir):
395
411
    os.mkdir(destination_dir)
396
412
    source_file = os.path.join(results_dir, 'mongodb-stats.log')
 
413
 
 
414
    if not os.path.exists(source_file):
 
415
        log.warning(
 
416
            'Not creating mongodb rrd. Source file not found ({})'.format(
 
417
                source_file))
 
418
        return False
 
419
 
397
420
    dest_file = os.path.join(destination_dir, 'mongodb.rrd')
398
421
 
399
422
    first_ts, last_ts, all_data = get_mongodb_stat_data(source_file)
417
440
            u=int(entry[3]),
418
441
            d=int(entry[4]))
419
442
        rrdtool.update(dest_file, update_details)
 
443
    return True
420
444
 
421
445
 
422
446
def get_mongodb_stat_data(log_file):
722
746
        'sudo apt-get update',
723
747
        'sudo apt-get install --yes --allow-unauthenticated mongodb-org-tools daemon',
724
748
        'sudo chmod +x /tmp/runner.sh',
725
 
        'daemon /tmp/runner.sh',
726
749
    ]
727
750
    full_command = " && ".join(commands)
728
751
    admin_client.juju('ssh', ('0', '--', full_command))
729
752
 
730
 
    # create rrd database.
731
 
    # values for insert, query, update, delete. (then maybe vsize, res?
732
 
    # netin/netout)
733
 
    # for line in stat_json:
734
 
    #     convert line to epoch seconds
 
753
    # Start collection
 
754
    admin_client.juju('ssh', ('0', '--', 'daemon /tmp/runner.sh'))
735
755
 
736
756
 
737
757
def parse_args(argv):