Skip to content

🎧 Your Personal Streaming Service

fix(insights): check if running in a container

Deluan906ac635c296
diff --git a/Dockerfile b/Dockerfile
index 7e9a0c4c0..7c966dc1c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -134,6 +134,7 @@ ENV ND_MUSICFOLDER=/music
ENV ND_DATAFOLDER=/data
ENV ND_PORT=4533
ENV GODEBUG="asyncpreemptoff=1"
+RUN touch /.nddockerenv
EXPOSE ${ND_PORT}
HEALTHCHECK CMD wget -O- http://localhost:${ND_PORT}/ping || exit 1
diff --git a/consts/consts.go b/consts/consts.go
index fa57562a1..eb0c34a33 100644
--- a/consts/consts.go
+++ b/consts/consts.go
@@ -3,6 +3,7 @@ package consts
import (
"crypto/md5"
"fmt"
+ "os"
"path/filepath"
"strings"
"time"
@@ -134,3 +135,11 @@ var (
ServerStart = time.Now()
)
+
+var InContainer = func() bool {
+ // Check if the /.nddockerenv file exists
+ if _, err := os.Stat("/.nddockerenv"); err == nil {
+ return true
+ }
+ return false
+}()
diff --git a/core/metrics/insights.go b/core/metrics/insights.go
index 8a4b1a6d4..27d154f1e 100644
--- a/core/metrics/insights.go
+++ b/core/metrics/insights.go
@@ -151,6 +151,7 @@ var staticData = sync.OnceValue(func() insights.Data {
// Build info
data.Build.Settings, data.Build.GoVersion = buildInfo()
+ data.OS.Containerized = consts.InContainer
// OS info
data.OS.Type = runtime.GOOS
diff --git a/core/metrics/insights/data.go b/core/metrics/insights/data.go
index 0cf7b0411..cf28c43a3 100644
--- a/core/metrics/insights/data.go
+++ b/core/metrics/insights/data.go
@@ -10,11 +10,12 @@ type Data struct {
GoVersion string `json:"goVersion"`
} `json:"build"`
OS struct {
- Type string `json:"type"`
- Distro string `json:"distro,omitempty"`
- Version string `json:"version,omitempty"`
- Arch string `json:"arch"`
- NumCPU int `json:"numCPU"`
+ Type string `json:"type"`
+ Distro string `json:"distro,omitempty"`
+ Version string `json:"version,omitempty"`
+ Containerized bool `json:"containerized"`
+ Arch string `json:"arch"`
+ NumCPU int `json:"numCPU"`
} `json:"os"`
Mem struct {
Alloc uint64 `json:"alloc"`