Skip to content

Commit

Permalink
Merge pull request #210 from powerapi-ng/refactor/issue209/prometheus…
Browse files Browse the repository at this point in the history
…-consolidation

Refactor/issue209/prometheus consolidation
  • Loading branch information
gfieni authored Nov 22, 2023
2 parents 707a7fb + e60f2f6 commit 80ce800
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 518 deletions.
70 changes: 20 additions & 50 deletions powerapi/cli/common_cli_parsing_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
from powerapi.cli.parsing_manager import RootConfigParsingManager, SubgroupConfigParsingManager
from powerapi.cli.config_parser import store_true
from powerapi.cli.config_parser import MissingValueException
from powerapi.database.prometheus_db import DEFAULT_METRIC_DESCRIPTION, DEFAULT_MODEL_VALUE, DEFAULT_PUSHER_NAME, \
DEFAULT_ADDRESS
from powerapi.exception import BadTypeException, BadContextException, UnknownArgException

POWERAPI_ENVIRONMENT_VARIABLE_PREFIX = 'POWERAPI_'
Expand All @@ -40,6 +42,8 @@
POWERAPI_PRE_PROCESSOR_ENVIRONMENT_VARIABLE_PREFIX = POWERAPI_ENVIRONMENT_VARIABLE_PREFIX + 'PRE_PROCESSOR_'
POWERAPI_POST_PROCESSOR_ENVIRONMENT_VARIABLE_PREFIX = POWERAPI_ENVIRONMENT_VARIABLE_PREFIX + 'POST_PROCESSOR'

TAGS_ARGUMENT_HELP_TEXT = 'specify report tags'


