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: Fix #148: Disk Metrics come back from the API in GB
<!--
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**

The SabnzbD API uses inconsistent metrics in it's responses -- diskspace* and diskspacetotal* are expressed in GB, we are parsing them in MB. This PR adjusts this to the correct behavior.

**Benefits**

Correct statistics

**Possible drawbacks**

N/A

**Applicable issues**

<!-- Enter any applicable Issues here (You can reference an issue using #) -->
- fixes #148

**Additional information**

N/A


Patch:
diff --git a/internal/sabnzbd/model/model.go b/internal/sabnzbd/model/model.go
index b372360..88664ea 100644
--- a/internal/sabnzbd/model/model.go
+++ b/internal/sabnzbd/model/model.go
@@ -15,6 +15,7 @@ type Status int
 const (
 	KB = 1024
 	MB = 1024 * KB
+	GB = 1024 * MB
 )
 
 const (
@@ -152,10 +153,10 @@ func (q *QueueStats) UnmarshalJSON(data []byte) error {
 		return fmt.Errorf("Error parsing queue stats: %w", err)
 	}
 
-	q.DownloadDirDiskspaceUsed *= MB
-	q.DownloadDirDiskspaceTotal *= MB
-	q.CompletedDirDiskspaceUsed *= MB
-	q.CompletedDirDiskspaceTotal *= MB
+	q.DownloadDirDiskspaceUsed *= GB
+	q.DownloadDirDiskspaceTotal *= GB
+	q.CompletedDirDiskspaceUsed *= GB
+	q.CompletedDirDiskspaceTotal *= 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 c238eb7..1cc8991 100644
--- a/internal/sabnzbd/model/model_test.go
+++ b/internal/sabnzbd/model/model_test.go
@@ -58,10 +58,10 @@ func TestQueueStats_UnmarshalJSON(t *testing.T) {
 	require.False(queueStats.Paused)
 	require.False(queueStats.PausedAll)
 	require.Equal(time.Duration(0), queueStats.PauseDuration)
-	require.Equal(3.64627623936e+10, queueStats.DownloadDirDiskspaceUsed)
-	require.Equal(4.4971327488e+10, queueStats.DownloadDirDiskspaceTotal)
-	require.Equal(3.64061392896e+10, queueStats.CompletedDirDiskspaceUsed)
-	require.Equal(4.4972376064e+10, queueStats.CompletedDirDiskspaceTotal)
+	require.Equal(3.73378686910464e+13, queueStats.DownloadDirDiskspaceUsed)
+	require.Equal(4.6050639347712e+13, queueStats.DownloadDirDiskspaceTotal)
+	require.Equal(3.72798866325504e+13, queueStats.CompletedDirDiskspaceUsed)
+	require.Equal(4.6051713089536e+13, queueStats.CompletedDirDiskspaceTotal)
 	require.Equal(100.0, queueStats.SpeedLimit)
 	require.Equal(1.048576e+09, queueStats.SpeedLimitAbs)
 	require.Equal(0.0, queueStats.HaveWarnings)
diff --git a/internal/sabnzbd/test_fixtures/expected_metrics.txt b/internal/sabnzbd/test_fixtures/expected_metrics.txt
index 9e8211b..8f43dea 100644
--- a/internal/sabnzbd/test_fixtures/expected_metrics.txt
+++ b/internal/sabnzbd/test_fixtures/expected_metrics.txt
@@ -6,12 +6,12 @@ sabnzbd_article_cache_articles{target="http://127.0.0.1:39965"} 0
 sabnzbd_article_cache_bytes{target="http://127.0.0.1:39965"} 0
 # HELP sabnzbd_disk_total_bytes Total Bytes on the SabnzbD instance's disk
 # TYPE sabnzbd_disk_total_bytes gauge
-sabnzbd_disk_total_bytes{folder="complete",target="http://127.0.0.1:39965"} 4.4972376064e+10
-sabnzbd_disk_total_bytes{folder="download",target="http://127.0.0.1:39965"} 4.4971327488e+10
+sabnzbd_disk_total_bytes{folder="complete",target="http://127.0.0.1:39965"} 4.6051713089536e+13
+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.64061392896e+10
-sabnzbd_disk_used_bytes{folder="download",target="http://127.0.0.1:39965"} 3.64627623936e+10
+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
 # 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