Repository: onedr0p/exportarr (go)

Issue:
sabnzbd - metrics values
Saw reference to `sabnzbd` metrics being available in latest version.  Working on a Grafana Dashboard for it, but having some issues with 2 metrics:

* `sabnzbd_disk_total_bytes` seems to be reporting size in number of 1K blocks not bytes.  I get `209715200` 1K blocks instead of `214748364800` bytes.

* `sabnzbd_disk_used_bytes` not sure what its reporting as it shows up as a decimal such `207901163.52`. I'm expecting more like `1855259765` bytes (reported by `du -b /downloads`).  Value reported seems closer to free space in 1K blocks `207904768` than used space in bytes.





Pull request description:
diskspace1 * diskspace2 are free space, rather than used
<!--
Before you open the request please review the following guidelines and tips to help it be more easily integrated:

- Describe the scope of your change - i.e. what the change does.
- Describe any known limitations with your change.
- Please run any tests or examples that can exercise your modified code.

Thank you for contributing! We will try to test and integrate the change as soon as we can. There is no need to bump or check in on a pull request (it will clutter the discussion of the request).

Also don't be worried if the request is closed or not integrated sometimes our priorities might not match the priorities of the pull request. Don't fret, the open source community thrives on forks and GitHub makes it easy to keep your changes in a forked repo.
-->

**Description of the change**

Sorry for the double PR @onedr0p. Realized when I went to verify these metrics on my instance that these are actually disk free, not disk used. I think disk used makes a bit more sense, so updated to math disk used from `total - free`.

**Benefits**

Again, correct metrics.

**Possible drawbacks**

<!-- Describe any known limitations with your change -->

**Applicable issues**

<!-- Enter any applicable Issues here (You can reference an issue using #) -->
- fixes #148 

**Additional information**

<!-- If there's anything else that's important and relevant to your pull request, mention that information here.-->


Patch:
diff --git a/internal/sabnzbd/model/model.go b/internal/sabnzbd/model/model.go
index 88664ea..2cd58d0 100644
--- a/internal/sabnzbd/model/model.go
+++ b/internal/sabnzbd/model/model.go
@@ -133,9 +133,9 @@ func (q *QueueStats) UnmarshalJSON(data []byte) error {
 
 	var err error
 	q.PauseDuration, err = parseDuration(queue["pause_int"], err)
-	q.DownloadDirDiskspaceUsed, err = parseFloat(queue["diskspace1"], err)
+	downloadDirDiskspaceFree, err := parseFloat(queue["diskspace1"], err)
+	completedDirDiskspaceFree, err := parseFloat(queue["diskspace2"], err)
 	q.DownloadDirDiskspaceTotal, err = parseFloat(queue["diskspacetotal1"], err)
-	q.CompletedDirDiskspaceUsed, err = parseFloat(queue["diskspace2"], err)
 	q.CompletedDirDiskspaceTotal, err = parseFloat(queue["diskspacetotal2"], err)
 	q.SpeedLimit, err = parseSize(queue["speedlimit"], err)
 	q.SpeedLimitAbs, err = parseSize(queue["speedlimit_abs"], err)
@@ -153,10 +153,11 @@ func (q *QueueStats) UnmarshalJSON(data []byte) error {
 		return fmt.Errorf("Error parsing queue stats: %w", err)
 	}
 
-	q.DownloadDirDiskspaceUsed *= GB
 	q.DownloadDirDiskspaceTotal *= GB
-	q.CompletedDirDiskspaceUsed *= GB
+
 	q.CompletedDirDiskspaceTotal *= GB
+	q.DownloadDirDiskspaceUsed = q.DownloadDirDiskspaceTotal - (downloadDirDiskspaceFree * GB)
+	q.CompletedDirDiskspaceUsed = q.CompletedDirDiskspaceTotal - (completedDirDiskspaceFree * GB)
 	q.Speed *= KB
 	q.RemainingSize *= MB
 	q.Size *= MB


Test patch:
diff --git a/internal/sabnzbd/model/model_test.go b/internal/sabnzbd/model/model_test.go
index 1cc8991..2476ae8 100644
--- a/internal/sabnzbd/model/model_test.go
+++ b/internal/sabnzbd/model/model_test.go
@@ -58,9 +58,9 @@ func TestQueueStats_UnmarshalJSON(t *testing.T) {
 	require.False(queueStats.Paused)
 	require.False(queueStats.PausedAll)
 	require.Equal(time.Duration(0), queueStats.PauseDuration)
-	require.Equal(3.73378686910464e+13, queueStats.DownloadDirDiskspaceUsed)
+	require.Equal(8.712770656665602e+12, queueStats.DownloadDirDiskspaceUsed)
 	require.Equal(4.6050639347712e+13, queueStats.DownloadDirDiskspaceTotal)
-	require.Equal(3.72798866325504e+13, queueStats.CompletedDirDiskspaceUsed)
+	require.Equal(8.771826456985602e+12, queueStats.CompletedDirDiskspaceUsed)
 	require.Equal(4.6051713089536e+13, queueStats.CompletedDirDiskspaceTotal)
 	require.Equal(100.0, queueStats.SpeedLimit)
 	require.Equal(1.048576e+09, queueStats.SpeedLimitAbs)
diff --git a/internal/sabnzbd/test_fixtures/expected_metrics.txt b/internal/sabnzbd/test_fixtures/expected_metrics.txt
index 8f43dea..fc230e4 100644
--- a/internal/sabnzbd/test_fixtures/expected_metrics.txt
+++ b/internal/sabnzbd/test_fixtures/expected_metrics.txt
@@ -10,8 +10,8 @@ sabnzbd_disk_total_bytes{folder="complete",target="http://127.0.0.1:39965"} 4.60
 sabnzbd_disk_total_bytes{folder="download",target="http://127.0.0.1:39965"} 4.6050639347712e+13
 # HELP sabnzbd_disk_used_bytes Used Bytes Used on the SabnzbD instance's disk
 # TYPE sabnzbd_disk_used_bytes gauge
-sabnzbd_disk_used_bytes{folder="complete",target="http://127.0.0.1:39965"} 3.72798866325504e+13
-sabnzbd_disk_used_bytes{folder="download",target="http://127.0.0.1:39965"} 3.73378686910464e+13
+sabnzbd_disk_used_bytes{folder="complete",target="http://127.0.0.1:39965"} 8.771826456985602e+12
+sabnzbd_disk_used_bytes{folder="download",target="http://127.0.0.1:39965"} 8.712770656665602e+12
 # HELP sabnzbd_downloaded_bytes Total Bytes Downloaded by SABnzbd
 # TYPE sabnzbd_downloaded_bytes counter
 sabnzbd_downloaded_bytes{target="http://127.0.0.1:39965"} 5.869995742788e+12