- name: Statistics columns: - size: small widgets: - type: custom-api title: Jellyfin base-url: https://jellyfin.${GROUND_DOMAIN} options: url: https://jellyfin.${GROUND_DOMAIN} key: ${JELLYFIN_API_KEY} template: | {{ $url := .Options.StringOr "url" "" }} {{ $key := .Options.StringOr "key" "" }} {{- if or (eq $url "") (eq $key "") -}}
Error: The URL or API key was not configured in the widget options.
{{- else -}} {{- $auth := printf "MediaBrowser Token=\"%s\"" $key -}} {{- $countsUrl := printf "%s/Items/Counts" $url -}} {{- $jellyfinData := newRequest $countsUrl | withHeader "Authorization" $auth | getResponse -}} {{- $audiobooksUrl := printf "%s/Items?IncludeItemTypes=AudioBook&Recursive=true&Limit=0&EnableTotalRecordCount=true" $url -}} {{- $audiobooksData := newRequest $audiobooksUrl | withHeader "Authorization" $auth | getResponse -}} {{- if and (eq $jellyfinData.Response.StatusCode 200) (eq $audiobooksData.Response.StatusCode 200) -}}Failed to fetch Jellyfin library counts (Counts: {{ $jellyfinData.Response.StatusCode }}, Audiobooks: {{ $audiobooksData.Response.StatusCode }}).
{{- end -}} {{- end -}} - type: custom-api title: SABnzbd cache: 30s url: https://sabnzbd.${GROUND_DOMAIN}/api?output=json&apikey=${SABNZBD_API_KEY}&mode=queue headers: Authorization: Basic ${AUTHENTIK_BASIC_AUTH} Accept: application/json template: |Error fetching qBittorrent data.
Check QUI proxy URL and token.
Some options are not set or malformed.
{{ else }} {{ $indexUrl := printf "%s/api/v1/indexer" $apiBaseUrl }} {{ $indexData := newRequest $indexUrl | withHeader "Accept" "application/json" | withHeader "Authorization" "Basic ${AUTHENTIK_BASIC_AUTH}" | withHeader "X-Api-Key" $key | getResponse }} {{ if eq $indexData.Response.StatusCode 200 }}Failed to fetch data (Status: {{ $indexData.Response.StatusCode }})
{{ end }} {{ end }} - type: custom-api title: Server Stats cache: 5m options: base-url: https://beszel.${GROUND_DOMAIN} email: ${BESZEL_EMAIL} password: ${BESZEL_PASSWORD} template: | {{ $baseURL := .Options.StringOr "base-url" "" }} {{ $email := .Options.StringOr "email" "" }} {{ $password := .Options.StringOr "password" "" }} {{ define "errorMsg" }}{{ . }}
{{ end }} {{ define "formatGigabytes" }} {{ $value := . }} {{ $label := "GiB" }} {{- if lt $value 1.0 }} {{ $value = mul $value 1024.0 }} {{ $label = "MiB" }} {{- else if lt $value 1024.0 }} {{ else }} {{ $value = div $value 1024.0 }} {{ $label = "TiB" }} {{ end }} {{ printf "%.1f" $value }} {{ $label }} {{ end }} {{ if or (eq $baseURL "") (eq $email "") (eq $password "") }} {{ template "errorMsg" "Some required options are not set." }} {{ else }} {{ $authBody := printf "{\"identity\":%s,\"password\":%s}" (.Options.JSON "email") (.Options.JSON "password") }} {{ $authResponse := newRequest (print $baseURL "/api/collections/users/auth-with-password") | withParameter "fields" "token" | withHeader "Content-Type" "application/json" | withStringBody $authBody | getResponse }} {{ if ne $authResponse.Response.StatusCode 200 }} {{ template "errorMsg" (printf "Beszel authentication failed: %s" $authResponse.Response.Status) }} {{ else }} {{ $token := concat "Bearer " ($authResponse.JSON.String "token") }} {{ $systemsResponse := newRequest (print $baseURL "/api/collections/systems/records") | withHeader "Authorization" $token | getResponse }} {{ if ne $systemsResponse.Response.StatusCode 200 }} {{ template "errorMsg" (printf "Failed to fetch Beszel systems: %s" $systemsResponse.Response.Status) }} {{ else }} {{ range $n, $system := $systemsResponse.JSON.Array "items" }} {{ $status := $system.String "status" }} {{ $systemStatsRequest := newRequest (print $baseURL "/api/collections/system_stats/records") | withHeader "Authorization" $token | withParameter "sort" "-created" | withParameter "page" "1" | withParameter "perPage" "1" | withParameter "filter" (print "type='1m'&&system='" ($system.String "id") "'") | getResponse }} {{ $systemStatItems := $systemStatsRequest.JSON.Array "items" }} {{ $hostname := $system.String "name" }} {{ $uptimeSec := $system.Float "info.u" }} {{ $systemTemp := $system.Float "info.dt" }} {{ $cpuLoad := $system.Float "info.cpu" }} {{ $cpuLoad1m := $system.Float "info.la.0" }} {{ $cpuLoad15m := $system.Float "info.la.2" }} {{ $memoryUsedPercent := $system.Float "info.mp" }} {{ $rootUsedPercent := $system.Float "info.dp" }} {{ $hasStats := false }} {{ $systemStats := "" }} {{ $memoryTotalGb := 0.0 }} {{ $memoryUsedGb := 0.0 }} {{ $swapTotalGb := 0.0 }} {{ $swapUsedGb := 0.0 }} {{ $swapUsedPercent := 0.0 }} {{ $rootTotalGb := 0.0 }} {{ $rootUsedGb := 0.0 }} {{ if gt (len $systemStatItems) 0 }} {{ $hasStats = true }} {{ $systemStats = index $systemStatItems 0 }} {{ $memoryTotalGb = $systemStats.Float "stats.m" }} {{ $memoryUsedGb = $systemStats.Float "stats.mu" }} {{ $swapTotalGb = $systemStats.Float "stats.s" }} {{ $swapUsedGb = $systemStats.Float "stats.su" }} {{ if gt $swapTotalGb 0.0 }} {{ $swapUsedPercent = mul (div $swapUsedGb $swapTotalGb) 100.0 }} {{ end }} {{ $rootTotalGb = $systemStats.Float "stats.d" }} {{ $rootUsedGb = $systemStats.Float "stats.du" }} {{ end }}