mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 04:57:59 +00:00
Display host stats
This commit is contained in:
parent
be7643bd31
commit
be4e3e778e
@ -1,6 +1,6 @@
|
||||
## Unreleased
|
||||
|
||||
* Display database statistics generated by the corresponding diagnostic MongoDB commands in addition to collection stats (#15).
|
||||
* Display host and database statistics generated by the corresponding diagnostic MongoDB commands in addition to collection stats (#15).
|
||||
* Added version number of the running Rolens instance in the about dialog (#25, #28).
|
||||
* Fixed host/database selection bug in grid.
|
||||
|
||||
|
@ -64,10 +64,8 @@ export function deepClone(obj) {
|
||||
|
||||
export function pathsAreEqual(x, y) {
|
||||
const lengthOfLongest = (x.length >= y.length) ? x.length : y.length;
|
||||
console.log(x, y)
|
||||
|
||||
for (let i = 0; i < lengthOfLongest; i++) {
|
||||
console.log(x[i], y[i])
|
||||
if (x[i] !== y[i]) {
|
||||
return false;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
<div class="view" class:empty={!database}>
|
||||
{#if database}
|
||||
{#key database}
|
||||
<TabBar tabs={[ { key: 'stats', icon: 'chart', title: 'Stats' } ]} bind:selectedKey={tab} />
|
||||
<TabBar tabs={[ { key: 'stats', icon: 'chart', title: 'Database stats' } ]} bind:selectedKey={tab} />
|
||||
<div class="container">
|
||||
{#if tab === 'stats'} <Stats {database} />
|
||||
{/if}
|
||||
|
64
frontend/src/organisms/connection/host/index.svelte
Normal file
64
frontend/src/organisms/connection/host/index.svelte
Normal file
@ -0,0 +1,64 @@
|
||||
<script>
|
||||
import BlankState from '$components/blankstate.svelte';
|
||||
import TabBar from '$components/tabbar.svelte';
|
||||
import { EventsOn } from '$wails/runtime/runtime';
|
||||
import Status from './status.svelte';
|
||||
import SystemInfo from './systeminfo.svelte';
|
||||
|
||||
export let host;
|
||||
export let hostKey;
|
||||
|
||||
let tab = 'status';
|
||||
|
||||
$: if (host) {
|
||||
host.hostKey = hostKey;
|
||||
}
|
||||
|
||||
$: if (hostKey || dbKey) {
|
||||
tab = 'status';
|
||||
}
|
||||
|
||||
EventsOn('OpenStatusTab', name => (tab = name || tab));
|
||||
</script>
|
||||
|
||||
<div class="view" class:empty={!host}>
|
||||
{#if host}
|
||||
{#key host}
|
||||
<TabBar tabs={[
|
||||
{ key: 'status', icon: 'chart', title: 'Host status' },
|
||||
{ key: 'systemInfo', icon: 'server', title: 'System info' }
|
||||
]} bind:selectedKey={tab} />
|
||||
|
||||
<div class="container">
|
||||
{#if tab === 'status'} <Status {host} />
|
||||
{:else if tab === 'systemInfo'} <SystemInfo {host} />
|
||||
{/if}
|
||||
</div>
|
||||
{/key}
|
||||
{:else}
|
||||
<BlankState label="Select a host to continue" />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.view {
|
||||
height: 100%;
|
||||
display: grid;
|
||||
grid-template: auto 1fr / 1fr;
|
||||
}
|
||||
.view.empty {
|
||||
grid-template: 1fr / 1fr;
|
||||
}
|
||||
|
||||
.container {
|
||||
padding: 0.5rem;
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
overflow: auto;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
}
|
||||
.container > :global(*) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
45
frontend/src/organisms/connection/host/status.svelte
Normal file
45
frontend/src/organisms/connection/host/status.svelte
Normal file
@ -0,0 +1,45 @@
|
||||
<script>
|
||||
import Icon from '$components/icon.svelte';
|
||||
import ObjectGrid from '$components/objectgrid.svelte';
|
||||
|
||||
export let host;
|
||||
|
||||
let copySucceeded = false;
|
||||
|
||||
async function copy() {
|
||||
const json = JSON.stringify(collection.stats, undefined, '\t');
|
||||
await navigator.clipboard.writeText(json);
|
||||
copySucceeded = true;
|
||||
setTimeout(() => copySucceeded = false, 1500);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="stats">
|
||||
<!-- <CodeExample code="db.stats()" /> -->
|
||||
|
||||
<div class="grid">
|
||||
<ObjectGrid data={host.status} />
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
<button class="btn secondary" on:click={copy}>
|
||||
<Icon name={copySucceeded ? 'check' : 'clipboard'} />
|
||||
Copy JSON
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.stats {
|
||||
display: grid;
|
||||
gap: 0.5rem;
|
||||
grid-template: 1fr auto / 1fr;
|
||||
}
|
||||
|
||||
.stats .grid {
|
||||
overflow: auto;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
</style>
|
45
frontend/src/organisms/connection/host/systeminfo.svelte
Normal file
45
frontend/src/organisms/connection/host/systeminfo.svelte
Normal file
@ -0,0 +1,45 @@
|
||||
<script>
|
||||
import Icon from '$components/icon.svelte';
|
||||
import ObjectGrid from '$components/objectgrid.svelte';
|
||||
|
||||
export let host;
|
||||
|
||||
let copySucceeded = false;
|
||||
|
||||
async function copy() {
|
||||
const json = JSON.stringify(collection.stats, undefined, '\t');
|
||||
await navigator.clipboard.writeText(json);
|
||||
copySucceeded = true;
|
||||
setTimeout(() => copySucceeded = false, 1500);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="stats">
|
||||
<!-- <CodeExample code="db.stats()" /> -->
|
||||
|
||||
<div class="grid">
|
||||
<ObjectGrid data={host.systemInfo} />
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
<button class="btn secondary" on:click={copy}>
|
||||
<Icon name={copySucceeded ? 'check' : 'clipboard'} />
|
||||
Copy JSON
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.stats {
|
||||
display: grid;
|
||||
gap: 0.5rem;
|
||||
grid-template: 1fr auto / 1fr;
|
||||
}
|
||||
|
||||
.stats .grid {
|
||||
overflow: auto;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
</style>
|
@ -30,17 +30,24 @@
|
||||
|
||||
async function openConnection(hostKey) {
|
||||
const progress = startProgress(`Connecting to "${hostKey}"…`);
|
||||
|
||||
activeCollKey = '';
|
||||
activeDbKey = '';
|
||||
activeHostKey = hostKey;
|
||||
const databases = await OpenConnection(hostKey);
|
||||
|
||||
const { databases, status, systemInfo } = await OpenConnection(hostKey);
|
||||
|
||||
if (databases) {
|
||||
$connections[hostKey] = { databases: {} };
|
||||
$connections[hostKey] = $connections[hostKey] || {};
|
||||
$connections[hostKey].status = status;
|
||||
$connections[hostKey].systemInfo = systemInfo;
|
||||
|
||||
$connections[hostKey].databases = $connections[hostKey].databases || {};
|
||||
databases.forEach(dbKey => {
|
||||
$connections[hostKey].databases[dbKey] =
|
||||
$connections[hostKey].databases[dbKey] || { collections: {} };
|
||||
});
|
||||
|
||||
activeHostKey = hostKey;
|
||||
dispatch('connected', hostKey);
|
||||
WindowSetTitle(`${$hosts[activeHostKey].name} - Rolens`);
|
||||
|
@ -5,6 +5,7 @@
|
||||
import { EnterText } from '$wails/go/ui/UI';
|
||||
import { EventsOn } from '$wails/runtime/runtime';
|
||||
import { onMount } from 'svelte';
|
||||
import HostView from './host/index.svelte';
|
||||
import DatabaseView from './database/index.svelte';
|
||||
import CollectionView from './collection/index.svelte';
|
||||
import DumpInfo from './dump.svelte';
|
||||
@ -124,6 +125,11 @@
|
||||
hostKey={activeHostKey}
|
||||
dbKey={activeDbKey}
|
||||
/>
|
||||
{:else if activeHostKey}
|
||||
<HostView
|
||||
host={$connections[activeHostKey]}
|
||||
hostKey={activeHostKey}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<HostDetail
|
||||
|
2
frontend/wailsjs/go/app/App.d.ts
generated
vendored
2
frontend/wailsjs/go/app/App.d.ts
generated
vendored
@ -33,7 +33,7 @@ export function Menu():Promise<menu.Menu>;
|
||||
|
||||
export function OpenCollection(arg1:string,arg2:string,arg3:string):Promise<primitive.M>;
|
||||
|
||||
export function OpenConnection(arg1:string):Promise<Array<string>>;
|
||||
export function OpenConnection(arg1:string):Promise<app.HostInfo>;
|
||||
|
||||
export function OpenDatabase(arg1:string,arg2:string):Promise<app.DatabaseInfo>;
|
||||
|
||||
|
16
frontend/wailsjs/go/models.ts
generated
16
frontend/wailsjs/go/models.ts
generated
@ -44,6 +44,22 @@ export namespace app {
|
||||
this.downloadDirectory = source["downloadDirectory"];
|
||||
}
|
||||
}
|
||||
export class HostInfo {
|
||||
databases: string[];
|
||||
status: {[key: string]: any};
|
||||
systemInfo: {[key: string]: any};
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new HostInfo(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.databases = source["databases"];
|
||||
this.status = source["status"];
|
||||
this.systemInfo = source["systemInfo"];
|
||||
}
|
||||
}
|
||||
export class QueryResult {
|
||||
total: number;
|
||||
results: string[];
|
||||
|
@ -12,6 +12,12 @@ import (
|
||||
mongoOptions "go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type HostInfo struct {
|
||||
Databases []string `json:"databases"`
|
||||
Status bson.M `json:"status"`
|
||||
SystemInfo bson.M `json:"systemInfo"`
|
||||
}
|
||||
|
||||
func (a *App) connectToHost(hostKey string) (*mongo.Client, context.Context, func(), error) {
|
||||
hosts, err := a.Hosts()
|
||||
if err != nil {
|
||||
@ -43,18 +49,38 @@ func (a *App) connectToHost(hostKey string) (*mongo.Client, context.Context, fun
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *App) OpenConnection(hostKey string) (databases []string) {
|
||||
func (a *App) OpenConnection(hostKey string) (info HostInfo) {
|
||||
client, ctx, close, err := a.connectToHost(hostKey)
|
||||
if err != nil {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
databases, err = client.ListDatabaseNames(ctx, bson.M{})
|
||||
|
||||
info.Databases, err = client.ListDatabaseNames(ctx, bson.M{})
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not retrieve database names for host "+hostKey)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Error while getting databases"), zenity.ErrorIcon)
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
command := bson.M{"serverStatus": 1}
|
||||
err = client.Database("admin").RunCommand(ctx, command).Decode(&info.Status)
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not retrieve server status")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Could not get server status"), zenity.ErrorIcon)
|
||||
return
|
||||
}
|
||||
|
||||
command = bson.M{"hostInfo": 1}
|
||||
err = client.Database("admin").RunCommand(ctx, command).Decode(&info.SystemInfo)
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not retrieve system info")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Could not get system info"), zenity.ErrorIcon)
|
||||
return
|
||||
}
|
||||
|
||||
defer close()
|
||||
return databases
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user