-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b9f233
commit f30827a
Showing
11 changed files
with
215 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<script> | ||
import Grid from '$components/grid.svelte'; | ||
import Icon from '$components/icon.svelte'; | ||
import ObjectViewer from '$components/objectviewer.svelte'; | ||
import input from '$lib/actions/input'; | ||
import { BrowserOpenURL } from '$wails/runtime/runtime'; | ||
export let host; | ||
const autoReloadIntervals = [ 1, 2, 5, 10, 30, 60 ]; | ||
let filter = 'global'; | ||
let logs; | ||
let total = 0; | ||
let error = ''; | ||
let copySucceeded = false; | ||
let autoReloadInterval = 0; | ||
let objectViewerData; | ||
$: filter && refresh(); | ||
$: busy = !logs && !error && 'Requesting logs…'; | ||
async function refresh() { | ||
let _logs = []; | ||
({ logs: _logs, total, error } = await host.getLogs(filter)); | ||
logs = []; | ||
for (let index = 0; index < _logs.length; index++) { | ||
const log = JSON.parse(_logs[index]); | ||
log._index = index; | ||
logs = [ ...logs, log ]; | ||
} | ||
} | ||
function openFilterDocs() { | ||
BrowserOpenURL('https://www.mongodb.com/docs/manual/reference/command/getLog/#command-fields'); | ||
} | ||
function openLogDetail(event) { | ||
objectViewerData = logs[event.detail.index]; | ||
} | ||
async function copy() { | ||
const json = JSON.stringify(host.status, undefined, '\t'); | ||
await navigator.clipboard.writeText(json); | ||
copySucceeded = true; | ||
setTimeout(() => copySucceeded = false, 1500); | ||
} | ||
</script> | ||
|
||
<div class="stats"> | ||
<div class="grid"> | ||
<Grid | ||
items={logs || []} | ||
columns={[ | ||
{ title: 'Date', key: 't.$date' }, | ||
{ title: 'Severity', key: 's' }, | ||
{ title: 'ID', key: 'id' }, | ||
{ title: 'Component', key: 'c' }, | ||
{ title: 'Context', key: 'ctx' }, | ||
{ title: 'Message', key: 'msg' }, | ||
]} | ||
key="_index" | ||
showHeaders | ||
errorTitle={error ? 'Error fetching server status' : ''} | ||
errorDescription={error} | ||
on:trigger={openLogDetail} | ||
{busy} | ||
/> | ||
</div> | ||
|
||
<div class="controls"> | ||
<div> | ||
<div class="field inline"> | ||
<button class="button" on:click={refresh}> | ||
<Icon name="reload" spin={busy} /> Reload | ||
</button> | ||
|
||
<button class="button secondary" on:click={copy} disabled={!host.status}> | ||
<Icon name={copySucceeded ? 'check' : 'clipboard'} /> | ||
Copy JSON | ||
</button> | ||
</div> | ||
|
||
<label class="field inline"> | ||
<span class="label">Reload (sec)</span> | ||
<input type="number" bind:value={autoReloadInterval} list="autoreloadintervals" use:input /> | ||
</label> | ||
|
||
<label class="field inline"> | ||
<select bind:value={filter}> | ||
<option value="global">Global</option> | ||
<option value="startupWarnings">Startup warnings</option> | ||
</select> | ||
<button class="button secondary" on:click={openFilterDocs} title="Documentation"> | ||
<Icon name="?" /> | ||
</button> | ||
</label> | ||
</div> | ||
|
||
{#if total} | ||
<div class="total"> | ||
Total: {total} | ||
</div> | ||
{/if} | ||
</div> | ||
</div> | ||
|
||
{#if objectViewerData} | ||
<ObjectViewer bind:data={objectViewerData} readonly /> | ||
{/if} | ||
|
||
<datalist id="autoreloadintervals"> | ||
{#each autoReloadIntervals as value} | ||
<option {value} /> | ||
{/each} | ||
</datalist> | ||
|
||
<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; | ||
} | ||
.controls { | ||
display: flex; | ||
align-items: center; | ||
gap: 0.1rem; | ||
} | ||
.total { | ||
margin-left: auto; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/wailsapp/wails/v2/pkg/runtime" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
type HostLogsResult struct { | ||
Total int32 `json:"total"` | ||
Logs []string `json:"logs"` | ||
Error string `json:"error"` | ||
} | ||
|
||
func (a *App) HostLogs(hostKey, filter string) (result HostLogsResult) { | ||
client, ctx, close, err := a.connectToHost(hostKey) | ||
if err != nil { | ||
result.Error = "Could not connect to host" | ||
return | ||
} | ||
defer close() | ||
|
||
var res bson.M | ||
err = client.Database("admin").RunCommand(ctx, bson.M{"getLog": filter}).Decode(&res) | ||
if err != nil { | ||
runtime.LogWarningf(a.ctx, "Could not get %s logs for %s: %s", filter, hostKey, err.Error()) | ||
result.Error = err.Error() | ||
} | ||
|
||
result.Total = res["totalLinesWritten"].(int32) | ||
result.Logs = make([]string, 0) | ||
|
||
for _, v := range res["log"].(bson.A) { | ||
result.Logs = append(result.Logs, v.(string)) | ||
} | ||
|
||
return | ||
} |