From d6bdcb7a18430279cc85540efa637c45dc35f84b Mon Sep 17 00:00:00 2001 From: zhangxiquan Date: Mon, 6 Jan 2025 05:21:22 +0000 Subject: [PATCH] + [task#135735] add monitor setting. --- module/instance/model.php | 2 +- module/instance/ui/view.html.php | 9 +- module/instance/zen.php | 3 + module/space/config/dtable.php | 5 +- module/space/config/form.php | 5 + module/space/control.php | 12 ++ module/space/js/browse.ui.js | 14 +- module/space/ui/browse.html.php | 10 +- module/space/ui/monitorsetting.html.php | 244 ++++++++++++++++++++++++ module/system/control.php | 9 +- 10 files changed, 302 insertions(+), 11 deletions(-) create mode 100644 module/space/config/form.php create mode 100644 module/space/ui/monitorsetting.html.php diff --git a/module/instance/model.php b/module/instance/model.php index d339e08cbb..a64edcfada 100644 --- a/module/instance/model.php +++ b/module/instance/model.php @@ -131,7 +131,7 @@ class instanceModel extends model ->beginIF($status != 'all')->andWhere('instance.status')->eq($status)->fi() ->orderBy('instance.id desc') ->beginIF($pager)->page($pager)->fi() - ->fetchAll('id'); + ->fetchAll('id', false); $spaces = $this->dao->select('*')->from(TABLE_SPACE) ->where('deleted')->eq(0) diff --git a/module/instance/ui/view.html.php b/module/instance/ui/view.html.php index 0febd1fd16..4a2d38d4c8 100644 --- a/module/instance/ui/view.html.php +++ b/module/instance/ui/view.html.php @@ -115,7 +115,14 @@ div div ( $instance->name, setClass('text-xl'), - $type === 'store' ? span($instance->appVersion, setClass('ml-3 label gray-pale rounded-full')) : null + $type === 'store' ? span($instance->appVersion, setClass('ml-3 label gray-pale rounded-full')) : null, + $type === 'store' && isset($monitor) ? + span + ( + set::title($monitor['tips']), + icon('icon icon-info'), + setClass('ml-3 label ' . $monitor['class'] . ' rounded-full') + ) : null ), $type === 'store' ? div ( diff --git a/module/instance/zen.php b/module/instance/zen.php index 3ce7972b72..fa62719b38 100644 --- a/module/instance/zen.php +++ b/module/instance/zen.php @@ -42,6 +42,9 @@ class instanceZen extends instance $pipeline = $this->loadModel('pipeline')->getByUrl($url); $instance->externalID = !empty($pipeline) ? $pipeline->id : 0; } + $instance->monitor = empty($instance->monitor || !$this->config->inQuickon) ? array() : $this->loadModel('space')->formatMonitor(json_decode($instance->monitor, true)); + isset($instance->monitor['warning']['tips']) && $this->view->monitor = array('class' => 'warning-pale', 'tips' => $instance->monitor['warning']['tips']); + isset($instance->monitor['danger']['tips']) && $this->view->monitor = array('class' => 'danger-pale', 'tips' => $instance->monitor['danger']['tips']) ; $this->view->title = $instance->appName; $this->view->instance = $instance; diff --git a/module/space/config/dtable.php b/module/space/config/dtable.php index eedff5d8cd..37a4271a14 100644 --- a/module/space/config/dtable.php +++ b/module/space/config/dtable.php @@ -7,8 +7,9 @@ $app->loadLang('gitlab'); $config->space->dtable = new stdclass(); -$config->space->dtable->fieldList['name']['title'] = $lang->instance->name; -$config->space->dtable->fieldList['name']['type'] = 'title'; +$config->space->dtable->fieldList['name']['title'] = $lang->instance->name; +$config->space->dtable->fieldList['name']['type'] = 'title'; +$config->space->dtable->fieldList['name']['className'] = 'overflow-hidden'; $config->space->dtable->fieldList['appName']['title'] = $lang->instance->appName; $config->space->dtable->fieldList['appName']['type'] = 'text'; diff --git a/module/space/config/form.php b/module/space/config/form.php new file mode 100644 index 0000000000..1edb15344e --- /dev/null +++ b/module/space/config/form.php @@ -0,0 +1,5 @@ +space->form = new stdclass(); +$config->space->form->monitorsetting = array(); +$config->space->form->monitorsetting['warning'] = array('type' => 'array', 'required' => true); +$config->space->form->monitorsetting['danger'] = array('type' => 'array', 'required' => true); diff --git a/module/space/control.php b/module/space/control.php index a010fd30bd..ebaff237ae 100644 --- a/module/space/control.php +++ b/module/space/control.php @@ -62,6 +62,18 @@ class space extends control $this->display(); } + public function monitorSetting() + { + if ($_POST) { + $formData = form::data()->get(); + a(json_encode($formData));die; + } + $json = '{"warning":{"cpu":{"threshold":"45","duration":"3"},"memory":{"threshold":"70"},"disk":{"threshold":"80"}},"danger":{"cpu":{"threshold":"60","duration":"1"},"memory":{"threshold":"75"},"disk":{"threshold":"90"}}}'; + $this->view->title = $this->lang->space->monitorSetting; + $this->view->setting = json_decode($json); + $this->display(); + } + /** * 创建一个应用。 * Create a application. diff --git a/module/space/js/browse.ui.js b/module/space/js/browse.ui.js index 3611f58b28..c32f8a6954 100644 --- a/module/space/js/browse.ui.js +++ b/module/space/js/browse.ui.js @@ -17,13 +17,23 @@ window.renderInstanceList = function (result, {col, row, value}) } else if(col.name === 'name') { + let monitor = ''; + if(row.data.monitor && row.data.monitor.warning && row.data.monitor.warning.tips) + { + monitor = ' '; + } + /* danger monitor priority display */ + if(row.data.monitor && row.data.monitor.danger && row.data.monitor.danger.tips) + { + monitor = ' '; + } if(row.data.type == 'external') { - result[0] = {html: '' + result[0] + ''}; + result[0] = {html: '' + result[0] + '' + monitor}; } else { - result[0] = {html: '' + result[0] + ''}; + result[0] = {html: '' + result[0] + '' + monitor}; } } else if(col.name === 'createdAt') diff --git a/module/space/ui/browse.html.php b/module/space/ui/browse.html.php index 04a4a1155b..0c06c8cf1c 100644 --- a/module/space/ui/browse.html.php +++ b/module/space/ui/browse.html.php @@ -42,6 +42,14 @@ toolBar 'data-id' => 'installProgress', 'data-toggle' => 'modal' ))) : null, + $config->inQuickon && hasPriv('space', 'monitorSetting') ? item(set(array + ( + 'text' => $lang->space->monitorSetting, + 'icon' => 'backend', + 'class' => 'btn primary', + 'url' => createLink('space', 'monitorSetting'), + 'data-toggle' => 'modal' + ))) : null, $canInstall ? item(set(array ( 'text' => $lang->space->install, @@ -83,7 +91,7 @@ dtable set::onRenderCell(jsRaw('window.renderInstanceList')), set::sortLink(createLink('space', 'browse', "spaceID=&browseType={$browseType}&orderBy={name}_{sortType}&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}")), set::orderBys($orderBy), - set::footPager(usePager()) + set::footPager(usePager()), ); a(setStyle('display', 'none'), setID('editLinkContainer'), setData('toggle', 'modal')); diff --git a/module/space/ui/monitorsetting.html.php b/module/space/ui/monitorsetting.html.php new file mode 100644 index 0000000000..dbb86e2dcc --- /dev/null +++ b/module/space/ui/monitorsetting.html.php @@ -0,0 +1,244 @@ + + * @package instance + * @link https://www.zentao.net + */ + +namespace zin; + +$warning = zget($setting, 'warning', new stdClass); +$danger = zget($setting, 'danger', new stdClass); +formPanel +( + set::title($title), + setID('monitorSetting'), + setClass('w-full'), + col + ( + setClass('leading-10'), + row + ( + set::align('center'), + cell + ( + setClass('border rounded px-2'), + set::width('1/3'), + set::flex('auto'), + ' ', + ), + cell + ( + setClass('border rounded px-2'), + set::width('1/3'), + set::flex('none'), + $lang->space->monitor->warning, + ), + cell + ( + setClass('border rounded px-2'), + set::width('1/3'), + set::flex('none'), + $lang->space->monitor->danger, + ), + ), + row + ( + set::align('center'), + cell + ( + setClass('border rounded px-2'), + set::width('1/3'), + set::flex('auto'), + $lang->space->monitor->cpu, + ), + cell + ( + setClass('border rounded p-1'), + set::width('1/3'), + set::flex('none'), + formRow + ( + formGroup + ( + inputGroup + ( + $lang->space->monitor->used, + input + ( + set::name('warning[cpu][threshold]'), + set::value(zget($warning->cpu, 'threshold', 80)) + ), + '%' + ) + ), + formGroup + ( + inputGroup + ( + $lang->space->monitor->duration, + input + ( + set::name('warning[cpu][duration]'), + set::value(zget($warning->cpu, 'duration', 5)) + ), + $lang->space->monitor->minutes, + ) + ), + ), + ), + cell + ( + setClass('border rounded p-1'), + set::width('1/3'), + set::flex('none'), + formRow + ( + formGroup + ( + inputGroup + ( + $lang->space->monitor->used, + input + ( + set::name('danger[cpu][threshold]'), + set::value(zget($danger->cpu, 'threshold', 90)) + ), + '%' + ) + ), + formGroup + ( + inputGroup + ( + $lang->space->monitor->duration, + input + ( + set::name('danger[cpu][duration]'), + set::value(zget($danger->cpu, 'duration', 10)) + ), + $lang->space->monitor->minutes, + ) + ), + ), + ), + ), + row + ( + set::align('center'), + cell + ( + setClass('border rounded px-2'), + set::width('1/3'), + set::flex('auto'), + $lang->space->monitor->memory, + ), + cell + ( + setClass('border rounded p-1'), + set::width('1/3'), + set::flex('none'), + formRow + ( + formGroup + ( + inputGroup + ( + $lang->space->monitor->over, + input + ( + set::name('warning[memory][threshold]'), + set::value(zget($warning->memory, 'threshold', 80)) + ), + '%' + ) + ) + ), + ), + cell + ( + setClass('border rounded p-1'), + set::width('1/3'), + set::flex('none'), + formRow + ( + formGroup + ( + inputGroup + ( + $lang->space->monitor->over, + input + ( + set::name('danger[memory][threshold]'), + set::value(zget($danger->memory, 'threshold', 90)) + ), + '%' + ) + ) + ), + ), + ), + row + ( + set::align('center'), + cell + ( + setClass('border rounded px-2'), + set::width('1/3'), + set::flex('auto'), + $lang->space->monitor->disk, + ), + cell + ( + setClass('border rounded p-1'), + set::width('1/3'), + set::flex('none'), + formRow + ( + formGroup + ( + inputGroup + ( + $lang->space->monitor->over, + input + ( + set::name('warning[disk][threshold]'), + set::value(zget($warning->disk, 'threshold', 80)) + ), + '%' + ) + ) + ) + ), + cell + ( + setClass('border rounded p-1'), + set::width('1/3'), + set::flex('none'), + formRow + ( + formGroup + ( + inputGroup + ( + $lang->space->monitor->over, + input + ( + set::name('danger[disk][threshold]'), + set::value(zget($danger->disk, 'threshold', 90)) + ), + '%' + ) + ) + ) + ), + ), + ) +); + +render(); \ No newline at end of file diff --git a/module/system/control.php b/module/system/control.php index 5498699bcd..628bc88827 100644 --- a/module/system/control.php +++ b/module/system/control.php @@ -34,11 +34,12 @@ class system extends control $instances = $this->loadModel('instance')->getList($pager, '', '', 'running'); $instancesMetrics = $this->cne->instancesMetrics($instances); - foreach($instances as $instance) + foreach($instances as &$instance) { - $metrics = zget($instancesMetrics, $instance->id); - $instance->cpu = is_object($metrics) ? $this->instance->printCpuUsage($instance, $metrics->cpu) : new stdClass(); - $instance->mem = is_object($metrics) ? $this->instance->printStorageUsage($instance, $metrics->memory) : new stdClass(); + $metrics = zget($instancesMetrics, $instance->id); + $instance->cpu = is_object($metrics) ? $this->instance->printCpuUsage($instance, $metrics->cpu) : new stdClass(); + $instance->mem = is_object($metrics) ? $this->instance->printStorageUsage($instance, $metrics->memory) : new stdClass(); + $instance->monitor = empty($instance->monitor || !$this->config->inQuickon) ? array() : $this->loadModel('space')->formatMonitor(json_decode($instance->monitor, true)); } $actions = $this->loadModel('action')->getDynamic('all', 'today');