mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 12:33:58 +00:00
set mongo profiling
This commit is contained in:
@@ -197,4 +197,12 @@ module.exports = {
|
|||||||
testConnectionPermission(conid, req);
|
testConnectionPermission(conid, req);
|
||||||
return this.loadDataCore('serverSummary', { conid });
|
return this.loadDataCore('serverSummary', { conid });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
summaryCommand_meta: true,
|
||||||
|
async summaryCommand({ conid, command, row }, req) {
|
||||||
|
testConnectionPermission(conid, req);
|
||||||
|
const opened = await this.ensureOpened(conid);
|
||||||
|
if (opened.connection.isReadOnly) return false;
|
||||||
|
return this.loadDataCore('summaryCommand', { conid, command, row });
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -118,14 +118,19 @@ async function handleDriverDataCore(msgid, callMethod) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleServerSummary({ msgid, options }) {
|
async function handleServerSummary({ msgid }) {
|
||||||
return handleDriverDataCore(msgid, driver => driver.serverSummary(systemConnection));
|
return handleDriverDataCore(msgid, driver => driver.serverSummary(systemConnection));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleSummaryCommand({ msgid, command, row }) {
|
||||||
|
return handleDriverDataCore(msgid, driver => driver.summaryCommand(systemConnection, command, row));
|
||||||
|
}
|
||||||
|
|
||||||
const messageHandlers = {
|
const messageHandlers = {
|
||||||
connect: handleConnect,
|
connect: handleConnect,
|
||||||
ping: handlePing,
|
ping: handlePing,
|
||||||
serverSummary: handleServerSummary,
|
serverSummary: handleServerSummary,
|
||||||
|
summaryCommand: handleSummaryCommand,
|
||||||
createDatabase: props => handleDatabaseOp('createDatabase', props),
|
createDatabase: props => handleDatabaseOp('createDatabase', props),
|
||||||
dropDatabase: props => handleDatabaseOp('dropDatabase', props),
|
dropDatabase: props => handleDatabaseOp('dropDatabase', props),
|
||||||
};
|
};
|
||||||
|
|||||||
3
packages/types/engines.d.ts
vendored
3
packages/types/engines.d.ts
vendored
@@ -128,7 +128,8 @@ export interface EngineDriver {
|
|||||||
getNewObjectTemplates(): NewObjectTemplate[];
|
getNewObjectTemplates(): NewObjectTemplate[];
|
||||||
// direct call of pool method, only some methods could be supported, on only some drivers
|
// direct call of pool method, only some methods could be supported, on only some drivers
|
||||||
callMethod(pool, method, args);
|
callMethod(pool, method, args);
|
||||||
loadSummary(pool): Promise<ServerSummary>;
|
serverSummary(pool): Promise<ServerSummary>;
|
||||||
|
summaryCommand(pool, command, row): Promise<void>;
|
||||||
|
|
||||||
analyserClass?: any;
|
analyserClass?: any;
|
||||||
dumperClass?: any;
|
dumperClass?: any;
|
||||||
|
|||||||
@@ -9,6 +9,11 @@
|
|||||||
export let conid;
|
export let conid;
|
||||||
|
|
||||||
let refreshToken = 0;
|
let refreshToken = 0;
|
||||||
|
|
||||||
|
async function callAction(command, row) {
|
||||||
|
await apiCall('server-connections/summary-command', { conid, refreshToken, command, row });
|
||||||
|
refreshToken += 1;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#await apiCall('server-connections/server-summary', { conid, refreshToken })}
|
{#await apiCall('server-connections/server-summary', { conid, refreshToken })}
|
||||||
@@ -22,10 +27,18 @@
|
|||||||
emptyMessage={'No databases'}
|
emptyMessage={'No databases'}
|
||||||
columns={summary.columns.map(col => ({
|
columns={summary.columns.map(col => ({
|
||||||
...col,
|
...col,
|
||||||
slot: col.dataType == 'bytes' ? 1 : null,
|
slot: col.columnType == 'bytes' ? 1 : col.columnType == 'actions' ? 2 : null,
|
||||||
}))}
|
}))}
|
||||||
>
|
>
|
||||||
<svelte:fragment slot="1" let:row let:col>{formatFileSize(row?.[col.fieldName])}</svelte:fragment>
|
<svelte:fragment slot="1" let:row let:col>{formatFileSize(row?.[col.fieldName])}</svelte:fragment>
|
||||||
|
<svelte:fragment slot="2" let:row let:col>
|
||||||
|
{#each col.actions as action, index}
|
||||||
|
{#if index > 0}
|
||||||
|
<span> | </span>
|
||||||
|
{/if}
|
||||||
|
<Link onClick={() => callAction(action.command, row)}>{action.header}</Link>
|
||||||
|
{/each}
|
||||||
|
</svelte:fragment>
|
||||||
</ObjectListControl>
|
</ObjectListControl>
|
||||||
</div>
|
</div>
|
||||||
{/await}
|
{/await}
|
||||||
|
|||||||
@@ -352,6 +352,20 @@ const driver = {
|
|||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async summaryCommand(pool, command, row) {
|
||||||
|
switch (command) {
|
||||||
|
case 'profileOff':
|
||||||
|
await pool.db(row.name).command({ profile: 0 });
|
||||||
|
return;
|
||||||
|
case 'profileFiltered':
|
||||||
|
await pool.db(row.name).command({ profile: 1, slowms: 100 });
|
||||||
|
return;
|
||||||
|
case 'profileAll':
|
||||||
|
await pool.db(row.name).command({ profile: 2 });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async serverSummary(pool) {
|
async serverSummary(pool) {
|
||||||
const res = await pool.__getDatabase().admin().listDatabases();
|
const res = await pool.__getDatabase().admin().listDatabases();
|
||||||
const profiling = await Promise.all(res.databases.map((x) => pool.db(x.name).command({ profile: -1 })));
|
const profiling = await Promise.all(res.databases.map((x) => pool.db(x.name).command({ profile: -1 })));
|
||||||
@@ -363,7 +377,7 @@ const driver = {
|
|||||||
case 1:
|
case 1:
|
||||||
return `Filtered (>${info.slowms} ms)`;
|
return `Filtered (>${info.slowms} ms)`;
|
||||||
case 2:
|
case 2:
|
||||||
'Profile all';
|
return 'Profile all';
|
||||||
default:
|
default:
|
||||||
return '???';
|
return '???';
|
||||||
}
|
}
|
||||||
@@ -373,19 +387,37 @@ const driver = {
|
|||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
fieldName: 'name',
|
fieldName: 'name',
|
||||||
dataType: 'string',
|
columnType: 'string',
|
||||||
header: 'Name',
|
header: 'Name',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'sizeOnDisk',
|
fieldName: 'sizeOnDisk',
|
||||||
dataType: 'bytes',
|
columnType: 'bytes',
|
||||||
header: 'Size',
|
header: 'Size',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'profiling',
|
fieldName: 'profiling',
|
||||||
dataType: 'string',
|
columnType: 'string',
|
||||||
header: 'Profiling',
|
header: 'Profiling',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'setProfile',
|
||||||
|
columnType: 'actions',
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
header: 'Off',
|
||||||
|
command: 'profileOff',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'Filtered',
|
||||||
|
command: 'profileFiltered',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'All',
|
||||||
|
command: 'profileAll',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
databases: res.databases.map((db, i) => ({
|
databases: res.databases.map((db, i) => ({
|
||||||
...db,
|
...db,
|
||||||
|
|||||||
Reference in New Issue
Block a user