Compare commits

...

13 Commits

Author SHA1 Message Date
Daniel Legt cf313cdaf3
Merge pull request #4 from manjarisri/feature
Modified Dockerfile and reduced image size
2024-01-24 11:07:02 +02:00
Manjari Srivastav 28b319c3c5
Add files via upload
optimised Dockerfile
2024-01-24 12:29:59 +05:30
Manjari Srivastav 30aa7f7bde
Delete Dockerfile 2024-01-24 12:28:22 +05:30
Manjari Srivastav 4aaa187156
Delete drive-health directory 2024-01-24 12:27:49 +05:30
Manjari Srivastav 3ba65b93c0
Add files via upload 2024-01-24 12:22:35 +05:30
Daniel Legt de08a7f970 Fixed major bug
* Resolved the hwmon not found problem
2024-01-22 12:39:31 +02:00
Daniel Legt d6588742d3 Updated Information
* Updated `build.sh`
* Updated `README.md`
2024-01-22 12:24:27 +02:00
Daniel Legt 44d4237bec Fixed Static folder push 2024-01-22 02:34:27 +02:00
Daniel Legt f2c84fb6b2 Fixed Dockerfile 2024-01-22 02:23:43 +02:00
Daniel Legt 4f50819f92 Production docker-compose.yml updates 2024-01-22 02:12:18 +02:00
Daniel Legt 6117157598 DockerFile link to repository
* Fixed issue
2024-01-22 02:01:39 +02:00
Daniel Legt 79e44bd88a + Production docker-compose.yml 2024-01-22 01:59:38 +02:00
Daniel Legt c556e3827b Updated deploy 2024-01-22 01:58:43 +02:00
7 changed files with 155 additions and 33 deletions

8
.dockerignore Normal file
View File

