Beispiel #1
0
    def fetch_mem(self, lines):
        """
        获取 mem 的关键数据包括: 纯物理内存使用率, 包含虚拟内存的内存使用率(无则为0)
        :param lines: 带 mem 关键数据行
        """
        # 解析数据错误行数
        error_num = 0
        mem_sum = float(0)
        mem_virtual_sum = float(0)
        for line in lines:
            mems = line.split(",")
            if len(mems) == 17:
                # (Memtotal - Memfree - cached - buffers)/Memtotal  * 100
                mem_sum += ((float(mems[2]) - float(mems[6]) -
                             float(mems[11]) - float(mems[14])) /
                            float(mems[2]) * 100)
            elif len(mems) == 8:
                # (Real total - Real free)/Real total * 100
                mem_sum += ((float(mems[6]) - float(mems[4])) /
                            float(mems[6]) * 100)
                # (Real total - Real free + Virtual total - Virtual free) /(Real total + Virtual total) * 100
                mem_virtual_sum += ((float(mems[6]) - float(mems[4]) +
                                     float(mems[7]) - float(mems[5])) /
                                    (float(mems[6]) + float(mems[7])) * 100)
            else:
                logger.error("解析服务器ip为 %s 的 %s 监控文件的 MEM 数据出现异常,出现异常行数据为:%s" %
                             (self.ip, self.name, line))
                error_num += 1
                continue

        self.mem = (round(mem_sum / (len(lines) - error_num), 2),
                    round(mem_virtual_sum / (len(lines) - error_num), 2))
        logger.debug("mem: 不含虚拟内存的使用率 %.2f%%, 包含虚拟内存的使用率 %.2f%%" %
                     (self.mem[0], self.mem[1]))
Beispiel #2
0
    def start(self):
        logger.error("*****************************************************")
        self.config = Config.get_instance()
        self.check_dir(self.config.download_local_path)

        # 生成脚本运行命令
        if self.config.type == "1":
            # 判断参数是否填写
            self.check_jmeter_config_param()
            # jmeter 生成脚本命令前, 检查 jmeter 程序是否存在
            self.check_exe()
            script_path = self.config.jmeter_script_dir
            script_file, path = get_all_script(script_path, ".jmx")
            script_command, result_jmeter_file_list = jmeter_cmd(
                script_file, path)
        elif self.config.type == "2":
            self.check_loadrunner_config_param()
            script_path = self.config.loadrunner_script_dir
            script_file, path = get_all_script(script_path, ".lrs")
            script_command, result_analyse_command, result_loadrunner_file_list = lr_cmd(
                script_file, path)
        else:
            raise CustomError("参数type值只能为1或者2,目前值 %s 非法" % self.config.type)

        # 连接后台服务器,运行脚本,开启监控
        self.servers_connect()
        for command in script_command:
            index = script_command.index(command)
            self.servers_start_nmon_control(script_file[index])
            exe_command(command)

        # 下载nmon文件,关闭后台连接
        self.servers_close()

        # 如果是loadrunner需要额外调用命令,解析文件
        if not self.config.loadrunner_script_dir == "" and self.config.jmeter_script_dir == "":
            if len(result_analyse_command) == 0:
                raise CustomError("无法获取 loadrunner 解析命令")
            for command in result_analyse_command:
                exe_command(command)

        self.analyse_nmon(self.servers, self.result_nmon_variable_list)
        if not self.config.jmeter_script_dir == "":
            if len(result_jmeter_file_list) == 0:
                raise CustomError("jmeter 解析时出现异常,找不到结果文件所在路径")
            self.analyse_jmeter(result_jmeter_file_list,
                                self.result_file_analyse_variable_list)
        elif not self.config.loadrunner_script_dir == "":
            if len(result_loadrunner_file_list) == 0:
                raise CustomError("loadrunner 解析时出现异常,找不到结果文件所在路径")
            self.analyse_loadrunner(result_loadrunner_file_list,
                                    self.result_file_analyse_variable_list)
        else:
            raise CustomError("脚本路径不能全为空,解析结果失败")

        report = Report()
        report.get_report(self.result_file_analyse_variable_list,
                          self.result_nmon_variable_list,
                          file_name=self.config.report_name,
                          file_path=self.config.report_path)
Beispiel #3
0
def analyse_loadrunner(loadrunner_file_list, loadrunner_result_list):
    logger.info("开始解析loadrunner文件")

    for loadrunner_file in loadrunner_file_list:
        loadrunner = LoadRunnerAnalyse()
        try:
            loadrunner.file_analyse(loadrunner_file)
        except Exception as e:
            logger.error(e)
            continue
        loadrunner_result_list.append(loadrunner)

    logger.info("解析loadrunner文件结束")
Beispiel #4
0
def analyse_jmeter(jmeter_file_list, jmeter_result_list):
    logger.info("开始解析jmeter文件")

    for jmeter_file in jmeter_file_list:
        jmeter = JmeterAnalyse()
        try:
            jmeter.file_analyse(jmeter_file)
        except Exception as e:
            logger.error(e)
            continue
        jmeter_result_list.append(jmeter)

    logger.info("解析jmeter文件结束")
Beispiel #5
0
 def fetch_cpu(self, lines):
     """
     :param lines: 带 cpu 关键数据行
     """
     # 解析数据错误行数
     error_num = 0
     cpu_sum = float(0)
     for line in lines:
         cpus = line.split(",")
         # sys% datas[2] user datas[3]
         # total = sys + user
         try:
             cpu_sum += (float(cpus[3]) + float(cpus[2]))
         except Exception:
             logger.error("解析服务器ip为 %s 的 %s 监控文件的 cpu 数据出现异常,出现异常行数据为:%s" %
                          (self.ip, self.name, line))
             error_num += 1
     self.cpu = round(cpu_sum / (len(lines) - error_num), 2)
     logger.debug("cpu: %.2f%%" % self.cpu)
Beispiel #6
0
# -*- coding:utf-8 -*-
# @Time    : 2019/8/27 9:58
# @Author  : zengln
# @File    : start.py

from performance_autotest import launch
from performance_autotest.log import logger
import time
import sys
import traceback

"""
    入口脚本
"""

try:
    script_launch = launch.Launch()
    script_launch.start()
except Exception:
    error_msg = traceback.format_exc()
    logger.error(error_msg)
finally:
    time.sleep(1)
    input("按任意键退出")
    sys.exit()
Beispiel #7
0
    logger.info("开始解析loadrunner文件")

    for loadrunner_file in loadrunner_file_list:
        loadrunner = LoadRunnerAnalyse()
        try:
            loadrunner.file_analyse(loadrunner_file)
        except Exception as e:
            logger.error(e)
            continue
        loadrunner_result_list.append(loadrunner)

    logger.info("解析loadrunner文件结束")


try:
    logger.error("*****************************************************")
    config = Config.get_instance()
    # 保存结果文件路径
    result_jmeter_file_list = []
    result_loadrunner_file_list = []

    # 保存解析文件结果
    result_nmon_variable_list = []
    result_file_analyse_variable_list = []

    check_dir(config.download_local_path)

    # 生成脚本运行命令
    if not config.jmeter_script_dir == "":
        # jmeter 生成脚本命令前, 检查 jmeter 程序是否存在
        check_exe()