Skip to content

Commit

Permalink
improve console
Browse files Browse the repository at this point in the history
  • Loading branch information
keengo99 committed Jan 5, 2025
1 parent da5d696 commit 0981321
Show file tree
Hide file tree
Showing 21 changed files with 234 additions and 18 deletions.
2 changes: 1 addition & 1 deletion console/src/components/Whm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function whm_get(call_name: string, param?: Record<string, string>): Prom
param['format'] = 'json';
return fetch('/core.whm?' + new URLSearchParams(param).toString()).then((res) => res.json());
}
export function whm_post(call_name: string, formData: FormData): Promise<any> {
export function whm_post(call_name: string, formData: FormData|Record<string, string>): Promise<any> {
return fetch('/core.whm?' + new URLSearchParams({ "whm_call": call_name, "format": "json" }).toString(),
{
method: 'POST',
Expand Down
30 changes: 29 additions & 1 deletion console/src/views/ConnectPerIpView.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
<script lang="ts" setup>
import FooterView from "./FooterView.vue";
import { whm_get, whm_post } from '@/components/Whm.vue';
import { onMounted, ref } from 'vue';
interface ConnectPerIp {
ip: string,
count: number,
}
const connectPerIps = ref(<ConnectPerIp[]>[])
const maxPerIp = ref(0);
function flushConnectPerIp() {
whm_get("list_connect_per_ip").then((json) => {
connectPerIps.value = json.result.info;
maxPerIp.value = json.result.max_per_ip;
});
}
onMounted(flushConnectPerIp)
</script>
<template>
connect_per_ip
每IP连接信息({{ maxPerIp }}) [<a href="#" @click="flushConnectPerIp()">刷新</a>]
<table border="1" cellspacing="0">
<tr>
<th>ip地址</th>
<th>连接数</th>
</tr>
<tr v-for="info in connectPerIps">
<td>{{ info.ip }}</td>
<td>{{ info.count }}</td>
</tr>
</table>
<FooterView />
</template>
6 changes: 4 additions & 2 deletions console/src/views/ConnectionView.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
const connections = ref(<any[]>[]);
onMounted(()=>{
function flushConnect() {
fetch('/core.whm?whm_call=connection&format=json').then((res) => res.json()).then((json) => {
connections.value = json.result.c;
});
});
}
onMounted(flushConnect);
</script>
<template>
[<a href=# @click="flushConnect()">刷新</a>]
<table border="1" cellspacing="0">
<tr>
<th>源地址</th>
Expand Down
2 changes: 2 additions & 0 deletions console/src/views/InfoView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fetch('/core.whm?whm_call=info&format=json').then((res) => {
</table>
<h3>运行情况</h3>{{ info.total_run }}<h3>负载信息</h3>
<table>
<tbody>
<tr>
<td>连接数</td>
<td>{{ info.connect }}</td>
Expand All @@ -62,6 +63,7 @@ fetch('/core.whm?whm_call=info&format=json').then((res) => {
<td>空闲线程数</td>
<td>{{ info.thread_free }}</td>
</tr>
</tbody>
</table>
<h3>事件模型</h3>
<table>
Expand Down
56 changes: 54 additions & 2 deletions console/src/views/ProcessView.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,59 @@
<script lang="ts" setup>
import FooterView from "./FooterView.vue";
import { whm_get, whm_post } from '@/components/Whm.vue';
import { onMounted, ref } from 'vue';
interface Process {
app: string,
pid: number,
cpu_usage: number,
low_pri: number,
refs: number,
size: number,
total_run: number,
}
interface ProcessGroup {
name: string,
process: Process[]
}
const processGroups = ref(<ProcessGroup[]>[])
function flushProcess() {
whm_get("list_process").then((json) => {
processGroups.value = json.result.group;
});
}
function kill_process(name: string, process: Process) {
if (!confirm("确定关闭进程 " + process.pid + "吗?")) {
return;
}
whm_post("kill_process", { name: name, app: process.app, pid: process.pid.toString() }).then((json) => {
flushProcess();
})
}
onMounted(flushProcess)
</script>
<template>
process
<FooterView/>
<div>子进程信息 [<a href=# @click="flushProcess()">刷新</a>]</div>
<template v-for="group in processGroups">
{{ group.name }} ({{ group.process.length }})
<table border="1" cellspacing="0">
<tr>
<th>操作</th>
<th>用户名</th>
<th>pid</th>
<th>使用数</th>
<th>空闲数</th>
<th>运行时间</th>
</tr>
<tr v-for="process in group.process">
<td><a href=# @click="kill_process(group.name, process)">关闭</a></td>
<td>{{ process.app }}</td>
<td>{{ process.pid }}</td>
<td>{{ process.refs }}</td>
<td>{{ process.size }}</td>
<td>{{ process.total_run }}</td>
</tr>
</table>
</template>
<FooterView />
</template>
2 changes: 1 addition & 1 deletion include/KAcserverManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class KAcserverManager
void refreshCmd(time_t nowTime);
void getProcessInfo(KWStream &s);
void killCmdProcess(USER_T user);

void dump_process(kgl::serializable *sl);
#endif
void killAllProcess(KVirtualHost* vh);
void shutdown();
Expand Down
12 changes: 12 additions & 0 deletions include/KApiProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ class KApiProcess: public KVirtualHostProcess {
delete st;
}
}
void dump_process(const KString & app, kgl::serializable* sl) override {
KLocker lock(&stLock);
if (!st) {
return;
}
auto sl_process = sl->add_obj_array("process");
if (!sl_process) {
return;
}
sl->add("app", app);
dump_process_info(&st->process, this, sl_process);
}
void getProcessInfo(const USER_T &user, const KString &name, KWStream &s,int &count) override {
stLock.Lock();
if (st) {
Expand Down
13 changes: 13 additions & 0 deletions include/KCmdProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ class KSPCmdProcess: public KVirtualHostProcess {
~KSPCmdProcess();
KUpstream *PowerResult(KHttpRequest* rq, KPipeStream* st);
KPipeStream * PowerThread(KVirtualHost *vh,KExtendProgram *rd);
void dump_process(const KString& app, kgl::serializable* sl) override {
KLocker lock(&stLock);
if (!st) {
return;
}
auto sl_process = sl->add_obj_array("process");
if (!sl_process) {
return;
}
sl_process->add("app", app);
dump_process_info(&st->process, this, sl_process);
}
void getProcessInfo(const USER_T &user, const KString &name, KWStream &s,int &count)
{
stLock.Lock();
Expand Down Expand Up @@ -75,6 +87,7 @@ class KMPCmdProcess: public KVirtualHostProcess {
~KMPCmdProcess();
KUpstream* GetUpstream(KHttpRequest* rq, KExtendProgram* rd) override;
//kev_result handleRequest(KHttpRequest *rq,KExtendProgram *rd, KAsyncFetchObject *fo);
void dump_process(const KString &user, kgl::serializable* sl) override;
void getProcessInfo(const USER_T &user, const KString&name, KWStream &s,int &count) override;
bool killProcess(int pid) override;
//KTcpUpstream *poweron(KVirtualHost *vh,KExtendProgram *erd, bool &success);
Expand Down
5 changes: 4 additions & 1 deletion include/KHttpRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ class KHttpTransfer;
#define REQUEST_EMPTY 0
#define REQUEST_READY 1
#define MIN_SLEEP_TIME 4

namespace kangle {
KString get_connect_per_ip();
void dump_connect_per_ip(kgl::serializable *sl);
};
void log_access(KHttpRequest* rq);
kev_result on_sink_readhup(KOPAQUE data, void* arg, int got);
KHttpHeaderIteratorResult handle_http_header(void* arg, KHttpHeader* header);
Expand Down
1 change: 1 addition & 0 deletions include/KProcessManage.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class KProcessManage {
KUpstream* GetUpstream(KHttpRequest* rq, KExtendProgram* rd);
void clean();
void refresh(time_t nowTime);
void dump(kgl::serializable* sl);
void getProcessInfo(KWStream &s);
//{{ent
#ifdef ENABLE_ADPP
Expand Down
2 changes: 2 additions & 0 deletions include/KVirtualHostProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class KVirtualHostProcess : public KPoolableSocketContainer
virtual KPipeStream* PowerThread(KVirtualHost* vh, KExtendProgram* rd) = 0;
virtual void getProcessInfo(const USER_T& user, const KString& name, KWStream& s, int& count) {
}
virtual void dump_process(const KString &user, kgl::serializable* sl) = 0;
//{{ent
#ifdef ENABLE_ADPP
virtual void flushCpuUsage(const KString& user, const KString& name, ULONG64 cpuTime) {
Expand Down Expand Up @@ -175,5 +176,6 @@ struct VProcessPowerParam
kfiber* fiber;
};
void getProcessInfo(const USER_T& user, const KString& name, KProcess* process, KPoolableSocketContainer* ps, KWStream& s);
void dump_process_info(KProcess* process, KPoolableSocketContainer* ps, kgl::serializable *sl);
KTHREAD_FUNCTION VProcessPowerWorker(void* param);
#endif /* KVIRTUALPROCESS_H_ */
2 changes: 2 additions & 0 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ bool createProcess(KPipeStream *st,Token_t token, char * args[], KCmdEnv *envs,
bool createProcess(Token_t token, char * args[],KCmdEnv *envs,char *cur_dir,PIPE_T in,PIPE_T out,PIPE_T err,pid_t &pid);
pid_t createProcess(Token_t token,const char *cmd,KCmdEnv *envs,const char *curdir,kgl_process_std *std);
bool killProcess(KVirtualHost *vh);
bool killProcess(KString process, KString user, int pid);

#ifdef _WIN32
extern KMutex closeExecLock;
BOOL StartInteractiveClientProcess (
Expand Down
24 changes: 24 additions & 0 deletions module/whm/WhmCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,27 @@ int WhmCore::call_list_cmd(const char* call_name, const char* event_type, WhmCo
int WhmCore::call_list_dso(const char* call_name, const char* event_type, WhmContext* ctx) {
return conf.dem->dump(ctx);
}
int WhmCore::call_list_process(const char* call_name, const char* event_type, WhmContext* ctx) {
spProcessManage.dump(ctx->data());
#ifdef ENABLE_VH_RUN_AS
conf.gam->dump_process(ctx->data());
#endif
return WHM_OK;
}
int WhmCore::call_kill_process(const char* call_name, const char* event_type, WhmContext* ctx) {
auto uv = ctx->getUrlValue();
if (uv->getx("name")) {
if (!killProcess(uv->get("name"), uv->get("app"), uv->attribute.get_int("pid"))) {
return WHM_CALL_FAILED;
}
return WHM_OK;
}
if (!killProcess(ctx->getVh())) {
return WHM_CALL_FAILED;
}
return WHM_OK;
}
int WhmCore::call_list_connect_per_ip(const char* call_name, const char* event_type, WhmContext* ctx) {
kangle::dump_connect_per_ip(ctx->data());
return WHM_OK;
}
12 changes: 11 additions & 1 deletion module/whm/WhmCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class WhmCore final : public WhmExtend {
break;
case 'k':
if (strcmp(callName, "kill_process") == 0) {
return nullptr;
return (whm_call_ptr)&WhmCore::call_kill_process;
}
break;
case 'l':
Expand Down Expand Up @@ -147,6 +147,12 @@ class WhmCore final : public WhmExtend {
if (strcmp(callName, "list_mserver") == 0) {
return (whm_call_ptr)&WhmCore::call_list_mserver;
}
if (strcmp(callName, "list_process") == 0) {
return (whm_call_ptr)&WhmCore::call_list_process;
}
if (strcmp(callName, "list_connect_per_ip") == 0) {
return (whm_call_ptr)&WhmCore::call_list_connect_per_ip;
}
#ifdef ENABLE_LOG_DRILL
if (strcmp(callName, "log_drill") == 0) {
return nullptr;
Expand Down Expand Up @@ -220,6 +226,9 @@ class WhmCore final : public WhmExtend {
int call_list_api(const char* call_name, const char* event_type, WhmContext* ctx);
int call_list_cmd(const char* call_name, const char* event_type, WhmContext* ctx);
int call_list_dso(const char* call_name, const char* event_type, WhmContext* ctx);
/* process */
int call_list_process(const char* call_name, const char* event_type, WhmContext* ctx);
int call_kill_process(const char* call_name, const char* event_type, WhmContext* ctx);
/* system */
int call_reboot(const char* call_name, const char* event_type, WhmContext* ctx) {
console_call_reboot();
Expand All @@ -230,5 +239,6 @@ class WhmCore final : public WhmExtend {
int call_get_config_listen(const char* call_name, const char* event_type, WhmContext* ctx);
int call_get_listen(const char* call_name, const char* event_type, WhmContext* ctx);
int call_check_vh_db(const char* call_name, const char* event_type, WhmContext* ctx);
int call_list_connect_per_ip(const char* call_name, const char* event_type, WhmContext* ctx);
};
#endif
9 changes: 9 additions & 0 deletions src/KAcserverManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,15 @@ int KAcserverManager::getCmdPortMap(KVirtualHost* vh, KString cmd, KString name,
}
#endif
//}}
void KAcserverManager::dump_process(kgl::serializable* sl) {
auto locker = get_rlocker();
for (auto&& it : cmds) {
auto pm = it.second->getProcessManage();
if (pm) {
pm->dump(sl);
}
}
}
void KAcserverManager::getProcessInfo(KWStream& s) {
lock.RLock();
std::map<KString, KCmdPoolableRedirect*>::iterator it;
Expand Down
20 changes: 20 additions & 0 deletions src/KCmdProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,26 @@ void KMPCmdProcess::flushCpuUsage(const KString &user,const KString&name,ULONG64
stLock.Unlock();
}
#endif
void KMPCmdProcess::dump_process(const KString & app, kgl::serializable* sl) {
KSingleListenPipeStream* st;
KLocker lock(&stLock);
klist_foreach(st, busyProcessList) {
auto sl_process = sl->add_obj_array("process");
if (!sl_process) {
continue;
}
sl_process->add("app", app);
dump_process_info(&st->process, st, sl_process);
}
klist_foreach(st, freeProcessList) {
auto sl_process = sl->add_obj_array("process");
if (!sl_process) {
continue;
}
sl_process->add("app", app);
dump_process_info(&st->process, st, sl_process);
}
}
void KMPCmdProcess::getProcessInfo(const USER_T &user, const KString &name,KWStream &s,int &count)
{
KSingleListenPipeStream *st;
Expand Down
4 changes: 1 addition & 3 deletions src/KHttpManage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
#include "KDefer.h"
#include "KChain.h"
#include "kmd5.h"
namespace kangle {
KString get_connect_per_ip();
};

using namespace std;
using namespace kangle;
KPathHandler<kgl_request_handler> KHttpManage::handler(_KS(""));
Expand Down
12 changes: 11 additions & 1 deletion src/KProcessManage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,17 @@ void KProcessManage::refresh(time_t nowTime) {
lock.Unlock();

}

void KProcessManage::dump(kgl::serializable* sl) {
KLocker locker(&lock);
if (pools.empty()) {
return;
}
auto sl_process = sl->add_obj_array("group");
sl_process->add("name", name);
for (auto&& it : pools) {
it.second->dump_process(it.first, sl_process);
}
}
void KProcessManage::getProcessInfo(KWStream&s) {
int count = 0;
KStringBuf t;
Expand Down
Loading

0 comments on commit 0981321

Please sign in to comment.