add status monitor to glance
This commit is contained in:
@@ -1,97 +1,67 @@
|
||||
- type: custom-api
|
||||
title: Crafty Controller — Minecraft Server
|
||||
cache: 5s
|
||||
allow-insecure: true
|
||||
url: ${CRAFTY_URL}/api/v2/servers/${CRAFTY_SERVER_ID}/stats
|
||||
headers:
|
||||
Authorization: Bearer ${CRAFTY_API_TOKEN}
|
||||
Accept: application/json
|
||||
title: Minecraft
|
||||
url: https://api.mcstatus.io/v2/status/java/${MC_SERVER_URL}
|
||||
cache: 30s
|
||||
template: |
|
||||
<!-- USER SETTINGS SECTION -->
|
||||
|
||||
<!-- Change true to false if you wish to not display the MOTD -->
|
||||
{{ $displayMOTD := true }}
|
||||
|
||||
<!-- END OF USER SETTINGS SECTION -->
|
||||
|
||||
{{ $is_running := .JSON.Bool "data.running" }}
|
||||
{{ $online_players := .JSON.Int "data.online" | formatNumber }}
|
||||
{{ $max_players := .JSON.Int "data.max" | formatNumber }}
|
||||
{{ $name := .JSON.String "data.world_name" }}
|
||||
{{ $size := .JSON.String "data.world_size" }}
|
||||
{{ $version := .JSON.String "data.version" }}
|
||||
{{ $icon := .JSON.String "data.icon" }}
|
||||
{{ $server_ip := .JSON.String "data.server_id.server_ip" }}
|
||||
{{ $server_port := .JSON.String "data.server_id.server_port" }}
|
||||
{{ $motd := .JSON.String "data.desc" }}
|
||||
|
||||
{{ $server_addr := "" }}
|
||||
{{ if and ($is_running) (eq $server_ip "127.0.0.1") }}
|
||||
{{ $server_addr = printf "%s:%s" (replaceMatches "https?://" "" "${CRAFTY_URL}") $server_port }}
|
||||
{{ else if $is_running }}
|
||||
{{ $server_addr = printf "%s:%s" $server_ip $server_port }}
|
||||
{{ end }}
|
||||
|
||||
{{ $starting := false }}
|
||||
{{ if and ($is_running) (eq $max_players "0") (eq $version "False") }}
|
||||
{{ $starting = true }}
|
||||
{{ end }}
|
||||
|
||||
<!-- I couldn't find documentation describing the "waiting_start" state or the other booleans below. Implementation might not be correct. -->
|
||||
{{ $updating := .JSON.Bool "data.updating" }}
|
||||
{{ $importing := .JSON.Bool "data.importing" }}
|
||||
{{ $crashed := .JSON.Bool "data.crashed" }}
|
||||
|
||||
<div style="display:flex; align-items:center; gap:12px;">
|
||||
<!-- Server Icon -->
|
||||
<div style="width:40px; height:40px; flex-shrink:0; border-radius:4px; display:flex; justify-content:center; align-items:center; overflow:hidden;">
|
||||
{{ if eq $icon "" }}
|
||||
<img src="https://cdn.jsdelivr.net/gh/selfhst/icons/png/minecraft.png" style="width:100%; height:100%; object-fit:contain;" alt="Server icon">
|
||||
<div style="width:40px; height:40px; flex-shrink:0; border-radius:4px; display:flex; justify-content:center; align-items:center; overflow:hidden;">
|
||||
{{ if .JSON.Bool "online" }}
|
||||
<img src="{{ .JSON.String "icon" | safeURL }}" width="64" height="64" style="object-fit:contain;">
|
||||
{{ else }}
|
||||
<img src="data:image/png;base64, {{ $icon }}" style="width:100%; height:100%; object-fit:contain;" alt="Server icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" style="width:32px; height:32px; opacity:0.5;">
|
||||
<path fill-rule="evenodd" d="M1 5.25A2.25 2.25 0 0 1 3.25 3h13.5A2.25 2.25 0 0 1 19 5.25v9.5A2.25 2.25 0 0 1 16.75 17H3.25A2.25 2.25 0 0 1 1 14.75v-9.5Zm1.5 5.81v3.69c0 .414.336.75.75.75h13.5a.75.75 0 0 0 .75-.75v-2.69l-2.22-2.219a.75.75 0 0 0-1.06 0l-1.91 1.909.47.47a.75.75 0 1 1-1.06 1.06L6.53 8.091a.75.75 0 0 0-1.06 0l-2.97 2.97ZM12 7a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
<!-- Right side: Info -->
|
||||
<div style="display:flex; flex-direction:column;">
|
||||
<!-- First row: Server Name + IP -->
|
||||
<div style="display:flex; align-items:center; gap:6px;">
|
||||
<span class="size-h4 block text-truncate color-primary">
|
||||
{{ $name }}
|
||||
</span>
|
||||
|
||||
{{ if and ($is_running) (not $starting) (not (eq $server_addr "")) }}
|
||||
<div style="font-size:0.9em; color:var(--color-secondary);">
|
||||
<span class="size-h6 color-secondary">
|
||||
{{ $server_addr }}
|
||||
</span>
|
||||
</div>
|
||||
<div style="flex-grow:1; min-width:0;">
|
||||
<a class="size-h4 block text-truncate color-highlight">
|
||||
{{ .JSON.String "host" }}
|
||||
{{ if .JSON.Bool "online" }}
|
||||
<span
|
||||
style="width: 8px; height: 8px; border-radius: 50%; background-color: var(--color-positive); display: inline-block; vertical-align: middle;"
|
||||
data-popover-type="text"
|
||||
data-popover-text="Online"
|
||||
></span>
|
||||
{{ else }}
|
||||
<span
|
||||
style="width: 8px; height: 8px; border-radius: 50%; background-color: var(--color-negative); display: inline-block; vertical-align: middle;"
|
||||
data-popover-type="text"
|
||||
data-popover-text="Offline"
|
||||
></span>
|
||||
{{ end }}
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<!-- Second row: MOTD & Stats if server is running, otherwise show status msg ... -->
|
||||
{{ if and ($is_running) (not $starting) }}
|
||||
{{ if and (not (eq $motd "")) ($displayMOTD) }}
|
||||
<div style="font-size:0.9em; color:var(--color-secondary);">
|
||||
{{ replaceMatches "§." "" $motd }}
|
||||
<ul class="list-horizontal-text">
|
||||
<li>
|
||||
{{ if .JSON.Bool "online" }}
|
||||
<span>{{ .JSON.String "version.name_clean" }}</span>
|
||||
{{ else }}
|
||||
<span>Offline</span>
|
||||
{{ end }}
|
||||
</li>
|
||||
{{ if .JSON.Bool "online" }}
|
||||
<li data-popover-type="html">
|
||||
<div data-popover-html>
|
||||
{{ range .JSON.Array "players.list" }}{{ .String "name_clean" }}<br>{{ end }}
|
||||
</div>
|
||||
<p style="display:inline-flex;align-items:center;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-6" style="height:1em;vertical-align:middle;margin-right:0.5em;">
|
||||
<path fill-rule="evenodd" d="M7.5 6a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM3.751 20.105a8.25 8.25 0 0 1 16.498 0 .75.75 0 0 1-.437.695A18.683 18.683 0 0 1 12 22.5c-2.786 0-5.433-.608-7.812-1.7a.75.75 0 0 1-.437-.695Z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
{{ .JSON.Int "players.online" | formatNumber }}/{{ .JSON.Int "players.max" | formatNumber }} players
|
||||
</p>
|
||||
</li>
|
||||
{{ else }}
|
||||
<li>
|
||||
<p style="display:inline-flex;align-items:center;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-6" style="height:1em;vertical-align:middle;margin-right:0.5em;opacity:0.5;">
|
||||
<path fill-rule="evenodd" d="M7.5 6a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM3.751 20.105a8.25 8.25 0 0 1 16.498 0 .75.75 0 0 1-.437.695A18.683 18.683 0 0 1 12 22.5c-2.786 0-5.433-.608-7.812-1.7a.75.75 0 0 1-.437-.695Z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
0 players
|
||||
</p>
|
||||
</li>
|
||||
{{ end }}
|
||||
|
||||
<div style="font-size:0.9em; color:var(--color-secondary);">
|
||||
{{ $version }} - {{ $online_players }}/{{ $max_players }} players - {{ $size }}
|
||||
</div>
|
||||
|
||||
<!-- lots of assumptions about the boolean states meanings from crafty api.. -->
|
||||
{{ else if $starting }}
|
||||
<div style="font-size:0.9em; color:var(--color-secondary);">Server is starting up..</div>
|
||||
{{ else if $importing }}
|
||||
<div style="font-size:0.9em; color:var(--color-secondary);">Server is being imported..</div>
|
||||
{{ else if $updating }}
|
||||
<div style="font-size:0.9em; color:var(--color-secondary);">Server is being updated..</div>
|
||||
{{ else if $crashed }}
|
||||
<div style="font-size:0.9em; color:var(--color-secondary);">Server has crashed!</div>
|
||||
{{ else }}
|
||||
<div style="font-size:0.9em; color:var(--color-secondary);">Server is offline</div>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user