@ -0,0 +1,8 @@
/**
!main.go
!/lib
!/templates
!/static
!/go.mod
!/go.sum

View File

@ -1,7 +1,9 @@
# Build Stage
FROM debian:bullseye
# === Build Stage ===
FROM debian:bullseye-slim AS builder
ENV IS_DOCKER TRUE
LABEL org.opencontainers.image.source https://github.com/JustKato/drive-health
# Install build dependencies and runtime dependencies
RUN apt-get update && apt-get install -y \
gcc \
@ -22,10 +24,9 @@ ENV PATH /usr/local/go/bin:$PATH
ENV GOPATH=/go
ENV PATH=$GOPATH/bin:$PATH
ENV GO111MODULE=on
ENV DIST_DIR=/app
# Create the directory and set it as the working directory
WORKDIR $DIST_DIR
WORKDIR /app
# Copy the Go files and download dependencies
COPY go.mod go.sum ./
@ -42,6 +43,18 @@ RUN apt-get purge -y gcc musl-dev libsqlite3-dev wget \
&& apt-get autoremove -y \
&& apt-get clean
# === Final Stage ===
FROM debian:bullseye-slim AS final
# Set the environment variable
ENV IS_DOCKER TRUE
# Create the directory and set it as the working directory
WORKDIR /app
# Copy only the necessary files from the builder stage
COPY --from=builder /app/drive-health .
# Expose the necessary port
EXPOSE 8080

View File

@ -1,29 +1,69 @@
## 📖About
## 📖 About
Drive Health is a program written in golang to help with tracking and monitoring of your hardware's temperature.
This tool has been with the purpose of installing it in different servers I own with different configurations to help keep track of the temperature of different hard-disks, ssds, nvme drives, etc... The testing has been very limited to only 4 different computers and not on laptops so expect some mishaps.
This tool had been conceived with the purpose of installing it on different servers I own with different configurations to help keep track of the temperature of hard-disks, ssds, nvme drives, etc...
### Features
- Disk Listing
- Temperature Graphing
- Disk activity logging
- [API](./lib/web/api.go)
![UI Example](./media/design_v1.webp)
## ❗Disclaimer
## ❗ Disclaimer
I'm not exactly a linux hardware wizard, so I honestly have no clue about a lot of things and I myself can tell there's a lot to improve upon and that there's a lot of other things missing that are a little bit more obscure, I personally don't currently own any m.2 sata drives to test the code on, or many of the other drive types, I have only tested on HDD, SSD and NVMe drives, any issues opened would help me so much!
## ❗Requirements
## ❗ Requirements
1. A linux machine, this will NOT work on macOS or on Windows, it's meant to be ran on servers as a service with which administrators can privately connect to for temperature logging.
2. Please make sure you have the [**drivetemp kernel drive**](https://docs.kernel.org/hwmon/drivetemp.html) you can check this by running `sudo modprobe drivetemp`.
The program depends on this to be able to log the temperature of your devices.
## 📖How to use
## 📖 How to use
1. Follow the `Deployment` section instrcutions to launch the program
The program is straight forward to use really, edit the [.env](./.env) file and make the changes you would like applied.
2. Once the program has launched, access it in your browser
### Docker ( Recommended/Hassle free )
3. Enter the administrative username and password for the simple HTTP Auth
4. You now have access to the application, you can monitor your disk's temperature over a period of time.
## 🐦 Deployment
To deploy the application you have multiple choices, the preffered method should be one which runs the binary directly and not containerization, the `docker` image is taking up a wopping `1Gb+` because I have to include sqlite3-dev and musl-dev dependencies, which sucks, so I whole heartedly recommend just installing this on your system as a binary either with `SystemD` or whichever service manager you are using.
Download binaries from [the releases page](https://github.com/JustKato/drive-health/releases)
### 🐋 Docker
In the project there's a `docker-compose.prod.yml` which you can deploy on your server, you will notice that there's also a "dev" version, this version simply has a `build` instead of `image` property, so feel free to use either.
Please do take notice that I have just fed the `environment file` directly to the service via docker-compose, and I recommend you do the same but please feel free to pass in `environment` variables straight to the process as well.
[Docker Compose File](./docker-compose.prod.yml)
```yaml
version: "3.8"
services:
drive-health:
# Latest image pull, mention the specific version here please.
image: ghcr.io/justkato/drive-health:latest
# Restart in case of crashing
restart: unless-stopped
# Load environment variables from .env file
env_file:
- .env
# Mount the volume to the local drive
volumes:
- ./data:/data
# Setup application ports
ports:
- 5003:8080
```
### 💾 SystemD
When running with SystemD or any other service manager, please make sure you have a `.env` inside the `WorkingDirectory` of your runner, in the below example I will simply put my env in `/home/daniel/services/drive-health/.env`
### SystemD
```ini
[Unit]
Description=Drive Health Service
@ -40,18 +80,19 @@ Restart=on-failure
WantedBy=multi-user.target
```
## ❔FAQ
## ❔ FAQ
### How does it work?
Currently the program does not depend on any hardware library as I couldn't find anything that would not require root access while giving me the possibility to interrogate the temperature of the drives, I chose not to depend on `lsblk` either, so how does the program work? Well it looks in `/sys/block` and simply
Currently the program does not depend on any go library for hardware detection as I couldn't find anything that would not require root access while giving me the possibility to interrogate the temperature of the drives.
I chose not to depend on `lsblk` either, so how does the program work?
The program currently looks in `/sys/block` and then tries to make sense of the devices, I have had limited testing with my hardware specs, any issues being open in regards to different kinds of hardware would be highly appreciated
### Why not just run as root?
I really, really, **really** want to avoid asking people to run **ANY** program I write as root and even try and prevent that from happening since that's how things can go bad, especially because I am runnig actions over hardware items. I think you can see how easy it is for a mistake or a **malicious attack** to easily deal damage
I really, REALLY, **REALLY** want to avoid asking people to run **ANY** program I write as root and even try and prevent that from happening since that's how things can go bad, especially because I am running actions over hardware devices.
## Support & Contribution
For support, bug reports, or feature requests, please open an issue on the [GitHub repository](https://github.com/JustKato/drive-health/issues). Contributions are welcome! Fork the repository, make your changes, and submit a pull request.
## License
This project is licensed under the [Apache License 2.0](./LICENSE).

View File

@ -1,19 +1,50 @@
#!/bin/sh
#!/usr/bin/env bash
set -o pipefail
set -u
# Function to display messages in color
echo_color() {
color=$1
text=$2
case $color in
"green") echo -e "\033[0;32m$text\033[0m" ;;
"yellow") echo -e "\033[0;33m$text\033[0m" ;;
"red") echo -e "\033[0;31m$text\033[0m" ;;
*) echo "$text" ;;
esac
}
# Getting GIT_VERSION from the most recent tag or commit hash
GIT_VERSION=$(git describe --tags --always)
if [ -z "$GIT_VERSION" ]; then
echo_color red "Error: Unable to determine GIT_VERSION."
exit 1
fi
APP_NAME="drive-health"
DIST_DIR="${DIST_DIR:-dist}"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# make sure we are in the source dir
cd $SCRIPT_DIR;
# Create the dist directory if it doesn't exist
mkdir -p $DIST_DIR
# Build the application
echo "Building the application..."
echo_color yellow "[🦝] Building the application..."
GOOS=linux CGO_ENABLED=1 GOARCH=amd64 go build -o $DIST_DIR/$APP_NAME
# echo "Copying additional resources..."
# Copying additional resources...
cp -r static templates $DIST_DIR/
echo "Compilation and packaging completed."
echo_color yellow "[🦝] Compilation and packaging completed, archiving..."
cd $DIST_DIR/
zip "drive-health_$GIT_VERSION.zip" -r .
# TODO: Add reliable method of cleaning up the compiled files optionally
cd $SCRIPT_DIR;

View File

@ -29,7 +29,8 @@ echo_color green "All tests passed successfully."
echo_color green "Starting the Docker build process with version $GIT_VERSION..."
IMAGE_NAME="ghcr.io/JustKato/drive-health:$GIT_VERSION"
LATEST_IMAGE_NAME="ghcr.io/justkato/drive-health:latest"
IMAGE_NAME="ghcr.io/justkato/drive-health:$GIT_VERSION"
echo_color yellow "Image to be built: $IMAGE_NAME"
# Confirmation to build
@ -38,6 +39,10 @@ if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
# Building the Docker image
echo "Building Docker image: $IMAGE_NAME"
docker build --no-cache -t $IMAGE_NAME .
# Also tag this build as 'latest'
echo "Tagging image as latest: $LATEST_IMAGE_NAME"
docker tag $IMAGE_NAME $LATEST_IMAGE_NAME
else
echo_color red "Build cancelled."
exit 1
@ -49,6 +54,10 @@ if [[ "$push_response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
# Pushing the image
echo "Pushing image: $IMAGE_NAME"
docker push $IMAGE_NAME
# Pushing the 'latest' image
echo "Pushing latest image: $LATEST_IMAGE_NAME"
docker push $LATEST_IMAGE_NAME
else
echo_color red "Push cancelled."
fi

17
docker-compose.prod.yml Normal file
View File

@ -0,0 +1,17 @@
version: "3.8"
services:
drive-health:
# Latest image pull, mention the specific version here please.
image: ghcr.io/justkato/drive-health:latest
# Restart in case of crashing
restart: unless-stopped
# Load environment variables from .env file
env_file:
- .env
# Mount the volume to the local drive
volumes:
- ./data:/data
# Setup application ports
ports:
- 5003:8080

View File

@ -44,16 +44,19 @@ type Snapshots struct {
}
func (h *HardDrive) GetTemperature() int {
possiblePaths := []string{
"/sys/block/" + h.Name + "/device/hwmon/",
"/sys/block/" + h.Name + "/device/",
"/sys/block/" + h.Name + "/device/generic/device/",
}
for _, path := range possiblePaths {
// Try HDD/SSD path
temp, found := h.getTemperatureFromPath("/sys/block/" + h.Name + "/device/hwmon/")
temp, found := h.getTemperatureFromPath(path)
if found {
return temp
}
// Try NVMe path
temp, found = h.getTemperatureFromPath("/sys/block/" + h.Name + "/device/")
if found {
return temp
}
fmt.Printf("[🛑] Failed to get temperature for %s\n", h.Name)