def extract_file_names(arg, val, args, acc):
"""
Expand Down Expand Up @@ -250,69 +254,35 @@ def __init__(self):
subgroup_parser=subparser_mongo_output
)

subparser_prom_output = SubgroupConfigParsingManager("prom")
subparser_prom_output.add_argument("t", "tags", help_text="specify report tags")
subparser_prom_output.add_argument("u", "uri", help_text="specify server uri")
subparser_prom_output.add_argument(
subparser_prometheus_output = SubgroupConfigParsingManager("prometheus")
subparser_prometheus_output.add_argument("t", "tags", help_text=TAGS_ARGUMENT_HELP_TEXT)
subparser_prometheus_output.add_argument("u", "uri", help_text="specify server uri",
default_value=DEFAULT_ADDRESS)
subparser_prometheus_output.add_argument(
"p", "port", help_text="specify server port", argument_type=int
)
subparser_prom_output.add_argument(
subparser_prometheus_output.add_argument(
"M", "metric_name", help_text="specify metric name"
)
subparser_prom_output.add_argument(
subparser_prometheus_output.add_argument(
"d",
"metric_description",
help_text="specify metric description",
default_value="energy consumption",
)
help_text = "specify number of second for the value must be aggregated before compute statistics on them"
subparser_prom_output.add_argument(
"A", "aggregation_period", help_text=help_text, default_value=15, argument_type=int
)

subparser_prom_output.add_argument(
"m",
"model",
help_text="specify data type that will be stored in the database",
default_value="PowerReport",
)
subparser_prom_output.add_argument(
"n", "name", help_text="specify pusher name", default_value="pusher_prom"
)
self.add_subgroup_parser(
subgroup_name="output",
subgroup_parser=subparser_prom_output
default_value=DEFAULT_METRIC_DESCRIPTION
)

subparser_direct_prom_output = SubgroupConfigParsingManager("direct_prom")
subparser_direct_prom_output.add_argument(
"t", "tags", help_text="specify report tags"
)
subparser_direct_prom_output.add_argument("a", "uri", help_text="specify server uri")
subparser_direct_prom_output.add_argument(
"p", "port", help_text="specify server port", argument_type=int
)
subparser_direct_prom_output.add_argument(
"M", "metric_name", help_text="specify metric name"
)
subparser_direct_prom_output.add_argument(
"d",
"metric_description",
help_text="specify metric description",
default_value="energy consumption",
)
subparser_direct_prom_output.add_argument(
subparser_prometheus_output.add_argument(
"m",
"model",
help_text="specify data type that will be stored in the database",
default_value="PowerReport",
default_value=DEFAULT_MODEL_VALUE,
)
subparser_direct_prom_output.add_argument(
"n", "name", help_text="specify pusher name", default_value="pusher_prom"
subparser_prometheus_output.add_argument(
"n", "name", help_text="specify pusher name", default_value=DEFAULT_PUSHER_NAME
)
self.add_subgroup_parser(
subgroup_name="output",
subgroup_parser=subparser_direct_prom_output
subgroup_parser=subparser_prometheus_output
)

subparser_csv_output = SubgroupConfigParsingManager("csv")
Expand All @@ -328,7 +298,7 @@ def __init__(self):
default_value="PowerReport",
)

subparser_csv_output.add_argument("t", "tags", help_text="specify report tags")
subparser_csv_output.add_argument("t", "tags", help_text=TAGS_ARGUMENT_HELP_TEXT)
subparser_csv_output.add_argument(
"n", "name", help_text="specify pusher name", default_value="pusher_csv"
)
Expand All @@ -339,7 +309,7 @@ def __init__(self):

subparser_influx_output = SubgroupConfigParsingManager("influxdb")
subparser_influx_output.add_argument("u", "uri", help_text="specify InfluxDB uri")
subparser_influx_output.add_argument("t", "tags", help_text="specify report tags")
subparser_influx_output.add_argument("t", "tags", help_text=TAGS_ARGUMENT_HELP_TEXT)
subparser_influx_output.add_argument(
"d", "db", help_text="specify InfluxDB database name"
)
Expand Down Expand Up @@ -385,7 +355,7 @@ def __init__(self):

subparser_influx2_output = SubgroupConfigParsingManager("influxdb2")
subparser_influx2_output.add_argument("u", "uri", help_text="specify InfluxDB uri")
subparser_influx2_output.add_argument("t", "tags", help_text="specify report tags")
subparser_influx2_output.add_argument("t", "tags", help_text=TAGS_ARGUMENT_HELP_TEXT)
subparser_influx2_output.add_argument("k", "token",
help_text="specify token for accessing the database")
subparser_influx2_output.add_argument("g", "org",
Expand Down
2 changes: 1 addition & 1 deletion powerapi/cli/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def validate(self, conf: dict) -> dict:
elif current_argument_name != 'type':
raise UnknownArgException(argument_name=current_argument_name)

return conf
return self.normalize_configuration(conf=conf)

def normalize_configuration(self, conf: dict) -> dict:
"""
Expand Down
20 changes: 8 additions & 12 deletions powerapi/cli/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
TIMEOUT_QUERY_DEFAULT_VALUE
from powerapi.processor.pre.libvirt.libvirt_pre_processor_actor import LibvirtPreProcessorActor
from powerapi.report import HWPCReport, PowerReport, ControlReport, ProcfsReport, Report, FormulaReport
from powerapi.database import MongoDB, CsvDB, InfluxDB, OpenTSDB, SocketDB, PrometheusDB, DirectPrometheusDB, \
from powerapi.database import MongoDB, CsvDB, InfluxDB, OpenTSDB, SocketDB, PrometheusDB, \
VirtioFSDB, FileDB
from powerapi.puller import PullerActor
from powerapi.pusher import PusherActor
Expand Down Expand Up @@ -181,7 +181,7 @@ def __init__(self, component_group_name: str):
self.db_factory = {
'mongodb': lambda db_config: MongoDB(report_type=db_config['model'], uri=db_config['uri'],
db_name=db_config['db'], collection_name=db_config['collection']),
'socket': lambda db_config: SocketDB(db_config['model'], db_config['port']),
'socket': lambda db_config: SocketDB(report_type=db_config['model'], port=db_config['port']),
'csv': lambda db_config: CsvDB(report_type=db_config['model'], tags=gen_tag_list(db_config),
current_path=os.getcwd() if 'directory' not in db_config else db_config[
'directory'],
Expand All @@ -196,16 +196,12 @@ def __init__(self, component_group_name: str):
port=None if 'port' not in db_config else db_config['port']),
'opentsdb': lambda db_config: OpenTSDB(report_type=db_config['model'], host=db_config['uri'],
port=db_config['port'], metric_name=db_config['metric_name']),
'prom': lambda db_config: PrometheusDB(report_type=db_config['model'], port=db_config['port'],
address=db_config['uri'], metric_name=db_config['metric_name'],
metric_description=db_config['metric_description'],
aggregation_periode=db_config['aggregation_period'],
tags=gen_tag_list(db_config)),
'direct_prom': lambda db_config: DirectPrometheusDB(report_type=db_config['model'], port=db_config['port'],
address=db_config['uri'],
metric_name=db_config['metric_name'],
metric_description=db_config['metric_description'],
tags=gen_tag_list(db_config)),
'prometheus': lambda db_config: PrometheusDB(report_type=db_config['model'],
port=db_config['port'],
address=db_config['uri'],
metric_name=db_config['metric_name'],
metric_description=db_config['metric_description'],
tags=gen_tag_list(db_config)),
'virtiofs': lambda db_config: VirtioFSDB(report_type=db_config['model'],
vm_name_regexp=db_config['vm_name_regexp'],
root_directory_name=db_config['root_directory_name'],
Expand Down
1 change: 0 additions & 1 deletion powerapi/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@
from powerapi.database.influxdb2 import InfluxDB2
from powerapi.database.prometheus_db import PrometheusDB
from powerapi.database.virtiofs_db import VirtioFSDB
from powerapi.database.direct_prometheus_db import DirectPrometheusDB
from powerapi.database.socket_db import SocketDB
from powerapi.database.file_db import FileDB
112 changes: 0 additions & 112 deletions powerapi/database/direct_prometheus_db.py

This file was deleted.

Loading

0 comments on commit 80ce800

Please sign in to comment.