Skip to content

Commit

Permalink
new: Display lacus monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Jan 23, 2024
1 parent 3443d50 commit 7e188b8
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions tools/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import os
import sys

from typing import List, Tuple, Any
from typing import Any

from redis import Redis
from redis.exceptions import ConnectionError
from rich.console import Console
from rich.padding import Padding

from lookyloo.default import get_socket_path, AbstractManager
from pylacus import PyLacus

from lookyloo.default import get_socket_path, AbstractManager, get_config

# NOTE: run with watch:
# watch --color tools/monitoring.py
Expand All @@ -22,9 +24,19 @@

class Monitoring():

lacus: PyLacus | None = None

def __init__(self) -> None:
self.redis_cache: Redis = Redis(unix_socket_path=get_socket_path('cache'), decode_responses=True) # type: ignore[type-arg]
self.redis_indexing: Redis = Redis(unix_socket_path=get_socket_path('indexing'), decode_responses=True) # type: ignore[type-arg]
# try to connect to a remote lacus if lookyloo is configured this way
if remote_lacus_config := get_config('generic', 'remote_lacus'):
if remote_lacus_config.get('enable'):
remote_lacus_url = remote_lacus_config.get('url')
self.lacus = PyLacus(remote_lacus_url)
if not self.lacus.is_up:
self.lacus = None
console.print(f'[red]WARNING[/red]: Remote lacus is configured but not reachable: {remote_lacus_url}.')

@property
def backend_status(self) -> bool:
Expand Down Expand Up @@ -89,6 +101,17 @@ def tree_cache(self) -> dict[str, str]:
to_return[pid_name] = value
return to_return

def lacus_status(self) -> dict[str, Any]:
if not self.lacus:
return {}
to_return = {}
to_return['is_busy'] = self.lacus.is_busy()
status = self.lacus.status()
to_return['max_concurrent_captures'] = status['max_concurrent_captures']
to_return['ongoing_captures'] = status['ongoing_captures']
to_return['enqueued_captures'] = status['enqueued_captures']
return to_return


if __name__ == '__main__':

Expand All @@ -109,6 +132,14 @@ def tree_cache(self) -> dict[str, str]:
s = Padding(f'{name}: {status}', (0, 2))
console.print(s)

if m.lacus is not None:
status = m.lacus_status()
console.print('Lacus status:')
if status['is_busy']:
console.print(Padding('[red]WARNING[/red]: Lacus is busy.', (0, 2)))
console.print(Padding(f'Ongoing captures: {status["ongoing_captures"]}', (0, 2)))
console.print(Padding(f'Enqueued captures: {status["enqueued_captures"]}', (0, 2)))

console.print('Current queues:')
for q, priority in m.queues:
s = Padding(f'{q} Recently enqueued captures: {int(priority)}', (0, 2))
Expand Down

0 comments on commit 7e188b8

Please sign in to comment.