master
May B. 2022-11-02 11:01:06 +01:00
parent b7e19d61b0
commit 5cb42cf121
6 changed files with 111 additions and 8 deletions

View File

@ -53,12 +53,28 @@ services:
build:
context: nextcloud
gotify:
image: local/gotify
build:
context: gotify
# gotify:
# image: local/gotify
# build:
# context: gotify
dst:
image: local/dst
build:
context: dst
context: dst
metry:
image: local/metry
build:
context: metry
# scalliony-allium:
# image: local/scalliony-allium
# build:
# context: scalliony
# dockerfile: Dockerfile.allium
# scalliony-chives:
# image: local/scalliony-chives
# build:
# context: scalliony
# dockerfile: Dockerfile.chives

2
dst

@ -1 +1 @@
Subproject commit a9721d695cbf6e9b6884c1ae77e3c2a3bb7b022e
Subproject commit 516d05132eeafbe6dca5ec95fd78f4cfe95b2ccc

View File

@ -1,4 +1,4 @@
FROM mariadb
FROM mariadb:10.7
COPY docker-healthcheck /usr/local/bin/

18
metry/Dockerfile Normal file
View File

@ -0,0 +1,18 @@
FROM debian:buster-slim
LABEL maintainer="me@wadza.fr"
ENV INSTALL_KEY 379CE192D401AB61
ENV DEB_DISTRO buster
RUN apt-get update && apt-get install -y curl jq
RUN apt-get update && apt-get install -y gnupg1 apt-transport-https dirmngr && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $INSTALL_KEY && \
echo "deb https://ookla.bintray.com/debian ${DEB_DISTRO} main" | tee /etc/apt/sources.list.d/speedtest.list && \
apt-get update && \
apt-get install speedtest
COPY entrypoint.sh /usr/local/bin
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

69
metry/entrypoint.sh Executable file
View File

@ -0,0 +1,69 @@
#!/usr/bin/env bash
# InfluxDB variables
influxdb_proto=${INFLUXDB_PROTO:-http}
influxdb_host=${INFLUXDB_HOST:-influxdb}
influxdb_port=${INFLUXDB_PORT:-8086}
influxdb_db=${INFLUXDB_DB:-metrics}
influxdb_user=${INFLUXDB_USER:-user}
influxdb_pwd=${INFLUXDB_PWD}
interval=${WAIT_INTERVAL}
influxdb_url="${influxdb_proto}://${influxdb_host}:${influxdb_port}"
nextcloud_host=${NEXTCLOUD_HOST}
nextcloud_user=${NEXTCLOUD_USER:-user}
nextcloud_pwd=${NEXTCLOUD_PWD}
nextcloud_st_url="https://${nextcloud_host}/ocs/v2.php/apps/serverinfo/api/v1/info?format=json"
nextcloud_dk_url="https://${nextcloud_host}/ocs/v2.php/apps/serverinfo/api/v1/diskdata?format=json"
while true
do
# Run speedtest & store result
speed_result=$(speedtest -f json --accept-license --accept-gdpr)
# Extract data from speedtest result
result_id=$(echo "${speed_result}" | jq -r '.result.id')
ping_latency=$(echo "${speed_result}" | jq -r '.ping.latency')
download_bandwidth=$(echo "${speed_result}" | jq -r '.download.bandwidth')
upload_bandwidth=$(echo "${speed_result}" | jq -r '.upload.bandwidth')
# Write speed to InfluxDB
curl \
-H "Authorization: Token ${influxdb_user}:${influxdb_psd}" \
-d "speedtest,result_id=${result_id} ping_latency=${ping_latency},download_bandwidth=${download_bandwidth},upload_bandwidth=${upload_bandwidth}" \
"${influxdb_url}/write?db=${influxdb_db}"
# Run nextcloud status
next_result=$(curl -u ${nextcloud_user}:${nextcloud_pwd} "${nextcloud_st_url}" | sed -e 's/\\/\//g')
db_size=$(echo "${next_result}" | jq -r '.ocs.data.server.database.size')
active_users=$(echo "${next_result}" | jq -r '.ocs.data.activeUsers.last5minutes')
files=$(echo "${next_result}" | jq -r '.ocs.data.nextcloud.storage.num_files')
freespace=$(echo "${next_result}" | jq -r '.ocs.data.nextcloud.system.freespace')
# Write next to InfluxDB
curl \
-H "Authorization: Token ${influxdb_user}:${influxdb_psd}" \
-d "nextcloud db_size=${db_size},active_users=${active_users},files=${files},freespace=${freespace}" \
"${influxdb_url}/write?db=${influxdb_db}"
# Run disks usage
disk_result=$(curl -u ${nextcloud_user}:${nextcloud_pwd} -H "OCS-APIREQUEST: true" "${nextcloud_dk_url}")
disk_i=0
disk_vals=""
for disk in $(echo "${disk_result}" | jq -r '.ocs.data[][]')
do
disk_vals+=$((($disk_i % 2)) && echo "free" || echo "used")
disk_vals+="$(($disk_i / 2))=${disk},"
disk_i=$(($disk_i + 1))
done
# Write disks to InfluxDB
curl \
-H "Authorization: Token ${influxdb_user}:${influxdb_psd}" \
-d "disks ${disk_vals::-1}" \
"${influxdb_url}/write?db=${influxdb_db}"
sleep "${interval}"
done

View File

@ -1,4 +1,4 @@
FROM postgres:alpine
FROM postgres:12-alpine
RUN apk add --no-cache bash