diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..468263e --- /dev/null +++ b/.drone.yml @@ -0,0 +1,26 @@ +--- +kind: pipeline +type: docker +name: build and publish + +trigger: + event: + include: + - push + +steps: + - name: docker build and publish + image: plugins/docker + environment: + REVISION: ${DRONE_COMMIT_SHA} + CREATED: ${DRONE_BUILD_CREATED} + SOURCE_URL: ${DRONE_GIT_HTTP_URL} + settings: + purge: true + username: + from_secret: dockerhub_user + password: + from_secret: dockerhub_key + repo: varakh/hetzner-storagebox-exporter + tags: + - latest diff --git a/.env b/.env deleted file mode 100644 index b0a86e7..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -TAG=1.0 diff --git a/Dockerfile b/Dockerfile index 4b53c0e..48a4b52 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,14 @@ -FROM alpine +FROM alpine:3 +LABEL maintainer="Varakh " \ + description="hetzner-storagebox-exporter" \ + org.opencontainers.image.authors="Varakh" \ + org.opencontainers.image.revision="${REVISION}" \ + org.opencontainers.image.vendor="Varakh" \ + org.opencontainers.image.title="hetzner-storagebox-exporter" \ + org.opencontainers.image.description="hetzner-storagebox-exporter" \ + org.opencontainers.image.base.name="alpine:3" \ + org.opencontainers.artifact.created=${CREATED} \ + org.opencontainers.image.source=${SOURCE_URL} RUN apk add --no-cache nmap-ncat openssl coreutils openssh diff --git a/readme.md b/README.md similarity index 55% rename from readme.md rename to README.md index 4435860..3fbe738 100644 --- a/readme.md +++ b/README.md @@ -1,5 +1,11 @@ # Hetzner Storage Exporter +**Initially forked from https://github.com/gmasil/hetzner-storagebox-exporter**. + +- Applied some improvements +- Adapted documentation +- Added pipeline for publish to DockerHub + This is a simple prometheus exporter to provide storage space metrics of a Hetzner Storagebox. # Example @@ -9,15 +15,15 @@ A SSH private key to login via SSH has to be provided and SSH has to be enabled Here you can see an example output of the hetzner-storage-exporter: -``` -# HELP hetzner_storage_available Available storage +```shell +# HELP hetzner_storage_available Available storage in kilobytes # TYPE hetzner_storage_available gauge -# HELP hetzner_storage_used Used storage -# TYPE hetzner_storage_used gauge -# HELP hetzner_storage_total Total storage -# TYPE hetzner_storage_total gauge hetzner_storage_available{host="u123456.your-storagebox.de"} 1062381134 +# HELP hetzner_storage_used Used storage in kilobytes +# TYPE hetzner_storage_used gauge hetzner_storage_used{host="u123456.your-storagebox.de"} 11360690 +# HELP hetzner_storage_total Total storage in kilobytes +# TYPE hetzner_storage_total gauge hetzner_storage_total{host="u123456.your-storagebox.de"} 1073741824 ``` @@ -26,44 +32,44 @@ hetzner_storage_total{host="u123456.your-storagebox.de"} 1073741824 Build simply with docker: ```bash -docker build . +docker build --no-cache -t "varakh/hetzner-storagebox-exporter:latest" . ``` -Build with Compose: - -```bash -docker-compose build -``` - -**Note:** this will build an image called `registry.gmasil.de/docker/hetzner-storage-exporter`, this is my own docker registry. +**Note:** This will build an image called `varakh/hetzner-storagebox-exporter:latest`. # Usage -You can use the image I uploaded to my docker registry, if you want to use your own build just replace the image name accordingly. - The exporter will **listen** on **port 80** and exposes it by default. You have to provide your username for your storage box via environment variable `USERNAME` and a SSH private key to login. Additionally you need a `known_hosts` file to accept the SSH connection. -Usage with docker: +Usage with `docker`: ```bash -docker run -p 80:80 -e "USERNAME=u123456" -v "$(cd ~ && pwd)/.ssh:/root/.ssh" registry.gmasil.de/docker/hetzner-storage-exporter:1.0 +docker run --rm -p 80:80 -e "USERNAME=u123456" \ + -v "/home/myuser/.ssh/id_rsa:/root/.ssh/id_rsa" \ + -v "/home/myuser/.ssh/known_hosts:/root/.ssh/known_hosts" \ + varakh/hetzner-storagebox-exporter:latest ``` -Example docker-compose file: +Example `docker-compose` file: -```bash +```yml version: '3' services: hetzner-storage-exporter: - image: registry.gmasil.de/docker/hetzner-storage-exporter:1.0 + container_name: hetzner-storage-exporter + restart: unless-stopped + image: varakh/hetzner-storagebox-exporter:latest + port: + - "9494:80" environment: - "USERNAME=u123456" volumes: - - "/home/peter/.ssh:/root/.ssh" + - "/home/myuser/.ssh/id_rsa:/root/.ssh/id_rsa" + - "/home/myuser/.ssh/known_hosts:/root/.ssh/known_hosts" ``` ## Prometheus @@ -83,17 +89,3 @@ scrape_configs: ``` **Note:** As the exporter will provide the metrics on all URIs, you can leave all defaults like scraping on the `/metrics` URI. - -## License - -[GNU GPL v3 License](LICENSE.md) - -Hetzner Storage Exporter is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Hetzner Storage Exporter is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. diff --git a/check-storage.sh b/check-storage.sh old mode 100644 new mode 100755 index f7609b7..977acf5 --- a/check-storage.sh +++ b/check-storage.sh @@ -5,17 +5,16 @@ set -eu PORT=${PORT:-23} HOST=${HOST:-$USERNAME.your-storagebox.de} -echo "# HELP hetzner_storage_available Available storage" -echo "# TYPE hetzner_storage_available gauge" - -echo "# HELP hetzner_storage_used Used storage" -echo "# TYPE hetzner_storage_used gauge" - -echo "# HELP hetzner_storage_total Total storage" -echo "# TYPE hetzner_storage_total gauge" - ssh -p${PORT} ${USERNAME}@${HOST} df -k | tail -n +2 | while read FS TOTAL USED AVAIL PERCENT MOUNT; do + echo "# HELP hetzner_storage_available Available storage in kilobytes" + echo "# TYPE hetzner_storage_available gauge" echo "hetzner_storage_available{host=\"${HOST}\"} $AVAIL" + + echo "# HELP hetzner_storage_used Used storage in kilobytes" + echo "# TYPE hetzner_storage_used gauge" echo "hetzner_storage_used{host=\"${HOST}\"} $USED" + + echo "# HELP hetzner_storage_total Total storage in kilobytes" + echo "# TYPE hetzner_storage_total gauge" echo "hetzner_storage_total{host=\"${HOST}\"} $TOTAL" done diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 9a79f23..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: "3.0" - -services: - hetzner-storage-exporter: - build: . - image: registry.gmasil.de/docker/hetzner-storage-exporter:${TAG} diff --git a/header.sh b/header.sh old mode 100644 new mode 100755