Skip to content

Commit 0b7f2cd

Browse files
authored
Merge pull request #183 from Chachigo/main
Synology Disk Station Widget
2 parents b46a8aa + 3f41e2f commit 0b7f2cd

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Synology Disk Station Widget
2+
3+
Displays RAM and CPU usage and used storage of your Synology NAS
4+
5+
## Widget Type
6+
`custom-api`
7+
8+
## Preview
9+
10+
![Synology Disk Station Widget Preview](preview.png)
11+
12+
## How to Use
13+
1. Copy the contents of the file below into your glance.yml file. (This works best as a -size: small widget)
14+
2. Replace [username], [password], [IP] and [Port]
15+
16+
17+
```yaml
18+
- type: custom-api
19+
cache: 5m
20+
title: Synology Disk Station
21+
options:
22+
nas-ip: "[IP]"
23+
nas-port: "[Port]"
24+
username: "[username]"
25+
password: "[password]"
26+
template: |
27+
{{ $baseUrl := concat "http://" (.Options.StringOr "nas-ip" "127.0.0.1") ":" (.Options.StringOr "nas-port" "5000") "/webapi/entry.cgi" }}
28+
{{ $auth := newRequest $baseUrl
29+
| withParameter "api" "SYNO.API.Auth"
30+
| withParameter "version" "6"
31+
| withParameter "method" "login"
32+
| withParameter "account" (.Options.StringOr "username" "admin")
33+
| withParameter "passwd" (.Options.StringOr "password" "admin")
34+
| withParameter "session" "FileStation"
35+
| withParameter "format" "sid"
36+
| getResponse
37+
}}
38+
39+
{{ $sid := $auth.JSON.String "data.sid" }}
40+
41+
42+
{{
43+
$storage := newRequest $baseUrl
44+
| withParameter "api" "SYNO.Core.System"
45+
| withParameter "method" "info"
46+
| withParameter "type" "storage"
47+
| withParameter "version" "1"
48+
| withParameter "_sid" $sid
49+
| getResponse
50+
}}
51+
52+
{{
53+
$cpu := newRequest $baseUrl
54+
| withParameter "api" "SYNO.Core.System.Utilization"
55+
| withParameter "method" "get"
56+
| withParameter "version" "1"
57+
| withParameter "_sid" $sid
58+
| getResponse
59+
}}
60+
61+
{{ if and (eq $storage.Response.StatusCode 200) (eq $cpu.Response.StatusCode 200) }}
62+
{{ $volInfo := index ($storage.JSON.Array "data.vol_info") 0 }}
63+
{{ $total := $volInfo.Float "total_size" }}
64+
{{ $used := $volInfo.Float "used_size" }}
65+
{{ $storagePercent := mul (div $used $total) 100 | toInt }}
66+
67+
{{ $cpuPercent := $cpu.JSON.Int "data.cpu.user_load" }}
68+
{{ $ramPercent := $cpu.JSON.Int "data.memory.real_usage" }}
69+
{{ $ramTotalKB := $cpu.JSON.Float "data.memory.total_real" }}
70+
{{ $ramUsedKB := mul (div $ramTotalKB 100.0) ($ramPercent | toFloat) }}
71+
{{ $ramUsedMB := div $ramUsedKB 1000 }}
72+
{{ $ramUsedGB := div $ramUsedKB 1000000 }}
73+
{{ $ramTotalGB := div $ramTotalKB 1000000 }}
74+
75+
<div class="flex justify-between text-center">
76+
<div>
77+
<div class="size-h3 color-highlight">{{ $cpuPercent }}%</div>
78+
<div class="size-h6">CPU</div>
79+
</div>
80+
<div>
81+
<div class="size-h3 color-highlight">{{ $ramPercent }}%</div>
82+
<div class="size-h6">RAM</div>
83+
<div class="size-h6 margin-top-5">
84+
{{ if ge $ramUsedGB 1.0 }}
85+
{{ $ramUsedGB | printf "%.1f" }}GB/{{ $ramTotalGB | printf "%.0f" }}GB
86+
{{ else }}
87+
{{ $ramUsedMB | printf "%.0f" }}MB/{{ $ramTotalGB | printf "%.0f" }}GB
88+
{{ end }}
89+
</div>
90+
</div>
91+
<div>
92+
<div class="size-h3 color-highlight">{{ $storagePercent }}%</div>
93+
<div class="size-h6">STORAGE</div>
94+
<div class="size-h6 margin-top-5">
95+
{{ div $used 1099511627776 | printf "%.2f" }}TB/{{ div $total 1099511627776 | printf "%.2f" }}TB
96+
</div>
97+
</div>
98+
</div>
99+
{{ else }}
100+
<p class="color-negative">Failed to fetch system data</p>
101+
{{ end }}
102+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
title: Synology Disk Station
2+
description: Displays RAM and CPU usage and used storage of your Synology NAS
3+
author: Chachigo
8.66 KB
Loading

0 commit comments

Comments
 (0)