From bd11a68114ec3ee583f10d79aeae220a4151eb02 Mon Sep 17 00:00:00 2001 From: chenhq Date: Fri, 3 Nov 2023 11:29:52 +0800 Subject: [PATCH] v1.0.14 --- webmeter/core/engine.py | 8 +- webmeter/core/plan.py | 2 +- webmeter/core/sqlhandle/crud.py | 4 +- webmeter/core/sqlhandle/database.py | 2 +- webmeter/core/sqlhandle/models.py | 4 +- webmeter/core/task.py | 4 +- webmeter/core/utils.py | 1 - webmeter/templates/analysis.html | 175 ++++++++++++++++++++++++++- webmeter/templates/config.html | 180 +++++++++++++++++++++++++++- webmeter/templates/result.html | 174 ++++++++++++++++++++++++++- webmeter/view/api.py | 12 +- webmeter/view/page.py | 2 +- webmeter/webmeter/app.db | Bin 98304 -> 0 bytes webmeter/webmeter/plan01/plan.jmx | 52 -------- 14 files changed, 540 insertions(+), 80 deletions(-) delete mode 100644 webmeter/webmeter/app.db delete mode 100644 webmeter/webmeter/plan01/plan.jmx diff --git a/webmeter/core/engine.py b/webmeter/core/engine.py index 5c39aaa..6fd3c2e 100644 --- a/webmeter/core/engine.py +++ b/webmeter/core/engine.py @@ -1,9 +1,9 @@ import os import datetime from loguru import logger -from core.utils import Common, Platform -from core.sqlhandle import crud -from core.task import TaskBase +from webmeter.core.utils import Common, Platform +from webmeter.core.sqlhandle import crud +from webmeter.core.task import TaskBase class EngineServie(TaskBase): @@ -68,7 +68,7 @@ def run(cls, content: dict, remote=False) -> int: crud.create_task(tasks={ 'plan': content.get('plan_name'), 'task': task_format, - 'model': 'stand-alone', + 'model': 'local', 'threads': int(content.get('threads')) }) result = Common.exec_cmd('{jmeter} -n -t {jmx_path} -l {jtl_path} -j {log_path} -e -o {report_path}'.format( diff --git a/webmeter/core/plan.py b/webmeter/core/plan.py index 6b87fc9..f3b749b 100644 --- a/webmeter/core/plan.py +++ b/webmeter/core/plan.py @@ -2,7 +2,7 @@ import shutil from loguru import logger from fastapi import UploadFile -from core.utils import Common, JMX +from webmeter.core.utils import Common, JMX class Base(object): diff --git a/webmeter/core/sqlhandle/crud.py b/webmeter/core/sqlhandle/crud.py index 1f5d5bd..802469e 100644 --- a/webmeter/core/sqlhandle/crud.py +++ b/webmeter/core/sqlhandle/crud.py @@ -1,8 +1,8 @@ from typing import Optional from loguru import logger import os, shutil, datetime -from core.sqlhandle import models, schemas, database -from core.plan import TestPlan +from webmeter.core.sqlhandle import models, schemas, database +from webmeter.core.plan import TestPlan def create_task(tasks: dict): with database.dbConnect() as session: diff --git a/webmeter/core/sqlhandle/database.py b/webmeter/core/sqlhandle/database.py index bd0c790..f4ad2d0 100644 --- a/webmeter/core/sqlhandle/database.py +++ b/webmeter/core/sqlhandle/database.py @@ -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:///{}/app.db".format(SQL_DIR) diff --git a/webmeter/core/sqlhandle/models.py b/webmeter/core/sqlhandle/models.py index f670117..c0af31e 100644 --- a/webmeter/core/sqlhandle/models.py +++ b/webmeter/core/sqlhandle/models.py @@ -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 class Task(Base): @@ -8,7 +8,7 @@ class Task(Base): id = Column(Integer, primary_key=True, index=True) plan = Column(String, index=True) task = Column(String, index=True, unique=True) - model = Column(String, index=True, default='stand-alone') #stand-alone | distributed + model = Column(String, index=True, default='local') #local | remote success_num = Column(Integer, index=True, default=0) fail_num = Column(Integer, index=True, default=0) threads = Column(Integer, index=True, default=1) diff --git a/webmeter/core/task.py b/webmeter/core/task.py index 5f6dfeb..dd47629 100644 --- a/webmeter/core/task.py +++ b/webmeter/core/task.py @@ -1,8 +1,8 @@ from loguru import logger import json, os from typing import Optional -from core.utils import Common -from core.sqlhandle import crud +from webmeter.core.utils import Common +from webmeter.core.sqlhandle import crud class TaskBase(object): diff --git a/webmeter/core/utils.py b/webmeter/core/utils.py index 5261740..ccbfd35 100644 --- a/webmeter/core/utils.py +++ b/webmeter/core/utils.py @@ -3,7 +3,6 @@ from enum import Enum, unique import platform import psutil -import time from loguru import logger from xml.etree import ElementTree from typing import Optional diff --git a/webmeter/templates/analysis.html b/webmeter/templates/analysis.html index 00c95c5..9884196 100644 --- a/webmeter/templates/analysis.html +++ b/webmeter/templates/analysis.html @@ -52,7 +52,7 @@

- + @@ -326,13 +326,49 @@

+
+
+

+ + Monitor +

+ +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + + + @@ -361,12 +397,59 @@

const connectOverTime = reactive([]) const latencyOverTime = reactive([]) const statisticsJson = ref({}) + + //monitor + const cpuChart = ref() + const memoryChart = ref() + const monitorStatus = ref(false) + const monitorStartBtn = ref(true) + const monitorStopBtn = ref(false) + + const rangeSelector = { + buttons: [{ + count: 1, + type: 'minute', + text: '1min' + }, { + count: 5, + type: 'minute', + text: '5min' + }, { + type: 'all', + text: 'All' + }], + inputEnabled: false, + selected: 1 + }; + + const series = [{ + name : 'value', + pointInterval: 120 * 1000, + data : (function () { + var data = [], time = (new Date()).getTime(), i; + for (i = -999; i <= 0; i += 1) { + data.push([ + time + i * 1000, + Math.round(0) + ]); + } + return data; + }()) + }]; onBeforeMount(() => { getLanguage() + hljs.highlightAll(); + Highcharts.setOptions({ + global : { + useUTC : false + } + }); }); onMounted(() => { + cpuChart.value = chartsInitialize('cpu', 'CPU (%)') + memoryChart.value = chartsInitialize('memory', 'Memory (%)') getTestAndReportInfo() getRequestSummaryInfo() getStatisticsInfo() @@ -375,6 +458,87 @@

initLatencyOverTimeChart() }); + const chartsInitialize = (target,title) => { + let seriesFinal = series; + let legend = false; + let yAxis = { + opposite:false, + }; + let charts = Highcharts.stockChart(target, { + rangeSelector: rangeSelector, + title : { + text : title + }, + tooltip: { + split: false + }, + legend: { + enabled:legend + }, + credits:{ + enabled: false + }, + scrollbar : { + enabled : true + }, + navigator : { + enabled : false + }, + exporting: { + enabled: false + }, + yAxis: yAxis, + series : seriesFinal + }); + return charts + }; + + const startMonitor = () => { + monitorStatus.value = true + monitorStopBtn.value = true + monitorStartBtn.value = false + monitorMachineCPU() + monitorMachineMemory() + } + const monitorMachineCPU = () => { + axios.post('/api/monitor/cpu', {}) + .then(function (response) { + if(response['data']['status'] == 1 && monitorStatus.value == true){ + var series = cpuChart.value.series[0] + var x = (new Date()).getTime() + var y = response['data']['data'] + series.addPoint([x, y], true, true) + setTimeout(monitorMachineCPU(), 2000) + } + console.log(response); + }).catch(function (error) { + console.log(error); + }); + } + + const monitorMachineMemory = () => { + axios.post('/api/monitor/memory', {}) + .then(function (response) { + if(response['data']['status'] == 1 && monitorStatus.value == true){ + var series = memoryChart.value.series[0] + var x = (new Date()).getTime() + var y = response['data']['data'] + series.addPoint([x, y], true, true) + setTimeout(monitorMachineMemory(), 2000) + } + console.log(response); + }).catch(function (error) { + console.log(error); + }); + } + + + const stopMonitor = () => { + monitorStatus.value = false + monitorStopBtn.value = false + monitorStartBtn.value = true + } + const screenShot = (classname, downloadname) => { let container = document.getElementsByClassName(classname); html2canvas(container[0]).then(canvas => { @@ -692,11 +856,18 @@

connectOverTime, latencyOverTime, statisticsJson, + + //monitor + monitorStartBtn, + monitorStopBtn, + screenShot, setLanguage, initResponseOverTimeChart, initConnectOverTimeChart, - initLatencyOverTimeChart + initLatencyOverTimeChart, + startMonitor, + stopMonitor }; } }); diff --git a/webmeter/templates/config.html b/webmeter/templates/config.html index eb951c2..c6dca52 100644 --- a/webmeter/templates/config.html +++ b/webmeter/templates/config.html @@ -54,7 +54,7 @@

- + @@ -176,6 +176,40 @@

+
+

+ + Monitor +

+ +
+
+ +
+
+
+
+
+
+
+
+
+
+
+ + + @@ -184,6 +218,8 @@

+ + @@ -207,14 +243,143 @@

- + @@ -250,6 +250,38 @@

Are you sure?

+
+
+

+ + Monitor +

+ +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+