Compare commits
3 Commits
d65f7e3f1f
...
aaafebdef1
| Author | SHA1 | Date | |
|---|---|---|---|
| aaafebdef1 | |||
| f564068ea5 | |||
| b794cbd6cf |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1 @@
|
|||||||
.venv
|
/.venv/
|
||||||
.idea
|
|
||||||
|
|||||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.11 (tmobile-monitor)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (tmobile-monitor)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
10
.idea/tmobile-monitor.iml
generated
Normal file
10
.idea/tmobile-monitor.iml
generated
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Use the official Python image from the Docker Hub
|
||||||
|
FROM python:3.9-slim
|
||||||
|
|
||||||
|
# Set the working directory inside the container
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy the requirements file and the script into the container
|
||||||
|
COPY requirements.txt .
|
||||||
|
COPY tmobile_monitor.py .
|
||||||
|
|
||||||
|
# Install the Python dependencies
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# Expose the port that the Prometheus client will use
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
# Run the script
|
||||||
|
CMD ["python", "tmobile_monitor.py"]
|
||||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
requests~=2.31.0
|
||||||
|
beautifulsoup4~=4.12.3
|
||||||
|
prometheus_client~=0.20.0
|
||||||
39
tmobile_monitor.py
Normal file
39
tmobile_monitor.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from prometheus_client import start_http_server, Gauge
|
||||||
|
import time
|
||||||
|
|
||||||
|
metrics = {
|
||||||
|
'snr': Gauge('snr', 'Signal to Noise Ratio'),
|
||||||
|
'internetStatusRSRP': Gauge('rsrp', 'Reference Signal Received Power'),
|
||||||
|
'internetStatusRSRQ': Gauge('rsrq', 'Reference Signal Received Quality')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def collect_metrics():
|
||||||
|
url = 'http://192.168.1.1'
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.get(url, verify=False)
|
||||||
|
response.raise_for_status()
|
||||||
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
|
|
||||||
|
for key in metrics:
|
||||||
|
element = soup.find('div', id=key)
|
||||||
|
if element:
|
||||||
|
value = float(element.text.strip().split()[0])
|
||||||
|
metrics[key].set(value)
|
||||||
|
else:
|
||||||
|
print(f"{key.upper()} value not found on the page.")
|
||||||
|
|
||||||
|
except requests.RequestException as e:
|
||||||
|
print(f"Error fetching data from {url}: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
start_http_server(8000)
|
||||||
|
print("HTTP server started on port 8000")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
collect_metrics()
|
||||||
|
time.sleep(10)
|
||||||
Loading…
x
Reference in New Issue
Block a user