Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to analyzer brief #51

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions duetector/analyzer/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def brief(
]

return AnalyzerBrief(
tracers=[brief.tracer for brief in briefs],
collector_ids=[brief.collector_id for brief in briefs],
tracers=set([brief.tracer for brief in briefs]),
collector_ids=set([brief.collector_id for brief in briefs]),
briefs=briefs,
)
36 changes: 31 additions & 5 deletions duetector/analyzer/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from datetime import datetime
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Set

import pydantic

Expand Down Expand Up @@ -67,20 +67,46 @@ class Brief(pydantic.BaseModel):
count: Optional[int] = None
fields: Dict[str, Any] = {}

def __repr__(self):
fields_repr = ", ".join([f"{k}: {v.__name__}" for k, v in self.fields.items()])

s = f"""
{self.tracer}@{self.collector_id} with {self.count} records
from {self.start} to {self.end}
available fields: [{fields_repr}]
"""

return s

def __str__(self):
return self.__repr__()


class AnalyzerBrief(pydantic.BaseModel):
"""
Brief of analyzer.
"""

tracers: List[str]
tracers: Set[str]
"""
List of tracers
Set of tracers
"""

collector_ids: List[str]
collector_ids: Set[str]
"""
List of collector ids
Set of collector ids
"""

briefs: List[Brief]

def __repr__(self):
briefs_repr = "\n".join([f"\n----------------{b}----------------" for b in self.briefs])
s = f"""
Available tracers: {self.tracers}
Available collector ids: {self.collector_ids}
briefs: {briefs_repr}
"""
return s

def __str__(self):
return self.__repr__()
21 changes: 18 additions & 3 deletions duetector/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import click

from duetector.analyzer.db import DBAnalyzer
from duetector.config import CONFIG_PATH, ConfigLoader
from duetector.log import logger
from duetector.monitors import BccMonitor, ShMonitor
Expand Down Expand Up @@ -94,7 +95,9 @@ def generate_config(path):

@click.command()
@click.option(
"--config", default=CONFIG_PATH, help=f"Config file path, default: ``{CONFIG_PATH}``."
"--config",
default=CONFIG_PATH,
help=f"Config file path, default: ``{CONFIG_PATH}``.",
)
@click.option(
"--load_env",
Expand Down Expand Up @@ -124,13 +127,19 @@ def generate_config(path):
default=True,
help=f"Set false or False to disable shell monitor, default: ``True``.",
)
@click.option(
"--brief",
default=True,
help=f"Print brief when exit, default: ``True``.",
)
def start(
config,
load_env,
dump_when_load,
config_dump_dir,
enable_bcc_monitor,
enable_sh_monitor,
brief,
):
"""
Start A bcc monitor and wait for KeyboardInterrupt
Expand All @@ -157,8 +166,14 @@ def _shutdown(sig=None, frame=None):
logger.info("Exiting...")
for m in monitors:
m.shutdown()
for m in monitors:
logger.info(m.summary())
logger.info("All monitors shutdown.")
if brief:
try:
logger.info("Generating brief...")
logger.info(str(DBAnalyzer(c).brief()))
except Exception as e:
logger.error("Exception when generating brief")
logger.exception(e)
exit(0)

signal.signal(signal.SIGINT, _shutdown)
Expand Down
Loading