Skip to content

Commit

Permalink
v1.0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa0128 committed Nov 3, 2023
1 parent 2041fd2 commit bd11a68
Show file tree
Hide file tree
Showing 14 changed files with 540 additions and 80 deletions.
8 changes: 4 additions & 4 deletions webmeter/core/engine.py
Original file line number Diff line number Diff line change
@@ -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):

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion webmeter/core/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions webmeter/core/sqlhandle/crud.py
Original file line number Diff line number Diff line change
@@ -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:
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:///{}/app.db".format(SQL_DIR)
Expand Down
4 changes: 2 additions & 2 deletions 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


class Task(Base):
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions webmeter/core/task.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
1 change: 0 additions & 1 deletion webmeter/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
175 changes: 173 additions & 2 deletions webmeter/templates/analysis.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h1 class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-m
</div>
</div>
<div class="nav-item dropdown d-none d-md-flex me-3">
<a class="btn btn-pill w-100">
<a class="btn btn-pill w-100" data-bs-toggle="offcanvas" href="#offcanvasBottom" role="button" aria-controls="offcanvasBottom">
<svg t="1692319746964" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="51522" width="320" height="320"><path d="M815.2576 795.3408H208.7424c-73.4208 0-133.12-59.6992-133.12-133.12V218.624c0-73.4208 59.6992-133.12 133.12-133.12h606.5664c73.4208 0 133.12 59.6992 133.12 133.12v443.5968c-0.0512 73.4208-59.7504 133.12-133.1712 133.12zM208.7424 146.944c-39.5264 0-71.68 32.1536-71.68 71.68v443.5968c0 39.5264 32.1536 71.68 71.68 71.68h606.5664c39.5264 0 71.68-32.1536 71.68-71.68V218.624c0-39.5264-32.1536-71.68-71.68-71.68H208.7424zM706.2016 945.4592H317.7984c-16.9472 0-30.72-13.7728-30.72-30.72s13.7728-30.72 30.72-30.72h388.4032c16.9472 0 30.72 13.7728 30.72 30.72s-13.7728 30.72-30.72 30.72z" fill="#303135" p-id="51523"></path><path d="M256.6144 563.0976a30.6176 30.6176 0 0 1-22.3232-9.6256 30.67904 30.67904 0 0 1 1.2288-43.4176l162.7648-153.9072a30.72512 30.72512 0 0 1 41.8304-0.3584l129.7408 118.784 176.2816-169.2672c12.2368-11.7248 31.6928-11.3664 43.4176 0.8704s11.3664 31.6928-0.8704 43.4176l-197.0688 189.2352a30.77632 30.77632 0 0 1-42.0352 0.512L419.6864 420.4032l-141.9776 134.2976a30.7456 30.7456 0 0 1-21.0944 8.3968z" fill="#FF623E" p-id="51524"></path></svg>
<label v-text="language.monitor"></label>
</a>
Expand Down Expand Up @@ -326,13 +326,49 @@ <h3 class="card-title" v-text="language.statistics"></h3>
</div>
</div>
</footer>
<div class="offcanvas offcanvas-bottom" tabindex="-1" id="offcanvasBottom" aria-labelledby="offcanvasBottomLabel" style="height: 100%;">
<div class="offcanvas-header">
<h2 class="offcanvas-title" id="offcanvasBottomLabel">
<svg t="1692319746964" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="51522" width="320" height="320"><path d="M815.2576 795.3408H208.7424c-73.4208 0-133.12-59.6992-133.12-133.12V218.624c0-73.4208 59.6992-133.12 133.12-133.12h606.5664c73.4208 0 133.12 59.6992 133.12 133.12v443.5968c-0.0512 73.4208-59.7504 133.12-133.1712 133.12zM208.7424 146.944c-39.5264 0-71.68 32.1536-71.68 71.68v443.5968c0 39.5264 32.1536 71.68 71.68 71.68h606.5664c39.5264 0 71.68-32.1536 71.68-71.68V218.624c0-39.5264-32.1536-71.68-71.68-71.68H208.7424zM706.2016 945.4592H317.7984c-16.9472 0-30.72-13.7728-30.72-30.72s13.7728-30.72 30.72-30.72h388.4032c16.9472 0 30.72 13.7728 30.72 30.72s-13.7728 30.72-30.72 30.72z" fill="#303135" p-id="51523"></path><path d="M256.6144 563.0976a30.6176 30.6176 0 0 1-22.3232-9.6256 30.67904 30.67904 0 0 1 1.2288-43.4176l162.7648-153.9072a30.72512 30.72512 0 0 1 41.8304-0.3584l129.7408 118.784 176.2816-169.2672c12.2368-11.7248 31.6928-11.3664 43.4176 0.8704s11.3664 31.6928-0.8704 43.4176l-197.0688 189.2352a30.77632 30.77632 0 0 1-42.0352 0.512L419.6864 420.4032l-141.9776 134.2976a30.7456 30.7456 0 0 1-21.0944 8.3968z" fill="#FF623E" p-id="51524"></path></svg>
Monitor
</h2>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div class="btn-list">
<a class="btn d-none d-sm-inline-block" @click="startMonitor()" v-if="monitorStartBtn">
<svg t="1692612614001" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="118121" width="320" height="320"><path d="M510.3 98.2c-229.2 0-415.1 185.8-415.1 415S281 928.3 510.3 928.3s415.1-185.8 415.1-415.1c0-229.2-185.9-415-415.1-415z m163.8 448.1L446.5 679.1c-3.3 1.9-6.7 2.8-10.1 2.8-10.5 0-20.1-8.4-20.1-20.1V396.2c0-11.7 9.6-20.1 20.1-20.1 3.4 0 6.8 0.9 10.1 2.8l227.6 132.8c13.3 7.7 13.3 26.9 0 34.6z" fill="#3259CE" p-id="118122"></path></svg>
<label v-text="language.start"></label>
</a>
<a class="btn d-none d-sm-inline-block" @click="stopMonitor()" v-if="monitorStopBtn">
<svg t="1692694684479" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="25736" width="320" height="320"><path d="M510.171429 919.771429c-226.742857 0-411.428571-184.685714-411.428572-411.428572S283.428571 96.914286 510.171429 96.914286 921.6 281.6 921.6 508.342857 736.914286 919.771429 510.171429 919.771429zM548.571429 230.4h-74.971429v266.971429H548.571429V230.4z m230.4 213.942857c-5.485714-21.942857-12.8-42.057143-23.771429-62.171428-10.971429-20.114286-21.942857-38.4-36.571429-54.857143-14.628571-16.457143-42.057143-40.228571-42.057142-40.228572s0 1.828571-40.228572 43.885715c64 40.228571 98.742857 104.228571 98.742857 184.685714 0 122.514286-100.571429 223.085714-223.085714 223.085714s-223.085714-100.571429-223.085714-223.085714c0-76.8 38.4-144.457143 98.742857-184.685714L347.428571 288.914286s-32.914286 27.428571-47.542857 43.885714c-14.628571 16.457143-25.6 34.742857-34.742857 53.028571s-16.457143 38.4-21.942857 60.342858c-5.485714 20.114286-7.314286 42.057143-7.314286 64 0 38.4 7.314286 74.971429 21.942857 107.885714 14.628571 32.914286 34.742857 62.171429 60.342858 87.771428s54.857143 43.885714 87.771428 60.342858 69.485714 21.942857 107.885714 21.942857c38.4 0 74.971429-7.314286 107.885715-21.942857 32.914286-14.628571 62.171429-34.742857 87.771428-60.342858s43.885714-54.857143 60.342857-87.771428c14.628571-32.914286 21.942857-69.485714 21.942858-107.885714-5.485714-21.942857-7.314286-45.714286-12.8-65.828572z" fill="#99163d" p-id="25737" data-spm-anchor-id="a313x.search_index.0.i5.1fa53a8151ttue" class="selected"></path></svg>
<label v-text="language.stop"></label>
</a>
</div>
<div class="card mt-2">
<div class="card-body">
<div id="cpu" style="height: 330px;"></div>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
<div id="memory" style="height: 330px;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/@tabler/core@latest/dist/js/tabler.min.js"></script>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://unpkg.com/element-plus"></script>
<script src="https://unpkg.com/@element-plus/icons-vue"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/languages/go.min.js"></script>
<script src="/static/js/apexcharts.js"></script>
<script src="/static/js/highstock.js"></script>
<script src="/static/js/gray.js"></script>
<script src="/static/js/common.js"></script>
<script src="/static/js/lan.js"></script>
<script src="/static/js/html2canvas.min.js"></script>
Expand Down Expand Up @@ -361,12 +397,59 @@ <h3 class="card-title" v-text="language.statistics"></h3>
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()
Expand All @@ -375,6 +458,87 @@ <h3 class="card-title" v-text="language.statistics"></h3>
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 => {
Expand Down Expand Up @@ -692,11 +856,18 @@ <h3 class="card-title" v-text="language.statistics"></h3>
connectOverTime,
latencyOverTime,
statisticsJson,

//monitor
monitorStartBtn,
monitorStopBtn,

screenShot,
setLanguage,
initResponseOverTimeChart,
initConnectOverTimeChart,
initLatencyOverTimeChart
initLatencyOverTimeChart,
startMonitor,
stopMonitor
};
}
});
Expand Down
Loading

0 comments on commit bd11a68

Please sign in to comment.