Publishing My Synology NAS Status on the Web: How I Crashed and Burned on the DSM API, Then Solved It by Reading /proc Directly
I wanted a live Synology NAS status panel on my site. The DSM API kept failing with error 101, so I read /proc with PHP instead and published it via Cloudflare Tunnel.

Contents22 items
Wouldn’t it be kind of cool to have your NAS status displayed “quietly” somewhere on your blog?
What the CPU load is, that all the drives are healthy, how many days it’s been up… streaming that kind of info to the web in real time. You know the look — it just oozes engineer vibes.
So I built a system that shows my Synology NAS’s status on my website in real time.
But then… an unexpected enemy blocked my path.
“The official Synology API doesn’t work…”
I thought I might have the API name wrong, so I looked it up and got back 988 APIs. I pinned down the right API name from those and tried every authentication method there was, yet right to the end I was stopped by a wall called error 101.
The final solution was an almost too-simple idea: “The NAS runs Linux, so why not just read /proc directly?”
In the end, I managed to get more information than the API would have given me, and more simply. This time I’ll tell you the whole story.
The finished setup at a glance#
First, let’s look at the setup that’s actually running in the end.
PHP on the NAS (reads /proc) → Cloudflare Tunnel → Public URL → fetch from the websiteHere’s the data it can display. All of it in real time.
- Total storage capacity and usage (how many TB of the 97.7 TB are in use)
- Individual health status of the 8 HDDs (RAID 5)
- CPU load (load average)
- Memory usage
- Network throughput (receive/send MB/s)
- System uptime
Why use Cloudflare Tunnel?#
The NAS only has a private IP behind the router, so you need some kind of mechanism to reach it from outside. There are three options.
| Method | Security | Effort |
|---|---|---|
| Port forwarding (DDNS) | ⚠️ High risk (the NAS becomes a direct target) | Medium |
| Via VPN | ✅ Low risk | ❌ High (visitors need a VPN too) |
| Cloudflare Tunnel | ✅ Low risk (the NAS is unreachable from outside) | ✅ Low |
With Cloudflare Tunnel, a cloudflared process on the NAS keeps an outbound connection open to Cloudflare’s edge. No port is needed for direct access to the NAS from outside, and Cloudflare handles TLS termination too.
In other words, you don’t have to open any NAS ports to the internet.
STEP 1: Taking on the Synology DSM API (and losing)#
First, understand how the API works#
Synology DSM provides a REST-style Web API. The flow is simple:
- Log in with
SYNO.API.Auth→ get a session ID (SID) - Call each API with the SID attached
I started writing an implementation that calls it with PHP’s file_get_contents. I created a dedicated authentication user, ITI-API, and added it to the administrators group. I thought I was all set.
The API name was buried among 988 entries#
The first one I tried, SYNO.Storage.CGI.Disk, returned error 102 (API not found). SYNO.Storage.CGI.Storage did the same.
“Huh, is the API name wrong?”
To find the right API name, I fetched the full list of APIs… and got back 988 of them.
$info = file_get_contents(
"http://localhost:5000/webapi/query.cgi" .
"?api=SYNO.API.Info&version=1&method=query&query=all&_sid=$sid"
);
// → returns all 988 APIsAfter narrowing the 988 down to storage-related ones, these turned out to be the right API names.
SYNO.Core.Storage.Disk ← Disk information
SYNO.Core.Storage.Volume ← Volume information
SYNO.Core.Storage.Pool ← Pool/RAID informationThese are accessed via entry.cgi. “All right, now it’ll work!”
And then, the wall of error 101#
GET request → error 101
POST JSON → error 101
SynoToken (CSRF token) → error 101
additional parameter → error 101…Total wipeout.
With the right API names and the right authentication methods, every pattern I tried kept returning error 101 (Invalid parameter).
“Am I using this wrong, or does it just not work at all…?”
My final guess is this: the SYNO.Core.* APIs only work within a browser session of the DSM admin interface, and either some session validation beyond CSRF protection is running, or a separate application permission specific to Storage Manager is required. I couldn’t say for sure, but this is where I decided to retreat.
Conclusion: In the end, I’m not using the official Synology API.
STEP 2: Reading Linux /proc directly with PHP#
I changed course.
Synology DSM is its own UI on top of a Linux kernel. I realized that PHP running in WebStation can access the NAS’s local file system — in other words, it can read the /proc file system.
Here’s a summary of the information you can get.
| Information | Source |
|---|---|
| Total and free volume capacity | disk_total_space() / disk_free_space() |
| RAID status and drive health | /proc/mdstat |
| CPU load (load average) | sys_getloadavg() |
| Memory usage | /proc/meminfo |
| Cumulative network traffic | /proc/net/dev |
| System uptime | /proc/uptime |
| Drive temperature | /sys/class/thermal (gave up due to insufficient permissions) |
Whatever PHP’s built-in functions can get, I get with those; for the rest, I just read text files under /proc with file_get_contents and parse them with regular expressions. All the hassle of API session management and authentication tokens simply disappeared.
Parsing /proc/mdstat: a Synology-specific trap#
Drive health is read from /proc/mdstat. This file shows the state of Linux software RAID (md).
Here’s what the actual contents of /proc/mdstat look like (for 8 drives in RAID 5).
md2 : active raid5 sata1p5[0] sata8p5[7] sata7p5[6] ... sata2p5[1]
109306083712 blocks super 1.2 level 5, 64k chunk [8/8] [UUUUUUUU]Each U in [UUUUUUUU] is the state of one drive: U=healthy, _=failed. If all 8 are U, they’re all alive.
On Synology, the usual regex doesn’t work as is#
This is where I first got stuck. On typical Linux, RAID device names are sda, sdb, sdc… but Synology uses its own naming scheme: sata1, sata2… sata8.
// ❌ Regex for typical Linux (doesn't work on Synology)
preg_match_all('/sd([a-z]+)\[(\d+)\]/', $mdstat, $m);
// ✅ For Synology (written with sata numbers)
preg_match_all('/sata(\d+)p\d+\[(\d+)\](\(F\)|\(S\))?/', $block, $m);You can also check the flags for when a drive fails.
(F)= Failed (failed drive)(S)= Spare (hot spare)
How to get network throughput#
/proc/net/dev only holds cumulative byte counts per network interface. To get “the current transfer rate (MB/s),” you need to calculate the difference from the previous value.
Example of /proc/net/dev:
eth0: 3663582201582 ... 650931701580 ...
└── cumulative bytes received └── cumulative bytes sentThe implementation saves the previously fetched values to /tmp/iti_net_prev.json and calculates the difference on the next access.
$dt = $now - $prev['t']; // seconds elapsed since last time
if ($dt > 0 && $dt < 300) { // only data from within 5 minutes is valid
$rx_mbps = ($curr_rx - $prev['rx']) / $dt / 1024 / 1024;
$tx_mbps = ($curr_tx - $prev['tx']) / $dt / 1024 / 1024;
}Since the PHP cache is 60 seconds, what’s displayed is effectively “the average throughput over the past 60 seconds.”
The finished PHP code (final version)#
Place it at /volume1/web/iti-api/nas-status.php.
<?php
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Cache-Control: max-age=60');
// API key authentication
$api_key = $_GET['key'] ?? '';
if ($api_key !== 'YOUR_API_KEY') {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
exit;
}
// 60-second file cache
$cache_file = '/tmp/iti_nas_status.json';
if (file_exists($cache_file) && (time() - filemtime($cache_file)) < 60) {
echo file_get_contents($cache_file);
exit;
}
// ── Volume capacity (PHP built-ins) ──
$total = disk_total_space('/volume1') ?: 0;
$free = disk_free_space('/volume1') ?: 0;
$used = $total - $free;
$total_tb = round($total / (1024 ** 4), 1);
$used_tb = round($used / (1024 ** 4), 1);
$used_pct = $total > 0 ? round($used / $total * 100, 1) : 0;
// ── Drive health (/proc/mdstat) ──
$drives = []; $vol_status = 'normal';
$mdstat = @file_get_contents('/proc/mdstat');
if ($mdstat) {
preg_match('/^md2\s*:.*?(?=^md[0-9]|\z)/ms', $mdstat, $md2);
$block = $md2[0] ?? $mdstat;
preg_match_all('/sata(\d+)p\d+\[(\d+)\](\(F\)|\(S\))?/', $block, $m);
preg_match('/\[\d+\/\d+\]\s*\[([U_]+)\]/', $block, $health);
$health_str = $health[1] ?? str_repeat('U', 8);
$drive_map = [];
for ($i = 0; $i < count($m[0]); $i++) {
$sata_num = (int)$m[1][$i];
$position = (int)$m[2][$i];
$flag = $m[3][$i] ?? '';
$up = $health_str[$position] ?? 'U';
$status = ($flag === '(F)' || $up === '_') ? 'failed'
: ($flag === '(S)' ? 'spare' : 'normal');
$drive_map[$sata_num] = ['slot' => $sata_num, 'status' => $status];
}
ksort($drive_map);
$drives = array_values($drive_map);
for ($i = count($drives) + 1; $i <= 8; $i++) $drives[] = ['slot'=>$i,'status'=>'normal'];
if (strpos($health_str, '_') !== false) $vol_status = 'degraded';
if (strpos($mdstat, 'recovering') !== false) $vol_status = 'recovering';
if (strpos($mdstat, 'resync') !== false) $vol_status = 'resyncing';
} else {
for ($i = 1; $i <= 8; $i++) $drives[] = ['slot'=>$i,'status'=>'normal'];
}
// ── CPU load ──
$load = sys_getloadavg();
$cpuinfo = @file_get_contents('/proc/cpuinfo');
$cpu_cores = $cpuinfo ? max(1, preg_match_all('/^processor\s*:/m', $cpuinfo)) : 4;
$cpu_pct = round(min(100, ($load[0] / $cpu_cores) * 100), 1);
// ── Memory ──
$meminfo = @file_get_contents('/proc/meminfo');
$mem_total_kb = 0; $mem_avail_kb = 0;
if ($meminfo) {
preg_match('/MemTotal:\s+(\d+)/', $meminfo, $mt);
preg_match('/MemAvailable:\s+(\d+)/', $meminfo, $ma);
$mem_total_kb = (int)($mt[1] ?? 0);
$mem_avail_kb = (int)($ma[1] ?? 0);
}
$mem_used_pct = $mem_total_kb > 0
? round(($mem_total_kb - $mem_avail_kb) / $mem_total_kb * 100, 1) : 0;
// ── Network throughput (difference calculation) ──
$rx_mbps = 0; $tx_mbps = 0;
$net_prev = '/tmp/iti_net_prev.json';
$netdev = @file_get_contents('/proc/net/dev');
if ($netdev && preg_match(
'/^\s*eth0:\s*(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+(\d+)/m',
$netdev, $n)) {
$curr_rx = (int)$n[1]; $curr_tx = (int)$n[2]; $now = time();
if (file_exists($net_prev)) {
$prev = json_decode(file_get_contents($net_prev), true);
$dt = $now - ($prev['t'] ?? 0);
if ($dt > 0 && $dt < 300) {
$rx_mbps = max(0, round(($curr_rx - ($prev['rx'] ?? 0)) / $dt / 1024 / 1024, 2));
$tx_mbps = max(0, round(($curr_tx - ($prev['tx'] ?? 0)) / $dt / 1024 / 1024, 2));
}
}
file_put_contents($net_prev, json_encode(['t'=>$now,'rx'=>$curr_rx,'tx'=>$curr_tx]));
}
// ── Uptime ──
$uptime_raw = @file_get_contents('/proc/uptime');
$uptime_sec = $uptime_raw ? (int)explode(' ', $uptime_raw)[0] : 0;
$uptime_str = intdiv($uptime_sec, 86400) . 'd '
. intdiv($uptime_sec % 86400, 3600) . 'h '
. intdiv($uptime_sec % 3600, 60) . 'm';
$result = [
'ok' => true,
'volume' => ['total_tb'=>$total_tb,'used_tb'=>$used_tb,'used_pct'=>$used_pct,'status'=>$vol_status],
'drives' => $drives,
'cpu' => ['load_1m'=>round($load[0],2),'cores'=>$cpu_cores,'pct'=>$cpu_pct],
'memory' => ['used_pct'=>$mem_used_pct,'total_gb'=>round($mem_total_kb/1024/1024,1)],
'network' => ['rx_mbps'=>$rx_mbps,'tx_mbps'=>$tx_mbps],
'uptime' => $uptime_str,
];
$json = json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
file_put_contents($cache_file, $json);
echo $json;Call the API, and you get JSON like this back.
{
"ok": true,
"volume": { "total_tb": 97.7, "used_tb": 35.8, "used_pct": 36.7, "status": "normal" },
"drives": [ { "slot": 1, "status": "normal" }, ... ],
"cpu": { "load_1m": 1.27, "cores": 4, "pct": 31.8 },
"memory": { "used_pct": 24.6, "total_gb": 32.0 },
"network": { "rx_mbps": 3.4, "tx_mbps": 1.2 },
"uptime": "75d 22h 33m"
}The frontend JavaScript#
On the web page side, it just fetches the JSON with fetch and updates DOM elements. It runs only once on page load, and if the NAS is offline, the static display stays as is without errors.
(async function fetchNasStatus() {
try {
const res = await fetch('https://iti-api.itis.co.jp/nas-status.php?key=YOUR_API_KEY');
const data = await res.json();
if (!data.ok) return;
// Storage
document.getElementById('nas-total-tb').textContent = data.volume.total_tb + ' TB';
document.getElementById('nas-used-pct').textContent = data.volume.used_pct + '%';
// Header status
const allHealthy = data.drives.every(d => d.status === 'normal');
const label = data.volume.status === 'normal' && allHealthy
? 'ALL DRIVES HEALTHY'
: data.volume.status === 'degraded' ? 'DEGRADED — CHECK DRIVES' : 'RESYNCING';
document.getElementById('nas-status-text').textContent = 'SYNOLOGY NAS — ' + label;
// Drive bars (red on failure)
data.drives.forEach(dr => {
const el = document.getElementById('nas-drive-' + dr.slot);
if (!el) return;
if (dr.status === 'failed') {
el.style.background = 'linear-gradient(90deg, #ff2244, #cc0022)';
el.style.boxShadow = '0 0 8px rgba(255,34,68,0.6)';
}
});
// CPU (orange above 70%, red above 90%)
const cpuBar = document.getElementById('nas-cpu-bar');
cpuBar.style.width = data.cpu.pct + '%';
cpuBar.className = 'nas-sys-fill'
+ (data.cpu.pct > 90 ? ' alert' : data.cpu.pct > 70 ? ' warn' : '');
document.getElementById('nas-cpu-val').textContent = data.cpu.load_1m + ' avg';
// Memory
const ramBar = document.getElementById('nas-ram-bar');
ramBar.style.width = data.memory.used_pct + '%';
ramBar.className = 'nas-sys-fill'
+ (data.memory.used_pct > 90 ? ' alert' : data.memory.used_pct > 75 ? ' warn' : '');
document.getElementById('nas-ram-val').textContent = data.memory.used_pct + '%';
// Network speed (auto-switch between MB/s and KB/s)
const fmt = mb => mb >= 1 ? mb.toFixed(1) + ' MB/s'
: mb > 0 ? (mb * 1024).toFixed(0) + ' KB/s' : '0 B/s';
document.getElementById('nas-rx-speed').textContent = fmt(data.network.rx_mbps);
document.getElementById('nas-tx-speed').textContent = fmt(data.network.tx_mbps);
// Uptime
document.getElementById('nas-uptime').textContent = data.uptime;
} catch(e) { /* When the NAS is offline, keep the static display */ }
})();Setting up Cloudflare Tunnel#
Prerequisites#
- Your domain is already added to Cloudflare (the DNS nameservers point to Cloudflare)
- Cloudflared is already installed from Synology Package Center
Configure the tunnel and Public Hostname in Zero Trust#
- dash.cloudflare.com → Zero Trust → Networks → Tunnels
- “Create a tunnel” → select Cloudflared
- Start the connector on the NAS (this can be automated from Package Center)
- Add a Public Hostname
| Setting | Value |
|---|---|
| Subdomain | iti-api |
| Domain | itis.co.jp |
| Service Type | HTTP |
| URL | localhost:80 |
When you save, Cloudflare automatically creates a CNAME record.
Set up a virtual host in WebStation#
DSM → Web Station → Web Portal → “Create”:
| Setting | Value |
|---|---|
| Portal type | Name-based |
| Hostname | iti-api.itis.co.jp |
| Port | 80 (HTTP) |
| Back-end server | PHP 8.2 service |
| Document root | /volume1/web/iti-api |
Troubleshooting#
Here’s a rundown of the places I actually got stuck.
① Getting “API not found” (error 102/103)#
Usually the API name, such as SYNO.Storage.CGI.Disk, is wrong. Fetch all 988 with SYNO.API.Info?query=all, search for the storage-related ones, and pin down the right API name. The correct ones are SYNO.Core.Storage.Disk / SYNO.Core.Storage.Volume.
② The /proc/mdstat regex doesn’t match#
Synology’s RAID device names are sata1 through sata8. A regex that assumes sda/sdb won’t work as is. Refer to the sample code above.
③ I added a Cloudflare Tunnel but can’t access it#
Without a virtual host of the same name set up in WebStation, requests won’t be routed. Add the corresponding portal under DSM → Web Station → Web Portal.
④ The browser can’t connect, but dig returns the correct IP#
macOS’s DNS cache may be returning an old IP.
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponderSummary#
- In the end, I’m not using the Synology DSM API. I couldn’t get past error 101 with the
SYNO.Core.*APIs and gave up - The NAS runs Linux, so you can read
/proc. Reading it directly from PHP in WebStation got me more information than the API would have - Published securely with Cloudflare Tunnel. You can publish over HTTPS without opening any NAS ports to the outside
- Watch out for Synology-specific traps. Device names in
/proc/mdstataresata1throughsata8(notsda/sdb) - Network speed requires a difference calculation.
/proc/net/devholds cumulative values, so save the previous value to a file and calculate from that
Just putting your NAS status on the web gives you a bit of a server-admin vibe. Every time I see the “ALL DRIVES HEALTHY” display showing all drives in good shape, I get a strange sense of relief: “All right, everyone’s doing fine today.”
Give it a try!