mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 13:07:58 +00:00
Display sb stats generated by dbStats
command (#15)
This commit is contained in:
parent
ea376f5ba7
commit
be7643bd31
@ -1,5 +1,6 @@
|
|||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
* Display 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).
|
* Added version number of the running Rolens instance in the about dialog (#25, #28).
|
||||||
* Fixed host/database selection bug in grid.
|
* Fixed host/database selection bug in grid.
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
export let collection;
|
export let collection;
|
||||||
export let hostKey;
|
export let hostKey;
|
||||||
export let dbKey;
|
export let dbKey;
|
||||||
export let collectionKey;
|
export let collKey;
|
||||||
|
|
||||||
let tab = 'find';
|
let tab = 'find';
|
||||||
let find;
|
let find;
|
||||||
@ -25,10 +25,10 @@
|
|||||||
$: if (collection) {
|
$: if (collection) {
|
||||||
collection.hostKey = hostKey;
|
collection.hostKey = hostKey;
|
||||||
collection.dbKey = dbKey;
|
collection.dbKey = dbKey;
|
||||||
collection.key = collectionKey;
|
collection.key = collKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if (hostKey || dbKey || collectionKey) {
|
$: if (hostKey || dbKey || collKey) {
|
||||||
tab = 'find';
|
tab = 'find';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="collection" class:empty={!collection}>
|
<div class="view" class:empty={!collection}>
|
||||||
{#if collection}
|
{#if collection}
|
||||||
{#key collection}
|
{#key collection}
|
||||||
<TabBar tabs={[
|
<TabBar tabs={[
|
||||||
@ -85,12 +85,12 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.collection {
|
.view {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template: auto 1fr / 1fr;
|
grid-template: auto 1fr / 1fr;
|
||||||
}
|
}
|
||||||
.collection.empty {
|
.view.empty {
|
||||||
grid-template: 1fr / 1fr;
|
grid-template: 1fr / 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
60
frontend/src/organisms/connection/database/index.svelte
Normal file
60
frontend/src/organisms/connection/database/index.svelte
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<script>
|
||||||
|
import BlankState from '$components/blankstate.svelte';
|
||||||
|
import TabBar from '$components/tabbar.svelte';
|
||||||
|
import { EventsOn } from '$wails/runtime/runtime';
|
||||||
|
import Stats from './stats.svelte';
|
||||||
|
|
||||||
|
export let database;
|
||||||
|
export let hostKey;
|
||||||
|
export let dbKey;
|
||||||
|
|
||||||
|
let tab = 'stats';
|
||||||
|
|
||||||
|
$: if (database) {
|
||||||
|
database.hostKey = hostKey;
|
||||||
|
database.dbKey = dbKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
$: if (hostKey || dbKey) {
|
||||||
|
tab = 'stats';
|
||||||
|
}
|
||||||
|
|
||||||
|
EventsOn('OpenStatsTab', name => (tab = name || tab));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="view" class:empty={!database}>
|
||||||
|
{#if database}
|
||||||
|
{#key database}
|
||||||
|
<TabBar tabs={[ { key: 'stats', icon: 'chart', title: 'Stats' } ]} bind:selectedKey={tab} />
|
||||||
|
<div class="container">
|
||||||
|
{#if tab === 'stats'} <Stats {database} />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/key}
|
||||||
|
{:else}
|
||||||
|
<BlankState label="Select a database 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/database/stats.svelte
Normal file
45
frontend/src/organisms/connection/database/stats.svelte
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<script>
|
||||||
|
import Icon from '$components/icon.svelte';
|
||||||
|
import ObjectGrid from '$components/objectgrid.svelte';
|
||||||
|
|
||||||
|
export let database;
|
||||||
|
|
||||||
|
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={database.stats} />
|
||||||
|
</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>
|
@ -62,9 +62,10 @@
|
|||||||
|
|
||||||
async function openDatabase(dbKey) {
|
async function openDatabase(dbKey) {
|
||||||
const progress = startProgress(`Opening database "${dbKey}"…`);
|
const progress = startProgress(`Opening database "${dbKey}"…`);
|
||||||
const collections = await OpenDatabase(activeHostKey, dbKey);
|
const { collections, stats } = await OpenDatabase(activeHostKey, dbKey);
|
||||||
activeDbKey = dbKey;
|
activeDbKey = dbKey;
|
||||||
activeCollKey = '';
|
activeCollKey = '';
|
||||||
|
$connections[activeHostKey].databases[dbKey].stats = stats;
|
||||||
|
|
||||||
for (const collKey of collections || []) {
|
for (const collKey of collections || []) {
|
||||||
$connections[activeHostKey].databases[dbKey].collections[collKey] =
|
$connections[activeHostKey].databases[dbKey].collections[collKey] =
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
import { EnterText } from '$wails/go/ui/UI';
|
import { EnterText } from '$wails/go/ui/UI';
|
||||||
import { EventsOn } from '$wails/runtime/runtime';
|
import { EventsOn } from '$wails/runtime/runtime';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import CollectionDetail from './collection/index.svelte';
|
import DatabaseView from './database/index.svelte';
|
||||||
|
import CollectionView from './collection/index.svelte';
|
||||||
import DumpInfo from './dump.svelte';
|
import DumpInfo from './dump.svelte';
|
||||||
import HostDetail from './hostdetail.svelte';
|
import HostDetail from './hostdetail.svelte';
|
||||||
import HostTree from './hosttree.svelte';
|
import HostTree from './hosttree.svelte';
|
||||||
@ -110,12 +111,20 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<CollectionDetail
|
{#if activeCollKey}
|
||||||
collection={$connections[activeHostKey]?.databases[activeDbKey]?.collections?.[activeCollKey]}
|
<CollectionView
|
||||||
hostKey={activeHostKey}
|
collection={$connections[activeHostKey]?.databases[activeDbKey]?.collections?.[activeCollKey]}
|
||||||
dbKey={activeDbKey}
|
hostKey={activeHostKey}
|
||||||
collectionKey={activeCollKey}
|
dbKey={activeDbKey}
|
||||||
/>
|
collKey={activeCollKey}
|
||||||
|
/>
|
||||||
|
{:else if activeDbKey}
|
||||||
|
<DatabaseView
|
||||||
|
database={$connections[activeHostKey]?.databases[activeDbKey]}
|
||||||
|
hostKey={activeHostKey}
|
||||||
|
dbKey={activeDbKey}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<HostDetail
|
<HostDetail
|
||||||
bind:show={showHostDetail}
|
bind:show={showHostDetail}
|
||||||
|
2
frontend/wailsjs/go/app/App.d.ts
generated
vendored
2
frontend/wailsjs/go/app/App.d.ts
generated
vendored
@ -35,7 +35,7 @@ export function OpenCollection(arg1:string,arg2:string,arg3:string):Promise<prim
|
|||||||
|
|
||||||
export function OpenConnection(arg1:string):Promise<Array<string>>;
|
export function OpenConnection(arg1:string):Promise<Array<string>>;
|
||||||
|
|
||||||
export function OpenDatabase(arg1:string,arg2:string):Promise<Array<string>>;
|
export function OpenDatabase(arg1:string,arg2:string):Promise<app.DatabaseInfo>;
|
||||||
|
|
||||||
export function PerformDump(arg1:string):Promise<boolean>;
|
export function PerformDump(arg1:string):Promise<boolean>;
|
||||||
|
|
||||||
|
14
frontend/wailsjs/go/models.ts
generated
14
frontend/wailsjs/go/models.ts
generated
@ -1,5 +1,19 @@
|
|||||||
export namespace app {
|
export namespace app {
|
||||||
|
|
||||||
|
export class DatabaseInfo {
|
||||||
|
collections: string[];
|
||||||
|
stats: {[key: string]: any};
|
||||||
|
|
||||||
|
static createFrom(source: any = {}) {
|
||||||
|
return new DatabaseInfo(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(source: any = {}) {
|
||||||
|
if ('string' === typeof source) source = JSON.parse(source);
|
||||||
|
this.collections = source["collections"];
|
||||||
|
this.stats = source["stats"];
|
||||||
|
}
|
||||||
|
}
|
||||||
export class EnvironmentInfo {
|
export class EnvironmentInfo {
|
||||||
arch: string;
|
arch: string;
|
||||||
buildType: string;
|
buildType: string;
|
||||||
|
@ -6,22 +6,36 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *App) OpenDatabase(hostKey, dbKey string) (collections []string) {
|
type DatabaseInfo struct {
|
||||||
|
Collections []string `json:"collections"`
|
||||||
|
Stats bson.M `json:"stats"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) OpenDatabase(hostKey, dbKey string) (info DatabaseInfo) {
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
collections, err = client.Database(dbKey).ListCollectionNames(ctx, bson.D{})
|
command := bson.M{"dbStats": 1}
|
||||||
|
err = client.Database(dbKey).RunCommand(ctx, command).Decode(&info.Stats)
|
||||||
|
if err != nil {
|
||||||
|
runtime.LogWarning(a.ctx, "Could not retrieve database stats for "+dbKey)
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
|
zenity.Error(err.Error(), zenity.Title("Could not get stats"), zenity.ErrorIcon)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
info.Collections, err = client.Database(dbKey).ListCollectionNames(ctx, bson.D{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
runtime.LogWarning(a.ctx, "Could not retrieve collection list for db "+dbKey)
|
runtime.LogWarning(a.ctx, "Could not retrieve collection list for db "+dbKey)
|
||||||
runtime.LogWarning(a.ctx, err.Error())
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
zenity.Error(err.Error(), zenity.Title("Error while getting collections"), zenity.ErrorIcon)
|
zenity.Error(err.Error(), zenity.Title("Error while getting collections"), zenity.ErrorIcon)
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
defer close()
|
defer close()
|
||||||
return collections
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DropDatabase(hostKey, dbKey string) bool {
|
func (a *App) DropDatabase(hostKey, dbKey string) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user