feat: integrate yaspin for improved logging and error handling in Chrome driver setup
All checks were successful
Build and Push Docker Image / build (push) Successful in 1m5s
All checks were successful
Build and Push Docker Image / build (push) Successful in 1m5s
This commit is contained in:
16
main.py
16
main.py
@@ -4,6 +4,7 @@ import time
|
|||||||
import socket
|
import socket
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from yaspin import yaspin
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from http.server import HTTPServer
|
from http.server import HTTPServer
|
||||||
from utils.PostHandler import Handler
|
from utils.PostHandler import Handler
|
||||||
@@ -34,6 +35,7 @@ def interrupt_handler(signum, driver: webdriver.Remote):
|
|||||||
driver.quit()
|
driver.quit()
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
|
@yaspin()
|
||||||
def setupChromeDriver():
|
def setupChromeDriver():
|
||||||
logger.log(logging.INFO, 'Setting up Chrome driver.')
|
logger.log(logging.INFO, 'Setting up Chrome driver.')
|
||||||
chrome_options = Options()
|
chrome_options = Options()
|
||||||
@@ -159,7 +161,8 @@ def downloadStats(driver: webdriver.Chrome, peersDict: dict):
|
|||||||
|
|
||||||
def convert_to_bytes(down, downUnit):
|
def convert_to_bytes(down, downUnit):
|
||||||
return float(down) * (1024 ** {'B': 0, 'KB': 1, 'MB': 2, 'GB': 3}[downUnit])
|
return float(down) * (1024 ** {'B': 0, 'KB': 1, 'MB': 2, 'GB': 3}[downUnit])
|
||||||
|
|
||||||
|
@yaspin()
|
||||||
def setupStats(driver: webdriver.Remote, url: str):
|
def setupStats(driver: webdriver.Remote, url: str):
|
||||||
logger.log(logging.INFO, 'Setting up stats.')
|
logger.log(logging.INFO, 'Setting up stats.')
|
||||||
actions = ActionChains(driver)
|
actions = ActionChains(driver)
|
||||||
@@ -167,7 +170,13 @@ def setupStats(driver: webdriver.Remote, url: str):
|
|||||||
|
|
||||||
driver.get(url)
|
driver.get(url)
|
||||||
|
|
||||||
wait.until(ec.presence_of_element_located((By.CLASS_NAME, 'vjs-big-play-button')))
|
try:
|
||||||
|
wait.until(ec.presence_of_element_located((By.CLASS_NAME, 'vjs-big-play-button')))
|
||||||
|
except Exception:
|
||||||
|
logger.error('Timeout while waiting for the big play button to be present.')
|
||||||
|
driver.quit()
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
||||||
actions.click(driver.find_element(By.CLASS_NAME ,'video-js')).perform()
|
actions.click(driver.find_element(By.CLASS_NAME ,'video-js')).perform()
|
||||||
wait.until(ec.visibility_of_element_located((By.CLASS_NAME, 'vjs-control-bar')))
|
wait.until(ec.visibility_of_element_located((By.CLASS_NAME, 'vjs-control-bar')))
|
||||||
actions.context_click(driver.find_element(By.CLASS_NAME ,'video-js')).perform()
|
actions.context_click(driver.find_element(By.CLASS_NAME ,'video-js')).perform()
|
||||||
@@ -193,7 +202,6 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
setupStats(driver, url)
|
setupStats(driver, url)
|
||||||
|
|
||||||
logger.log(logging.INFO, 'Starting server collector.')
|
logger.info('Starting server collector.')
|
||||||
httpd = HTTPServer(('', 9092), partial(Handler, downloadStats, driver, logger))
|
httpd = HTTPServer(('', 9092), partial(Handler, downloadStats, driver, logger))
|
||||||
logger.info('Server collector started.')
|
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
@@ -1,2 +1,3 @@
|
|||||||
selenium
|
selenium
|
||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
|
yaspin
|
@@ -22,7 +22,7 @@ class WebrtcInternalExporter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
window.postMessage({ event: "webrtc-internal-exporter:ready" });
|
window.postMessage({ event: "webrtc-internal-exporter:ready" });
|
||||||
this.collectAllStats();
|
setInterval(() => this.collectAndPostAllStats(), this.updateInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
randomId() {
|
randomId() {
|
||||||
@@ -41,7 +41,7 @@ class WebrtcInternalExporter {
|
|||||||
this.peerConnections.set(id, pc);
|
this.peerConnections.set(id, pc);
|
||||||
pc.addEventListener("connectionstatechange", () => {
|
pc.addEventListener("connectionstatechange", () => {
|
||||||
log(`connectionStateChange: ${pc.connectionState}`);
|
log(`connectionStateChange: ${pc.connectionState}`);
|
||||||
this.collectAndPostSingleStat(id);
|
this.collectAndPostAllStats();
|
||||||
|
|
||||||
if (pc.connectionState === "closed") {
|
if (pc.connectionState === "closed") {
|
||||||
this.peerConnections.delete(id);
|
this.peerConnections.delete(id);
|
||||||
@@ -100,7 +100,7 @@ class WebrtcInternalExporter {
|
|||||||
log(`Single stat collected:`, [stats]);
|
log(`Single stat collected:`, [stats]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async collectAllStats() {
|
async collectAndPostAllStats() {
|
||||||
const stats = [];
|
const stats = [];
|
||||||
|
|
||||||
for (const [id] of this.peerConnections) {
|
for (const [id] of this.peerConnections) {
|
||||||
@@ -120,8 +120,7 @@ class WebrtcInternalExporter {
|
|||||||
);
|
);
|
||||||
|
|
||||||
log(`Stats collected:`, stats);
|
log(`Stats collected:`, stats);
|
||||||
|
|
||||||
setTimeout(this.collectAllStats.bind(this), this.updateInterval);
|
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user