40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
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)
|