Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #22 from hacker-h/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
Pedro César de Azevedo authored Jul 15, 2021
2 parents 43d6bf6 + 84426c4 commit bdb8ef5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
env_file:
- ./env/db.env
web:
# build: ./speedweb
# build: ./speedweb
image: pedrocesarti/internet-speedtest-docker:speedweb
container_name: speedweb
ports:
Expand All @@ -23,7 +23,7 @@ services:
- GF_SERVER_ROOT_URL=http://localhost
- GF_SECURITY_ADMIN_PASSWORD=teste
testing:
# build: ./speedtest
# build: ./speedtest
image: pedrocesarti/internet-speedtest-docker:speedtest
container_name: speedtest
links:
Expand Down
12 changes: 6 additions & 6 deletions speedtest/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM python:2-alpine
FROM python:3-alpine
MAINTAINER Pedro César de Azevedo <[email protected]>

RUN mkdir -p /app/speedtest/
RUN apk add --update curl
RUN curl https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py -o /app/speedtest/speedtest-cli
RUN chmod +x /app/speedtest/speedtest-cli
RUN mkdir -p /app/speedtest/ &&\
apk add --no-cache --update curl &&\
curl https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py -o /app/speedtest/speedtest-cli &&\
chmod +x /app/speedtest/speedtest-cli

ADD scripts/ /app/speedtest/
COPY scripts/ /app/speedtest/

CMD sh -c /app/speedtest/init_test_connection.sh
18 changes: 9 additions & 9 deletions speedtest/scripts/init_test_connection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FILE="/app/speedtest/test_connection.log"

while true
do
TIMESTAMP=$(date '+%s')
TIMESTAMP=$(date '+%s')

COMMAND=/app/speedtest/speedtest-cli
if [ -n "${TEST_SERVER}" ]; then
Expand All @@ -12,13 +12,13 @@ do

eval "${COMMAND} > ${FILE}"

DOWNLOAD=$(cat $FILE | grep "Download:" | awk -F " " '{print $2}')
UPLOAD=$(cat $FILE | grep "Upload:" | awk -F " " '{print $2}')
PING=$(ping -qc1 google.com 2>&1 | awk -F'/' 'END {print (/^round-trip/? $4:"-100")}')
echo "Download: $DOWNLOAD Upload: $UPLOAD Ping: $PING $TIMESTAMP"
curl -i -XPOST 'http://db:8086/write?db=speedtest' --data-binary "download,host=local value=$DOWNLOAD"
curl -i -XPOST 'http://db:8086/write?db=speedtest' --data-binary "upload,host=local value=$UPLOAD"
curl -i -XPOST 'http://db:8086/write?db=speedtest' --data-binary "ping,host=local value=$PING"
sleep $TEST_INTERVAL
DOWNLOAD=$(cat $FILE | grep "Download:" | awk -F " " '{print $2}')
UPLOAD=$(cat $FILE | grep "Upload:" | awk -F " " '{print $2}')
PING=$(ping -qc1 google.com 2>&1 | awk -F'/' 'END {print (/^round-trip/? $4:"-100")}')
echo "Download: $DOWNLOAD Upload: $UPLOAD Ping: $PING $TIMESTAMP"
curl -i -XPOST 'http://db:8086/write?db=speedtest' --data-binary "download,host=local value=$DOWNLOAD"
curl -i -XPOST 'http://db:8086/write?db=speedtest' --data-binary "upload,host=local value=$UPLOAD"
curl -i -XPOST 'http://db:8086/write?db=speedtest' --data-binary "ping,host=local value=$PING"
sleep $TEST_INTERVAL

done
4 changes: 2 additions & 2 deletions speedweb/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM grafana/grafana
MAINTAINER Pedro César de Azevedo <[email protected]>

ADD conf/grafana.db /var/lib/grafana/grafana.db
ADD conf/home.json /usr/share/grafana/public/dashboards/home.json
COPY conf/grafana.db /var/lib/grafana/grafana.db
COPY conf/home.json /usr/share/grafana/public/dashboards/home.json

ENV GF_SERVER_ROOT_URL http://localhost
ENV GF_SECURITY_ADMIN_PASSWORD admin
Expand Down

0 comments on commit bdb8ef5

Please sign in to comment.