diff --git a/CHANGELOG.md b/CHANGELOG.md index 9161fa8..d748c64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 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). * Fixed host/database selection bug in grid. diff --git a/frontend/src/organisms/connection/collection/index.svelte b/frontend/src/organisms/connection/collection/index.svelte index e2c05d6..b4650e9 100644 --- a/frontend/src/organisms/connection/collection/index.svelte +++ b/frontend/src/organisms/connection/collection/index.svelte @@ -15,7 +15,7 @@ export let collection; export let hostKey; export let dbKey; - export let collectionKey; + export let collKey; let tab = 'find'; let find; @@ -25,10 +25,10 @@ $: if (collection) { collection.hostKey = hostKey; collection.dbKey = dbKey; - collection.key = collectionKey; + collection.key = collKey; } - $: if (hostKey || dbKey || collectionKey) { + $: if (hostKey || dbKey || collKey) { tab = 'find'; } @@ -46,7 +46,7 @@ } -
+
{#if collection} {#key collection} - .collection { + .view { height: 100%; display: grid; grid-template: auto 1fr / 1fr; } - .collection.empty { + .view.empty { grid-template: 1fr / 1fr; } diff --git a/frontend/src/organisms/connection/database/index.svelte b/frontend/src/organisms/connection/database/index.svelte new file mode 100644 index 0000000..768b897 --- /dev/null +++ b/frontend/src/organisms/connection/database/index.svelte @@ -0,0 +1,60 @@ + + +
+ {#if database} + {#key database} + +
+ {#if tab === 'stats'} + {/if} +
+ {/key} + {:else} + + {/if} +
+ + diff --git a/frontend/src/organisms/connection/database/stats.svelte b/frontend/src/organisms/connection/database/stats.svelte new file mode 100644 index 0000000..0476aa7 --- /dev/null +++ b/frontend/src/organisms/connection/database/stats.svelte @@ -0,0 +1,45 @@ + + +
+ + +
+ +
+ +
+ +
+
+ + diff --git a/frontend/src/organisms/connection/hosttree.svelte b/frontend/src/organisms/connection/hosttree.svelte index d11277e..7458792 100644 --- a/frontend/src/organisms/connection/hosttree.svelte +++ b/frontend/src/organisms/connection/hosttree.svelte @@ -62,9 +62,10 @@ async function openDatabase(dbKey) { const progress = startProgress(`Opening database "${dbKey}"…`); - const collections = await OpenDatabase(activeHostKey, dbKey); + const { collections, stats } = await OpenDatabase(activeHostKey, dbKey); activeDbKey = dbKey; activeCollKey = ''; + $connections[activeHostKey].databases[dbKey].stats = stats; for (const collKey of collections || []) { $connections[activeHostKey].databases[dbKey].collections[collKey] = diff --git a/frontend/src/organisms/connection/index.svelte b/frontend/src/organisms/connection/index.svelte index d445c96..88dbcb8 100644 --- a/frontend/src/organisms/connection/index.svelte +++ b/frontend/src/organisms/connection/index.svelte @@ -5,7 +5,8 @@ import { EnterText } from '$wails/go/ui/UI'; import { EventsOn } from '$wails/runtime/runtime'; 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 HostDetail from './hostdetail.svelte'; import HostTree from './hosttree.svelte'; @@ -110,12 +111,20 @@ />
- +{#if activeCollKey} + +{:else if activeDbKey} + +{/if} >; -export function OpenDatabase(arg1:string,arg2:string):Promise>; +export function OpenDatabase(arg1:string,arg2:string):Promise; export function PerformDump(arg1:string):Promise; diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index 3704a64..c04a1d6 100755 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -1,5 +1,19 @@ 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 { arch: string; buildType: string; diff --git a/internal/app/database.go b/internal/app/database.go index 26ee8e8..87b2199 100644 --- a/internal/app/database.go +++ b/internal/app/database.go @@ -6,22 +6,36 @@ import ( "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) 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 { runtime.LogWarning(a.ctx, "Could not retrieve collection list for db "+dbKey) runtime.LogWarning(a.ctx, err.Error()) zenity.Error(err.Error(), zenity.Title("Error while getting collections"), zenity.ErrorIcon) - return nil + return } defer close() - return collections + return } func (a *App) DropDatabase(hostKey, dbKey string) bool {