Skip to content

Commit

Permalink
analysis task result
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa0128 committed Sep 19, 2023
1 parent 5d12bd1 commit 7794e08
Show file tree
Hide file tree
Showing 16 changed files with 660 additions and 54 deletions.
6 changes: 3 additions & 3 deletions webmeter/core/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import datetime
import json
from loguru import logger
from core.utils import Common
from core.sqlhandle import crud
from core.task import TaskBase
from webmeter.core.utils import Common
from webmeter.core.sqlhandle import crud
from webmeter.core.task import TaskBase

class EngineServie(TaskBase):

Expand Down
2 changes: 1 addition & 1 deletion webmeter/core/plan.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import shutil
from loguru import logger
from core.utils import Common, JMX
from webmeter.core.utils import Common, JMX
from fastapi import UploadFile

class Base(object):
Expand Down
9 changes: 0 additions & 9 deletions webmeter/core/result.py

This file was deleted.

24 changes: 17 additions & 7 deletions webmeter/core/sqlhandle/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Optional
from loguru import logger
import os, shutil, datetime
from core.plan import TestPlan
from webmeter.core.plan import TestPlan

def create_task(tasks: dict):
with database.dbConnect() as session:
Expand Down Expand Up @@ -32,21 +32,31 @@ def update_task(tasks: dict):
else:
raise Exception('{} is not existed'.format(result.task))

def query_task_one(tasks: schemas.taskQuery):
def query_task_one(plan: str, task: str) -> dict:
with database.dbConnect() as session:
results = session.query(models.Task).filter(models.Task.plan == tasks.plan).all()
result_dict = [result.task for result in results]
results = session.query(models.Task).filter(models.Task.plan == plan,
models.Task.task == task).first()
result_dict = dict()
result_dict['plan'] = results.plan
result_dict['task'] = results.task
result_dict['model'] = results.model
result_dict['status'] = results.status
result_dict['threads'] = results.threads
result_dict['success_num'] = results.success_num
result_dict['fail_num'] = results.fail_num
result_dict['stime'] = results.stime
result_dict['etime'] = results.etime
return result_dict

