-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dda9c8f
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Build and Push Docker image | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USER }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
push: true | ||
tags: dombyy/pinger:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# pull official base image | ||
FROM python:3.9.5-slim-buster | ||
|
||
# set work directory | ||
WORKDIR /usr/src/app | ||
|
||
# install dependencies | ||
COPY ./requirements.txt . | ||
RUN pip3 install --upgrade pip wheel \ | ||
&& pip3 install -r requirements.txt | ||
|
||
# copy project | ||
COPY . . | ||
|
||
USER root | ||
EXPOSE 8080 | ||
CMD ["/bin/bash", "-c", "python3 main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env python3 | ||
import time | ||
from datetime import datetime | ||
from nicegui import ui, app | ||
import os | ||
from ping3 import ping, verbose_ping | ||
|
||
|
||
if 'PINGER_IPS' not in os.environ: | ||
print('define PINGER_IPS > 1.1.1.1,8.8.8.8') | ||
quit() | ||
|
||
ips = os.getenv('PINGER_IPS').split(',') | ||
|
||
maxTimeSec = 600 | ||
pingAlertLimitMs = 100 | ||
maxPingResponseTimeS = 0.3 | ||
chartRefreshS = 1 | ||
chart = [] | ||
pingTimer = [] | ||
pingIntervalS = 1 | ||
|
||
for ip in ips: | ||
chart.append(ui.chart({'title': { 'text': ip}, | ||
'chart': { 'type': 'area', 'zoomType': 'x' }, | ||
'xAxis': { 'type': 'datetime' }, | ||
'yAxis': { 'title': {'text':'ms'}}, | ||
'time': { 'timezoneOffset': 7200}, | ||
'legend': { 'enabled': False }, | ||
'series': [{'name' : ip, 'data': [], 'color': '#32a84c'}], | ||
} | ||
).classes('w-full h-64')) | ||
|
||
log = ui.log(max_lines=30).classes('w-full h-96 bg-black text-white') | ||
|
||
def clear(): | ||
i = -1 | ||
|
||
for ip in ips: | ||
i+= 1 | ||
chart[i].options['series'][0]['data'].clear() | ||
|
||
log.clear() | ||
log.push("Auto refresh time: " + str(chartRefreshS) + "sec") | ||
|
||
ui.button('Clear all', on_click=clear) | ||
|
||
def ping_internal(i): | ||
global ips, conn, c, maxTimeSec, maxResponseTimeMs | ||
ip = ips[i] | ||
|
||
response_time = ping(ip, timeout=maxPingResponseTimeS, unit='ms') | ||
if response_time is None: | ||
print(datetime.now().strftime('%H:%M:%S') + " no ping reply from " + ip) | ||
log.push(datetime.now().strftime('%H:%M:%S') + " no ping reply from " + ip) | ||
ui.notify(datetime.now().strftime('%H:%M:%S') + " no ping reply from " + ip, type='negative') | ||
|
||
chart[i].options['series'][0]['data'].append({'x': int(time.time()*1000), 'y': 0, 'marker': { 'radius': 3, 'fillColor': '#eb0909' }}) | ||
|
||
else: | ||
chart[i].options['series'][0]['data'].append({'x': int(time.time()*1000), 'y': round(response_time,2), 'marker': { 'radius': 0 }}) | ||
|
||
if len(chart[i].options['series'][0]['data']) > maxTimeSec: | ||
chart[i].options['series'][0]['data'].pop(0) | ||
|
||
if response_time > pingAlertLimitMs: | ||
log.push(datetime.now().strftime('%H:%M:%S') + " high ping reply time from " + ip + " > " + str(response_time) + " ms") | ||
|
||
|
||
def updateCharts(): | ||
global ips, conn, c, maxTimeSec, maxResponseTimeMs | ||
i = -1 | ||
|
||
for ip in ips: | ||
i+= 1 | ||
chart[i].update() | ||
|
||
|
||
i = -1 | ||
for ip in ips: | ||
i += 1 | ||
pingTimer.append(ui.timer(pingIntervalS, lambda iter=i: ping_internal(iter))) | ||
|
||
# ui.timer(round(len(ips)*maxPingResponseTimeS+1), lambda: ping_internals()) | ||
chartTimer = ui.timer(chartRefreshS, lambda: updateCharts()) | ||
|
||
log.push("Auto refresh time: " + str(chartRefreshS) + "sec") | ||
ui.run(title="pinger", show="False", favicon="📶") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
uvicorn==0.20.0 | ||
nicegui==1.2.23 | ||
ping3==4.0.4 |