mirror of
https://github.com/JustKato/drive-health.git
synced 2026-03-04 08:29:45 +02:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cbe252fe94 | |||
| 07dec16aa4 | |||
| 545eed44cd | |||
| eb94ce4552 | |||
| c0f1ed6879 | |||
| c4aef27eda | |||
| 8f8da162e9 | |||
| 5cc58c7d53 | |||
| 21f24899a2 |
10
.env.example
10
.env.example
@@ -1,3 +1,11 @@
|
|||||||
|
# The frequency at which to fetch the temperature of ALL disks and add it to the database
|
||||||
DISK_FETCH_FREQUENCY=5
|
DISK_FETCH_FREQUENCY=5
|
||||||
MEMORY_DUMP_FREQUENCY=60
|
|
||||||
|
# The maximum age of logs in seconds
|
||||||
MAX_HISTORY_AGE=2592000
|
MAX_HISTORY_AGE=2592000
|
||||||
|
|
||||||
|
# The ip:port to listen to for the application
|
||||||
|
LISTEN=":8080"
|
||||||
|
|
||||||
|
# Basic Security
|
||||||
|
ACCESS_PASSWORD=
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,5 @@
|
|||||||
snapshots.dat
|
snapshots.dat
|
||||||
.env
|
.env
|
||||||
|
dist
|
||||||
|
data.db
|
||||||
|
data.sqlite
|
||||||
17
build.sh
Executable file
17
build.sh
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
APP_NAME="drive-health"
|
||||||
|
DIST_DIR="dist"
|
||||||
|
|
||||||
|
# Create the dist directory if it doesn't exist
|
||||||
|
mkdir -p $DIST_DIR
|
||||||
|
|
||||||
|
# Build the application
|
||||||
|
echo "Building the application..."
|
||||||
|
GOOS=linux GOARCH=amd64 go build -o $DIST_DIR/$APP_NAME
|
||||||
|
|
||||||
|
# Copy additional resources (like .env, static files, templates) to the dist directory
|
||||||
|
echo "Copying additional resources..."
|
||||||
|
cp -r .env static templates $DIST_DIR/
|
||||||
|
|
||||||
|
echo "Compilation and packaging completed."
|
||||||
8
go.mod
8
go.mod
@@ -14,21 +14,29 @@ require (
|
|||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.17.0 // indirect
|
github.com/go-playground/validator/v10 v10.17.0 // indirect
|
||||||
github.com/goccy/go-json v0.10.2 // indirect
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||||
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/joho/godotenv v1.5.1 // indirect
|
github.com/joho/godotenv v1.5.1 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
|
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
|
||||||
github.com/leodido/go-urn v1.2.4 // indirect
|
github.com/leodido/go-urn v1.2.4 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.19 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||||
|
github.com/wcharczuk/go-chart/v2 v2.1.1 // indirect
|
||||||
golang.org/x/arch v0.7.0 // indirect
|
golang.org/x/arch v0.7.0 // indirect
|
||||||
golang.org/x/crypto v0.18.0 // indirect
|
golang.org/x/crypto v0.18.0 // indirect
|
||||||
|
golang.org/x/image v0.11.0 // indirect
|
||||||
golang.org/x/net v0.20.0 // indirect
|
golang.org/x/net v0.20.0 // indirect
|
||||||
golang.org/x/sys v0.16.0 // indirect
|
golang.org/x/sys v0.16.0 // indirect
|
||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
google.golang.org/protobuf v1.32.0 // indirect
|
google.golang.org/protobuf v1.32.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
gorm.io/driver/sqlite v1.5.4 // indirect
|
||||||
|
gorm.io/gorm v1.25.5 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
46
go.sum
46
go.sum
@@ -27,9 +27,15 @@ github.com/go-playground/validator/v10 v10.17.0 h1:SmVVlfAOtlZncTxRuinDPomC2DkXJ
|
|||||||
github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
||||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||||
|
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||||
|
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||||
|
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
@@ -42,6 +48,8 @@ github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
|
|||||||
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
@@ -64,21 +72,55 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
|
|||||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||||
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
||||||
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||||
|
github.com/wcharczuk/go-chart/v2 v2.1.1 h1:2u7na789qiD5WzccZsFz4MJWOJP72G+2kUuJoSNqWnE=
|
||||||
|
github.com/wcharczuk/go-chart/v2 v2.1.1/go.mod h1:CyCAUt2oqvfhCl6Q5ZvAZwItgpQKZOkCJGb+VGv6l14=
|
||||||
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=
|
golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=
|
||||||
golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
|
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
|
||||||
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
|
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
|
||||||
|
golang.org/x/image v0.11.0 h1:ds2RoQvBvYTiJkwpSFDwCcDFNX7DqjL2WsUgTNk0Ooo=
|
||||||
|
golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
|
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
|
||||||
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
|
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
|
||||||
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
||||||
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||||
@@ -86,5 +128,9 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
|
|||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gorm.io/driver/sqlite v1.5.4 h1:IqXwXi8M/ZlPzH/947tn5uik3aYQslP9BVveoax0nV0=
|
||||||
|
gorm.io/driver/sqlite v1.5.4/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4=
|
||||||
|
gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
|
||||||
|
gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
|
||||||
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
||||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||||
|
|||||||
@@ -9,9 +9,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DHConfig struct {
|
type DHConfig struct {
|
||||||
DiskFetchFrequency int `json:"diskFetchFrequency"`
|
DiskFetchFrequency int `json:"diskFetchFrequency"`
|
||||||
MemoryDumpFrequency int `json:"memoryDumpFrequency"`
|
MaxHistoryAge int `json:"maxHistoryAge"`
|
||||||
MaxHistoryAge int `json:"maxHistoryAge"`
|
DatabaseFilePath string
|
||||||
|
Listen string
|
||||||
|
IdentityUsername string
|
||||||
|
IdentityPassword string
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConfiguration() DHConfig {
|
func GetConfiguration() DHConfig {
|
||||||
@@ -21,9 +24,13 @@ func GetConfiguration() DHConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
config := DHConfig{
|
config := DHConfig{
|
||||||
DiskFetchFrequency: 5, // default value
|
DiskFetchFrequency: 5, // default value
|
||||||
MemoryDumpFrequency: 60, // default value
|
MaxHistoryAge: 2592000, // default value
|
||||||
MaxHistoryAge: 2592000, // default value
|
DatabaseFilePath: "./data.sqlite",
|
||||||
|
IdentityUsername: "admin",
|
||||||
|
IdentityPassword: "admin",
|
||||||
|
|
||||||
|
Listen: ":8080",
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, exists := os.LookupEnv("DISK_FETCH_FREQUENCY"); exists {
|
if val, exists := os.LookupEnv("DISK_FETCH_FREQUENCY"); exists {
|
||||||
@@ -32,17 +39,27 @@ func GetConfiguration() DHConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, exists := os.LookupEnv("MEMORY_DUMP_FREQUENCY"); exists {
|
|
||||||
if intValue, err := strconv.Atoi(val); err == nil {
|
|
||||||
config.MemoryDumpFrequency = intValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if val, exists := os.LookupEnv("MAX_HISTORY_AGE"); exists {
|
if val, exists := os.LookupEnv("MAX_HISTORY_AGE"); exists {
|
||||||
if intValue, err := strconv.Atoi(val); err == nil {
|
if intValue, err := strconv.Atoi(val); err == nil {
|
||||||
config.MaxHistoryAge = intValue
|
config.MaxHistoryAge = intValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if val, exists := os.LookupEnv("LISTEN"); exists {
|
||||||
|
config.Listen = val
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, exists := os.LookupEnv("DATABASE_FILE_PATH"); exists {
|
||||||
|
config.DatabaseFilePath = val
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, exists := os.LookupEnv("IDENTITY_USERNAME"); exists {
|
||||||
|
config.IdentityUsername = val
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, exists := os.LookupEnv("IDENTITY_PASSWORD"); exists {
|
||||||
|
config.IdentityPassword = val
|
||||||
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetSystemHardDrives() ([]*HardDrive, error) {
|
func GetSystemHardDrives(db *gorm.DB, olderThan *time.Time, newerThan *time.Time) ([]*HardDrive, error) {
|
||||||
|
|
||||||
// Execute the lsblk command to get detailed block device information
|
// Execute the lsblk command to get detailed block device information
|
||||||
cmd := exec.Command("lsblk", "-d", "-o", "NAME,TRAN,SIZE,MODEL,SERIAL,TYPE")
|
cmd := exec.Command("lsblk", "-d", "-o", "NAME,TRAN,SIZE,MODEL,SERIAL,TYPE")
|
||||||
@@ -20,7 +23,7 @@ func GetSystemHardDrives() ([]*HardDrive, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var hardDrives []*HardDrive
|
var systemHardDrives []*HardDrive
|
||||||
|
|
||||||
// Scan the output line by line
|
// Scan the output line by line
|
||||||
scanner := bufio.NewScanner(&out)
|
scanner := bufio.NewScanner(&out)
|
||||||
@@ -39,17 +42,16 @@ func GetSystemHardDrives() ([]*HardDrive, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Filter out nvme drives (M.2)
|
// Filter out nvme drives (M.2)
|
||||||
if cols[1] != "nvme" {
|
if cols[1] != "nvme" && cols[5] != "Device" && cols[1] != "usb" {
|
||||||
hd := &HardDrive{
|
hd := &HardDrive{
|
||||||
Name: cols[0],
|
Name: cols[0],
|
||||||
Transport: cols[1],
|
Transport: cols[1],
|
||||||
Size: cols[2],
|
Size: cols[2],
|
||||||
Model: cols[3],
|
Model: cols[3],
|
||||||
Serial: cols[4],
|
Serial: cols[4],
|
||||||
Type: cols[5],
|
Type: cols[5],
|
||||||
Temperature: 0,
|
|
||||||
}
|
}
|
||||||
hardDrives = append(hardDrives, hd)
|
systemHardDrives = append(systemHardDrives, hd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,5 +60,33 @@ func GetSystemHardDrives() ([]*HardDrive, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return hardDrives, nil
|
var updatedHardDrives []*HardDrive
|
||||||
|
|
||||||
|
for _, sysHDD := range systemHardDrives {
|
||||||
|
var existingHD HardDrive
|
||||||
|
q := db.Where("serial = ? AND model = ? AND type = ?", sysHDD.Serial, sysHDD.Model, sysHDD.Type)
|
||||||
|
|
||||||
|
if newerThan != nil && olderThan != nil {
|
||||||
|
q = q.Preload("Temperatures", "time_stamp < ? AND time_stamp > ?", newerThan, olderThan)
|
||||||
|
}
|
||||||
|
|
||||||
|
result := q.First(&existingHD)
|
||||||
|
|
||||||
|
if result.Error == gorm.ErrRecordNotFound {
|
||||||
|
// Hard drive not found, create new
|
||||||
|
db.Create(&sysHDD)
|
||||||
|
updatedHardDrives = append(updatedHardDrives, sysHDD)
|
||||||
|
} else {
|
||||||
|
// Hard drive found, update existing
|
||||||
|
existingHD.Name = sysHDD.Name
|
||||||
|
existingHD.Transport = sysHDD.Transport
|
||||||
|
existingHD.Size = sysHDD.Size
|
||||||
|
existingHD.Model = sysHDD.Model
|
||||||
|
existingHD.Type = sysHDD.Type
|
||||||
|
db.Save(&existingHD)
|
||||||
|
updatedHardDrives = append(updatedHardDrives, &existingHD)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return updatedHardDrives, nil
|
||||||
}
|
}
|
||||||
|
|||||||
64
lib/hardware/models.go
Normal file
64
lib/hardware/models.go
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package hardware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/anatol/smart.go"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HardDrive struct {
|
||||||
|
ID uint `gorm:"primarykey"`
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||||
|
Name string
|
||||||
|
Transport string
|
||||||
|
Size string
|
||||||
|
Model string
|
||||||
|
Serial string
|
||||||
|
Type string
|
||||||
|
Temperatures []HardDriveTemperature `gorm:"foreignKey:HardDriveID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type HardDriveTemperature struct {
|
||||||
|
gorm.Model
|
||||||
|
HardDriveID uint
|
||||||
|
TimeStamp time.Time
|
||||||
|
Temperature int
|
||||||
|
}
|
||||||
|
|
||||||
|
// A snapshot in time of the current state of the harddrives
|
||||||
|
type HardwareSnapshot struct {
|
||||||
|
TimeStamp time.Time
|
||||||
|
HDD []*HardDrive
|
||||||
|
}
|
||||||
|
|
||||||
|
type Snapshots struct {
|
||||||
|
List []*HardwareSnapshot
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch the temperature of the device, optinally update the reference object
|
||||||
|
func (h *HardDrive) GetTemperature() int {
|
||||||
|
// Fetch the device by name
|
||||||
|
disk, err := smart.Open("/dev/" + h.Name)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to open device %s: %s\n", h.Name, err)
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
defer disk.Close()
|
||||||
|
|
||||||
|
// Fetch SMART data
|
||||||
|
smartInfo, err := disk.ReadGenericAttributes()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to get SMART data for %s: %s\n", h.Name, err)
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the temperature
|
||||||
|
temperature := int(smartInfo.Temperature)
|
||||||
|
|
||||||
|
// Return the found value
|
||||||
|
return temperature
|
||||||
|
}
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package hardware
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/anatol/smart.go"
|
|
||||||
)
|
|
||||||
|
|
||||||
type HardDrive struct {
|
|
||||||
Name string
|
|
||||||
Transport string
|
|
||||||
Size string
|
|
||||||
Model string
|
|
||||||
Serial string
|
|
||||||
Type string
|
|
||||||
Temperature int
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch the temperature of the device, optinally update the reference object
|
|
||||||
func (h *HardDrive) GetTemperature(updateTemp bool) int {
|
|
||||||
// Fetch the device by name
|
|
||||||
disk, err := smart.Open("/dev/" + h.Name)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Failed to open device %s: %s\n", h.Name, err)
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
defer disk.Close()
|
|
||||||
|
|
||||||
// Fetch SMART data
|
|
||||||
smartInfo, err := disk.ReadGenericAttributes()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Failed to get SMART data for %s: %s\n", h.Name, err)
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the temperature
|
|
||||||
temperature := int(smartInfo.Temperature)
|
|
||||||
|
|
||||||
// Optionally update the reference object's temperature
|
|
||||||
if updateTemp {
|
|
||||||
h.Temperature = temperature
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the found value
|
|
||||||
return temperature
|
|
||||||
}
|
|
||||||
@@ -1,128 +1,181 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
|
"gorm.io/driver/sqlite"
|
||||||
|
"gorm.io/gorm"
|
||||||
"tea.chunkbyte.com/kato/drive-health/lib/config"
|
"tea.chunkbyte.com/kato/drive-health/lib/config"
|
||||||
"tea.chunkbyte.com/kato/drive-health/lib/hardware"
|
"tea.chunkbyte.com/kato/drive-health/lib/hardware"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The path to where the snapshot database is located
|
var db *gorm.DB
|
||||||
const SNAPSHOT_LIST_PATH = "./snapshots.dat"
|
|
||||||
|
|
||||||
// A simple in-memory buffer for the history of snapshots
|
func InitDB() {
|
||||||
var snapShotBuffer []*HardwareSnapshot
|
var err error
|
||||||
|
dbPath := config.GetConfiguration().DatabaseFilePath
|
||||||
// A snapshot in time of the current state of the harddrives
|
if dbPath == "" {
|
||||||
type HardwareSnapshot struct {
|
dbPath = "./data.sqlite"
|
||||||
TimeStamp time.Time
|
|
||||||
HDD []*hardware.HardDrive
|
|
||||||
}
|
|
||||||
|
|
||||||
type Snapshots struct {
|
|
||||||
List []*HardwareSnapshot
|
|
||||||
}
|
|
||||||
|
|
||||||
// The function itterates through all hard disks and takes a snapshot of their state,
|
|
||||||
// returns a struct which contains metadata as well as the harddrives themselves.
|
|
||||||
func TakeHardwareSnapshot() (*HardwareSnapshot, error) {
|
|
||||||
drives, err := hardware.GetSystemHardDrives()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snapShot := &HardwareSnapshot{
|
db, err = gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
|
||||||
TimeStamp: time.Now(),
|
if err != nil {
|
||||||
HDD: []*hardware.HardDrive{},
|
panic("failed to connect database")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Migrate the schema
|
||||||
|
db.AutoMigrate(&hardware.HardDrive{}, &hardware.HardDriveTemperature{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDatabaseRef() *gorm.DB {
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|
||||||
|
func LogDriveTemps() error {
|
||||||
|
drives, err := hardware.GetSystemHardDrives(db, nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, hdd := range drives {
|
for _, hdd := range drives {
|
||||||
hdd.GetTemperature(true)
|
temp := hdd.GetTemperature()
|
||||||
snapShot.HDD = append(snapShot.HDD, hdd)
|
db.Create(&hardware.HardDriveTemperature{
|
||||||
}
|
HardDriveID: hdd.ID,
|
||||||
|
TimeStamp: time.Now(),
|
||||||
// Append to the in-memory listing
|
Temperature: temp,
|
||||||
snapShotBuffer = append(snapShotBuffer, snapShot)
|
})
|
||||||
|
|
||||||
// Return the snapshot just in case there is any need to modify it,
|
|
||||||
// any modification to it will also affect the current buffer from memory.
|
|
||||||
return snapShot, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// The function wil check if the `.dat` file is present, if it is then it will load it into memory
|
|
||||||
func UpdateHardwareSnapshotsFromFile() {
|
|
||||||
file, err := os.Open(SNAPSHOT_LIST_PATH)
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return // File does not exist, no snapshots to load
|
|
||||||
}
|
|
||||||
panic(err) // Handle error according to your error handling policy
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
decoder := gob.NewDecoder(file)
|
|
||||||
var snapshots Snapshots
|
|
||||||
if err := decoder.Decode(&snapshots); err != nil {
|
|
||||||
if err == io.EOF {
|
|
||||||
return // End of file reached
|
|
||||||
}
|
|
||||||
panic(err) // Handle error according to your error handling policy
|
|
||||||
}
|
|
||||||
|
|
||||||
snapShotBuffer = snapshots.List
|
|
||||||
|
|
||||||
fmt.Printf("Loaded %v snapshots from .dat", len(snapShotBuffer))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the list of snapshots that have been buffered in memory
|
|
||||||
func GetHardwareSnapshot() []*HardwareSnapshot {
|
|
||||||
return snapShotBuffer
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dump the current snapshot history from memory to file
|
|
||||||
func SaveSnapshotsToFile() error {
|
|
||||||
file, err := os.Create(SNAPSHOT_LIST_PATH)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
encoder := gob.NewEncoder(file)
|
|
||||||
snapshots := Snapshots{List: snapShotBuffer}
|
|
||||||
if err := encoder.Encode(snapshots); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunService() {
|
func RunLoggerService() {
|
||||||
|
fmt.Println("Initializing Temperature Logging Service...")
|
||||||
|
|
||||||
|
tickTime := time.Duration(config.GetConfiguration().DiskFetchFrequency) * time.Second
|
||||||
|
|
||||||
// Snapshot taking routine
|
// Snapshot taking routine
|
||||||
go func() {
|
go func() {
|
||||||
waitTime := time.Duration(config.GetConfiguration().DiskFetchFrequency) * time.Second
|
|
||||||
for {
|
for {
|
||||||
time.Sleep(waitTime)
|
time.Sleep(tickTime)
|
||||||
_, err := TakeHardwareSnapshot()
|
err := LogDriveTemps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Hardware Fetch Error: %s", err)
|
fmt.Printf("🛑 Temperature logging failed: %s\n", err)
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Periodic saving routine
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
waitTime := time.Duration(config.GetConfiguration().MemoryDumpFrequency) * time.Second
|
|
||||||
time.Sleep(waitTime)
|
|
||||||
err := SaveSnapshotsToFile()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Memory Dump Error: %s", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDiskGraphImage(hddID int, newerThan *time.Time, olderThan *time.Time) (*bytes.Buffer, error) {
|
||||||
|
var hdd hardware.HardDrive
|
||||||
|
// Fetch by a combination of fields
|
||||||
|
q := db.Where("id = ?", hddID)
|
||||||
|
|
||||||
|
if newerThan == nil && olderThan == nil {
|
||||||
|
q = q.Preload("Temperatures")
|
||||||
|
} else {
|
||||||
|
q = q.Preload("Temperatures", "time_stamp < ? AND time_stamp > ?", newerThan, olderThan)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query for the instance
|
||||||
|
result := q.First(&hdd)
|
||||||
|
if result.Error != nil {
|
||||||
|
return nil, result.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare slices for X (time) and Y (temperature) values
|
||||||
|
var xValues []time.Time
|
||||||
|
var yValues []float64
|
||||||
|
for _, temp := range hdd.Temperatures {
|
||||||
|
xValues = append(xValues, temp.TimeStamp)
|
||||||
|
yValues = append(yValues, float64(temp.Temperature))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate a buffer for the graph image
|
||||||
|
graphImageBuffer := bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
|
// TODO: Graph dark theme
|
||||||
|
|
||||||
|
// Generate the chart
|
||||||
|
graph := chart.Chart{
|
||||||
|
Title: fmt.Sprintf("%s:%s[%s]", hdd.Name, hdd.Serial, hdd.Size),
|
||||||
|
TitleStyle: chart.Style{
|
||||||
|
FontSize: 14,
|
||||||
|
},
|
||||||
|
|
||||||
|
// TODO: Implement customizable sizing
|
||||||
|
Width: 1280,
|
||||||
|
|
||||||
|
Background: chart.Style{
|
||||||
|
Padding: chart.Box{
|
||||||
|
Top: 20, Right: 20, Bottom: 20, Left: 20,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
XAxis: chart.XAxis{
|
||||||
|
Name: "Time",
|
||||||
|
ValueFormatter: func(v interface{}) string {
|
||||||
|
if ts, isValidTime := v.(float64); isValidTime {
|
||||||
|
t := time.Unix(int64(ts/1e9), 0)
|
||||||
|
|
||||||
|
return t.Format("Jan 2 2006, 15:04")
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
},
|
||||||
|
Style: chart.Style{},
|
||||||
|
GridMajorStyle: chart.Style{
|
||||||
|
StrokeColor: chart.ColorAlternateGray,
|
||||||
|
StrokeWidth: 0.5,
|
||||||
|
},
|
||||||
|
GridMinorStyle: chart.Style{
|
||||||
|
StrokeColor: chart.ColorAlternateGray.WithAlpha(64),
|
||||||
|
StrokeWidth: 0.25,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
YAxis: chart.YAxis{
|
||||||
|
Name: "Temperature (C)",
|
||||||
|
Style: chart.Style{},
|
||||||
|
GridMajorStyle: chart.Style{
|
||||||
|
StrokeColor: chart.ColorAlternateGray,
|
||||||
|
StrokeWidth: 0.5,
|
||||||
|
},
|
||||||
|
GridMinorStyle: chart.Style{
|
||||||
|
StrokeColor: chart.ColorAlternateGray.WithAlpha(64),
|
||||||
|
StrokeWidth: 0.25,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Series: []chart.Series{
|
||||||
|
chart.TimeSeries{
|
||||||
|
Name: "Temperature",
|
||||||
|
XValues: xValues,
|
||||||
|
YValues: yValues,
|
||||||
|
Style: chart.Style{
|
||||||
|
StrokeColor: chart.ColorCyan,
|
||||||
|
StrokeWidth: 2.0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a legend to the chart
|
||||||
|
graph.Elements = []chart.Renderable{
|
||||||
|
chart.Legend(&graph, chart.Style{
|
||||||
|
Padding: chart.Box{
|
||||||
|
Top: 5, Right: 5, Bottom: 5, Left: 5,
|
||||||
|
},
|
||||||
|
FontSize: 10,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render the chart into the byte buffer
|
||||||
|
err := graph.Render(chart.PNG, graphImageBuffer)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return graphImageBuffer, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"tea.chunkbyte.com/kato/drive-health/lib/hardware"
|
"tea.chunkbyte.com/kato/drive-health/lib/hardware"
|
||||||
@@ -10,19 +11,60 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func setupApi(r *gin.Engine) {
|
func setupApi(r *gin.Engine) {
|
||||||
api := r.Group("/v1/api")
|
api := r.Group("/api/v1")
|
||||||
|
|
||||||
|
api.GET("/disks/:diskid/chart", func(ctx *gin.Context) {
|
||||||
|
diskIDString := ctx.Param("diskid")
|
||||||
|
diskId, err := strconv.Atoi(diskIDString)
|
||||||
|
if err != nil {
|
||||||
|
ctx.AbortWithStatusJSON(400, gin.H{
|
||||||
|
"error": err.Error(),
|
||||||
|
"message": "Invalid Disk ID",
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
graphData, err := svc.GetDiskGraphImage(diskId, nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
ctx.AbortWithStatusJSON(500, gin.H{
|
||||||
|
"error": err.Error(),
|
||||||
|
"message": "Graph generation issue",
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the content type header
|
||||||
|
ctx.Writer.Header().Set("Content-Type", "image/png")
|
||||||
|
|
||||||
|
// Write the image data to the response
|
||||||
|
ctx.Writer.WriteHeader(http.StatusOK)
|
||||||
|
_, err = graphData.WriteTo(ctx.Writer)
|
||||||
|
if err != nil {
|
||||||
|
ctx.AbortWithStatusJSON(500, gin.H{
|
||||||
|
"error": err.Error(),
|
||||||
|
"message": "Write error",
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
api.GET("/disks", func(ctx *gin.Context) {
|
api.GET("/disks", func(ctx *gin.Context) {
|
||||||
|
|
||||||
|
olderThan := time.Now().Add(time.Minute * time.Duration(10) * -1)
|
||||||
|
newerThan := time.Now()
|
||||||
|
|
||||||
// Fetch the disk list
|
// Fetch the disk list
|
||||||
disks, err := hardware.GetSystemHardDrives()
|
disks, err := hardware.GetSystemHardDrives(svc.GetDatabaseRef(), &olderThan, &newerThan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(err)
|
ctx.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Request.URL.Query().Get("temp") != "" {
|
if ctx.Request.URL.Query().Get("temp") != "" {
|
||||||
for _, d := range disks {
|
for _, d := range disks {
|
||||||
temp := d.GetTemperature(true)
|
d.GetTemperature()
|
||||||
fmt.Printf("Disk Temp: %v", temp)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,10 +74,4 @@ func setupApi(r *gin.Engine) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
api.GET("/snapshots", func(ctx *gin.Context) {
|
|
||||||
snapshots := svc.GetHardwareSnapshot()
|
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, snapshots)
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
11
lib/web/auth_middleware.go
Normal file
11
lib/web/auth_middleware.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
func BasicAuthMiddleware(username, password string) gin.HandlerFunc {
|
||||||
|
authorized := gin.Accounts{
|
||||||
|
username: password,
|
||||||
|
}
|
||||||
|
|
||||||
|
return gin.BasicAuth(authorized)
|
||||||
|
}
|
||||||
@@ -2,9 +2,11 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"tea.chunkbyte.com/kato/drive-health/lib/hardware"
|
"tea.chunkbyte.com/kato/drive-health/lib/hardware"
|
||||||
|
"tea.chunkbyte.com/kato/drive-health/lib/svc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupFrontend(r *gin.Engine) {
|
func setupFrontend(r *gin.Engine) {
|
||||||
@@ -13,14 +15,16 @@ func setupFrontend(r *gin.Engine) {
|
|||||||
|
|
||||||
// Set up a route for the root URL
|
// Set up a route for the root URL
|
||||||
r.GET("/", func(c *gin.Context) {
|
r.GET("/", func(c *gin.Context) {
|
||||||
|
olderThan := time.Now().Add(time.Minute * time.Duration(10) * -1)
|
||||||
|
newerThan := time.Now()
|
||||||
|
|
||||||
hardDrives, err := hardware.GetSystemHardDrives()
|
hardDrives, err := hardware.GetSystemHardDrives(svc.GetDatabaseRef(), &olderThan, &newerThan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithStatus(500)
|
c.AbortWithStatus(500)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, hdd := range hardDrives {
|
for _, hdd := range hardDrives {
|
||||||
hdd.GetTemperature(true)
|
hdd.GetTemperature()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the HTML template
|
// Render the HTML template
|
||||||
|
|||||||
@@ -2,12 +2,16 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"tea.chunkbyte.com/kato/drive-health/lib/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetupRouter() *gin.Engine {
|
func SetupRouter() *gin.Engine {
|
||||||
// Initialize the Gin engine
|
// Initialize the Gin engine
|
||||||
|
cfg := config.GetConfiguration()
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
|
|
||||||
|
r.Use(BasicAuthMiddleware(cfg.IdentityUsername, cfg.IdentityPassword))
|
||||||
|
|
||||||
// Setup Health Pings
|
// Setup Health Pings
|
||||||
setupHealth(r)
|
setupHealth(r)
|
||||||
// Setup Api
|
// Setup Api
|
||||||
|
|||||||
10
main.go
10
main.go
@@ -9,18 +9,20 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"tea.chunkbyte.com/kato/drive-health/lib/config"
|
||||||
"tea.chunkbyte.com/kato/drive-health/lib/svc"
|
"tea.chunkbyte.com/kato/drive-health/lib/svc"
|
||||||
"tea.chunkbyte.com/kato/drive-health/lib/web"
|
"tea.chunkbyte.com/kato/drive-health/lib/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Load existing snapshots from file
|
// Init the database
|
||||||
svc.UpdateHardwareSnapshotsFromFile()
|
svc.InitDB()
|
||||||
|
cfg := config.GetConfiguration()
|
||||||
|
|
||||||
router := web.SetupRouter()
|
router := web.SetupRouter()
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: ":8080",
|
Addr: cfg.Listen,
|
||||||
Handler: router,
|
Handler: router,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +34,7 @@ func main() {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// Run the hardware service
|
// Run the hardware service
|
||||||
svc.RunService()
|
svc.RunLoggerService()
|
||||||
|
|
||||||
// Setting up signal capturing
|
// Setting up signal capturing
|
||||||
quit := make(chan os.Signal, 1)
|
quit := make(chan os.Signal, 1)
|
||||||
|
|||||||
134
static/main.js
134
static/main.js
@@ -1,134 +0,0 @@
|
|||||||
function stringToColor(str) {
|
|
||||||
let hash = 0;
|
|
||||||
for (let i = 0; i < str.length; i++) {
|
|
||||||
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
||||||
}
|
|
||||||
let color = '#';
|
|
||||||
for (let i = 0; i < 3; i++) {
|
|
||||||
const value = (hash >> (i * 8)) & 0xFF;
|
|
||||||
color += ('00' + value.toString(16)).substr(-2);
|
|
||||||
}
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
const diskTableBody = document.getElementById('disk-table-body');
|
|
||||||
const ctx = document.getElementById('temperatureChart').getContext('2d');
|
|
||||||
let temperatureChart = new Chart(ctx, {
|
|
||||||
type: 'line',
|
|
||||||
data: {
|
|
||||||
datasets: []
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
scales: {
|
|
||||||
x: {
|
|
||||||
type: 'time',
|
|
||||||
time: {
|
|
||||||
unit: 'second',
|
|
||||||
displayFormats: {
|
|
||||||
second: 'HH:mm:ss'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
title: {
|
|
||||||
display: true,
|
|
||||||
text: 'Time'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
y: {
|
|
||||||
beginAtZero: true,
|
|
||||||
title: {
|
|
||||||
display: true,
|
|
||||||
text: 'Temperature (°C)'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function fetchAndUpdateDisks() {
|
|
||||||
fetch('/v1/api/disks?temp=true')
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
updateDiskTable(data.disks);
|
|
||||||
})
|
|
||||||
.catch(error => console.error('Error fetching disk data:', error));
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateDiskTable(disks) {
|
|
||||||
let tableHTML = '';
|
|
||||||
disks.forEach(disk => {
|
|
||||||
tableHTML += `
|
|
||||||
<tr>
|
|
||||||
<td>${disk.Name}</td>
|
|
||||||
<td>${disk.Transport}</td>
|
|
||||||
<td>${disk.Size}</td>
|
|
||||||
<td>${disk.Model}</td>
|
|
||||||
<td>${disk.Serial}</td>
|
|
||||||
<td>${disk.Type}</td>
|
|
||||||
<td>${disk.Temperature}</td>
|
|
||||||
</tr>
|
|
||||||
`;
|
|
||||||
});
|
|
||||||
diskTableBody.innerHTML = tableHTML;
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchAndUpdateTemperatureChart() {
|
|
||||||
fetch('/v1/api/snapshots')
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(snapshots => {
|
|
||||||
updateTemperatureChart(snapshots);
|
|
||||||
})
|
|
||||||
.catch(error => console.error('Error fetching temperature data:', error));
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateTemperatureChart(snapshots) {
|
|
||||||
// Clear existing datasets
|
|
||||||
temperatureChart.data.datasets = [];
|
|
||||||
|
|
||||||
snapshots.forEach(snapshot => {
|
|
||||||
const time = new Date(snapshot.TimeStamp);
|
|
||||||
snapshot.HDD.forEach(disk => {
|
|
||||||
let dataset = temperatureChart.data.datasets.find(d => d.label === disk.Name);
|
|
||||||
if (!dataset) {
|
|
||||||
dataset = {
|
|
||||||
label: disk.Name,
|
|
||||||
data: [],
|
|
||||||
fill: false,
|
|
||||||
borderColor: stringToColor(disk.Name),
|
|
||||||
borderWidth: 1
|
|
||||||
};
|
|
||||||
temperatureChart.data.datasets.push(dataset);
|
|
||||||
}
|
|
||||||
|
|
||||||
dataset.data.push({
|
|
||||||
x: time,
|
|
||||||
y: disk.Temperature
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
temperatureChart.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Chart.js zoom and pan configuration
|
|
||||||
temperatureChart.options.plugins.zoom = {
|
|
||||||
zoom: {
|
|
||||||
wheel: {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
pinch: {
|
|
||||||
enabled: true
|
|
||||||
},
|
|
||||||
mode: 'x',
|
|
||||||
},
|
|
||||||
pan: {
|
|
||||||
enabled: true,
|
|
||||||
mode: 'x',
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchAndUpdateDisks();
|
|
||||||
fetchAndUpdateTemperatureChart();
|
|
||||||
setInterval(fetchAndUpdateDisks, 5000);
|
|
||||||
setInterval(fetchAndUpdateTemperatureChart, 5000);
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,45 +1,71 @@
|
|||||||
body {
|
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&family=Roboto:wght@100;300;400&display=swap');
|
||||||
font-family: Arial, sans-serif;
|
|
||||||
background-color: #333;
|
:root {
|
||||||
color: #fff;
|
--bg0: #202327;
|
||||||
margin: 0;
|
--bg1: #282d33;
|
||||||
|
--bg2: #31373f;
|
||||||
|
|
||||||
|
--fg0: #bbc0ca;
|
||||||
|
--fg0: #bbc0ca;
|
||||||
|
|
||||||
|
--acc: #bbc0ca;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root {
|
||||||
|
color: var(--fg0);
|
||||||
|
font-family: "Noto Sans Mono", "Roboto", sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vw;
|
||||||
|
|
||||||
|
overflow: auto;
|
||||||
|
|
||||||
|
background-color: var(--bg0);
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
width: 80%;
|
margin: 1rem auto;
|
||||||
margin: auto;
|
max-width: 768px;
|
||||||
|
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid var(--fg1);
|
||||||
|
|
||||||
|
background-color: var(--bg1);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
.container-titlebar {
|
||||||
text-align: center;
|
width: 100%;
|
||||||
padding: 20px 0;
|
|
||||||
|
background-color: var(--bg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.container .pad {
|
||||||
|
padding: .5rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container-titlebar h4 {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Table */
|
||||||
|
|
||||||
table {
|
table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-top: 20px;
|
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
|
|
||||||
table, th, td {
|
table thead tr {
|
||||||
border: 1px solid #ddd;
|
border-bottom: 1px solid var(--bg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
th, td {
|
.graph-image {
|
||||||
text-align: left;
|
max-width: 100%;
|
||||||
padding: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
th {
|
|
||||||
background-color: #555;
|
|
||||||
}
|
|
||||||
|
|
||||||
tr:nth-child(even) {
|
|
||||||
background-color: #666;
|
|
||||||
}
|
|
||||||
|
|
||||||
tr:hover {
|
|
||||||
background-color: #555;
|
|
||||||
}
|
}
|
||||||
@@ -8,28 +8,79 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>Drive Health Dashboard</h1>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<!-- ... table headers ... -->
|
|
||||||
</thead>
|
|
||||||
<tbody id="disk-table-body">
|
|
||||||
<!-- Data will be populated here by JavaScript -->
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<hr>
|
<div class="container-titlebar">
|
||||||
|
<div class="pad">
|
||||||
<div class="chart-container" style="position: relative; height:40vh; width:80vw; overflow-x: scroll;">
|
<h4>Available Disks</h4>
|
||||||
<canvas id="temperatureChart"></canvas>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="container-body">
|
||||||
|
<div class="pad">
|
||||||
|
{{ if len .drives }}
|
||||||
|
<table id="disks-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td>ID</td>
|
||||||
|
<td>Name</td>
|
||||||
|
<td>Model</td>
|
||||||
|
<td>Serial</td>
|
||||||
|
<td>Temperature</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="disk-table-body">
|
||||||
|
{{ range .drives }}
|
||||||
|
{{ $temp := .GetTemperature }}
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>#{{ .ID }}</td>
|
||||||
|
<td> {{ .Name }}</td>
|
||||||
|
<td> {{ .Model }}</td>
|
||||||
|
<td> {{ .Serial }}</td>
|
||||||
|
|
||||||
|
{{ if gt $temp 50 }} <!-- Temperature greater than 50°C -->
|
||||||
|
<td style="color: red;">{{ $temp }}°C</td>
|
||||||
|
{{ else if gt $temp 30 }} <!-- Temperature between 31°C and 50°C -->
|
||||||
|
<td style="color: orange;">{{ $temp }}°C</td>
|
||||||
|
{{ else }} <!-- Temperature 30°C or below -->
|
||||||
|
<td style="color: lime;">{{ $temp }}°C</td>
|
||||||
|
{{ end }}
|
||||||
|
</tr>
|
||||||
|
{{ end }}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{{ else }}
|
||||||
|
<p>No hard drives found.</p>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js@latest"></script>
|
<div class="container">
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns@latest"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom@latest"></script>
|
<div class="container-titlebar">
|
||||||
|
<div class="pad">
|
||||||
|
<h4>Temperature Graph</h4>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="container-body">
|
||||||
|
<div class="pad">
|
||||||
|
{{ if len .drives }}
|
||||||
|
{{ range .drives }}
|
||||||
|
<div id="disk-temp-{{ .ID }}">
|
||||||
|
<a href="/api/v1/disks/{{.ID}}/chart" target="_blank">
|
||||||
|
<img class="graph-image" src="/api/v1/disks/{{.ID}}/chart" alt="{{ .Model }} Image">
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
{{ else }}
|
||||||
|
<p>No hard drives found.</p>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="/static/main.js"></script>
|
<script src="/static/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user