def query_task_all():
def query_task_all() -> list:
with database.dbConnect() as session:
results = session.query(models.Task).order_by(models.Task.stime.desc()).all()
result_dict = [{'plan': result.plan, 'task':result.task,
result_list = [{'plan': result.plan, 'task':result.task,
'model': result.model, 'status': result.status,
'threads': result.threads, 'success_num': result.success_num,
'fail_num': result.fail_num, 'stime': result.stime,
'etime': result.etime} for result in results]
return result_dict
return result_list

def remove_task_one(plan: str, task: str):
logger.warning('remove task data : {}'.format(task))
Expand Down
2 changes: 1 addition & 1 deletion webmeter/core/sqlhandle/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from contextlib import contextmanager
from loguru import logger
import os
from core.utils import Common
from webmeter.core.utils import Common

SQL_DIR = Common.make_dir(os.path.join(os.getcwd(), 'webmeter'))
SQLALCHEMY_DATABASE_URL = "sqlite:///{}/webmeter_app.db".format(SQL_DIR)
Expand Down
2 changes: 1 addition & 1 deletion webmeter/core/sqlhandle/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sqlalchemy import Boolean, Column, Integer, String, DateTime, Float
from core.sqlhandle.database import Base
from webmeter.core.sqlhandle.database import Base
import datetime


Expand Down
37 changes: 33 additions & 4 deletions webmeter/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import json, os
from core.utils import Common
from typing import Optional
from webmeter.core.sqlhandle import crud


class TaskBase(object):

Expand All @@ -18,21 +20,48 @@ def read_statistics_file(cls, plan: str, task: str) -> dict:
raise Exception('No content found in the statistics.json')

@classmethod
def read_result_file(cls, plan: str, task: str):
def read_result_file(cls, plan: str, task: str) -> list:
"""read result.jtl content"""
result_file_path = os.path.join(cls.ROOT_DIR, plan, 'report', task,'result.jtl')
content = Common.read_file_content(result_file_path)
if content:
content = Common.read_file_lines(result_file_path)
if content.__len__() > 0:
return content
else:
raise Exception('No content found in the result.jtl')

@classmethod
def read_log(cls, plan: str, task: str) -> Optional[str]:
def read_log_file(cls, plan: str, task: str) -> Optional[str]:
"""read result.log content"""
log_file_path = os.path.join(cls.ROOT_DIR, plan, 'log', task,'result.log')
content = Common.read_file_content(log_file_path)
if content:
return content
else:
raise Exception('No content found in the result.log')

class TaskDetail(TaskBase):

@classmethod
def getTestAndReportInfo(cls, plan: str, task: str) -> dict:
result = dict()
summary_dict = crud.query_task_one(plan, task)
result['source_file'] = os.path.join(TaskBase.ROOT_DIR, plan, 'report', task, 'result.jtl')
result['stime'] = summary_dict.get('stime')
result['etime'] = summary_dict.get('etime')
return result

@classmethod
def getRequestSummary(cls, plan: str, task: str) -> list:
jtlContent = TaskBase.read_result_file(plan, task)
jtlContent.pop(0)
jtlList = [{'lable':item.split(',')[2],
'responseCode':item.split(',')[3],
'responseMessage':item.split(',')[4],
'threadName': item.split(',')[5],
'failureMessage':item.split(',')[8],
'bytes': item.split(',')[9],
'sentBytes': item.split(',')[10],
'allThreads':item.split(',')[12],
'URL': item.split(',')[13]} for item in jtlContent]
return jtlList

8 changes: 7 additions & 1 deletion webmeter/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ def make_dir_file(cls, dir : str, filename: str, content: str) -> str:
def read_file_content(cls, file_path) -> str:
with open(file=file_path, mode='r', encoding='utf-8') as f:
content = f.read()
return content
return content

@classmethod
def read_file_lines(cls, file_path) -> list:
with open(file=file_path, mode='r', encoding='utf-8') as f:
content = f.readlines()
return content

@classmethod
def pc_platform(cls) -> Optional[str]:
Expand Down
44 changes: 44 additions & 0 deletions webmeter/static/js/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

const getLocationParams = () => {
let href = window.location.href;
let query = href.substring(href.indexOf("?") + 1);
let vars = query.split("&");
let obj = {};
for (let i = 0; i < vars.length; i++) {
let pair = vars[i].split("=");
obj[pair[0]] = pair[1];
}
return obj;
};


const elMessage = (type, message) => {
switch(type){
case 'success':
ElementPlus.ElMessage({
showClose: true,
message: message,
type: 'success',
})
break;
case 'warning':
ElementPlus.ElMessage({
showClose: true,
message: message,
type: 'warning',
})
break;
case 'error':
ElementPlus.ElMessage({
showClose: true,
message: message,
type: 'error',
})
break;
default:
ElementPlus.ElMessage({
showClose: true,
message: message,
})
};
}
4 changes: 2 additions & 2 deletions webmeter/static/js/lan.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const ENGLISH = {
'plan_page_title':'TEST PLAN',
'result_page_title':'TEST RESULT',
'task_page_title':'TASK RESULT',
'monitor': 'Monitor',
'star_me': 'Star Me',
'documentation': 'Documentation',
Expand Down Expand Up @@ -61,7 +61,7 @@ const ENGLISH = {

const CHINESE = {
'plan_page_title':'测试计划',
'result_page_title':'测试结果',
'task_page_title':'任务管理',
'monitor': '资源监控',
'star_me': 'Github点赞',
'documentation': '文档',
Expand Down
487 changes: 487 additions & 0 deletions webmeter/templates/analysis.html

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions webmeter/templates/plan.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


<!doctype html>
<!--
* WebMeter - A web api-performance tool based on jmeter.
Expand Down Expand Up @@ -46,7 +47,7 @@ <h1 class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-m
<span class="nav-link-icon d-md-none d-lg-inline-block">
<svg t="1690875909592" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="26542" width="320" height="320"><path d="M244.224 370.78016h526.336c48.64 0 87.552 39.424 87.552 87.552v292.352c0 48.64-39.424 87.552-87.552 87.552H244.224c-48.64 0-87.552-39.424-87.552-87.552v-292.352c-0.512-48.128 38.912-87.552 87.552-87.552z" fill="#CAE4FF" p-id="26543"></path><path d="M760.832 983.30624H245.76c-114.176 0-206.848-92.672-206.848-206.848v-357.888c0-114.176 92.672-206.336 206.848-206.848h515.072c114.176 0 206.336 92.672 206.848 206.848v357.888c0 114.176-92.672 206.848-206.848 206.848zM245.76 270.09024c-81.92 0-148.48 66.56-148.48 148.48v357.888c0 81.92 66.56 148.48 148.48 148.48h515.072c81.92 0 148.48-66.56 148.48-148.48v-357.888c0-81.92-66.56-148.48-148.48-148.48H245.76z" fill="#0972E7" p-id="26544"></path><path d="M303.616 748.29824c0.512 14.848-11.264 27.648-26.112 28.16-14.848 0.512-27.648-11.264-28.16-26.112v-291.328c0.512-14.848 13.312-26.624 28.16-26.112 14.336 0.512 25.6 11.776 26.112 26.112v289.28z" fill="#0972E7" p-id="26545"></path><path d="M742.912 758.53824c0 13.824-11.264 25.088-25.088 25.088H274.432c-13.824 0.512-25.6-9.728-26.112-23.552-0.512-13.824 9.728-25.6 23.552-26.112h446.464c13.312 0 24.576 11.264 24.576 24.576z m-261.12-224.768c-9.728-10.24-26.112-10.24-36.352-0.512l-78.848 79.36c-10.24 10.24-10.24 26.624 0 36.864 9.728 10.24 26.112 10.24 36.352 0.512l79.36-78.848c9.728-10.752 9.728-27.136-0.512-37.376z" fill="#0972E7" p-id="26546"></path><path d="M564.736 648.97024c10.24-9.728 10.24-26.112 0-36.352l-79.36-78.848c-10.24-10.24-26.624-10.24-36.864 0-10.24 9.728-10.24 26.112 0 36.352l78.848 78.848c10.752 10.24 27.136 10.24 37.376 0z" fill="#0972E7" p-id="26547"></path><path d="M649.216 533.77024c-9.728-10.24-26.112-10.24-36.352-0.512l-79.36 78.848c-10.24 10.24-10.24 26.624 0 36.864 9.728 10.24 26.112 10.24 36.352 0.512l79.36-78.848c9.728-10.24 9.728-26.624 0-36.864z" fill="#0972E7" p-id="26548"></path><path d="M714.24 468.74624c-9.728-10.24-26.112-10.24-36.352-0.512l-79.36 78.848c-10.24 10.24-10.24 26.624 0 36.864 9.728 10.24 26.112 10.24 36.352 0.512l79.36-78.848c10.24-10.24 10.24-27.136 0-36.864zM97.792 404.74624H39.936c0-51.2-0.512-120.832-0.512-120.832 0-112.128 91.136-203.264 203.264-203.264h136.704c123.392 0 194.56 66.56 194.56 182.784h-57.856c0-83.968-44.544-124.928-136.192-124.928H242.688c-80.384 0-145.408 65.024-145.408 145.408 0 0 0.512 69.632 0.512 120.832z" fill="#0972E7" p-id="26549"></path></svg>
</span>
<span class="nav-link-title strong-text" v-text="language.result_page_title"></span>
<span class="nav-link-title strong-text" v-text="language.task_page_title"></span>
<span class="status-dot status-dot-animated bg-red d-block" style="margin-left: 5px;" v-if="redPointer"></span>
</a>
</li>
Expand Down Expand Up @@ -516,7 +517,7 @@ <h4>
</li>
<li class="list-inline-item">
<a href="https://github.com/smart-test-ti/webmeter/releases" target="_blank" class="link-secondary" rel="noopener">
<label v-text="language.release"></label> . V1.0.0
<a href="https://pypi.org/project/webmeter/" target="__blank"><img src="https://img.shields.io/pypi/v/webmeter" alt="webmeter preview"></a>
</a>
</li>
</ul>
Expand Down
Loading

0 comments on commit 7794e08

Please sign in to comment.