Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
oversize committed Jul 18, 2023
1 parent b631190 commit 68cb3e2
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 173 deletions.
73 changes: 0 additions & 73 deletions client_connect_listen.py

This file was deleted.

79 changes: 0 additions & 79 deletions client_connect_publish.py

This file was deleted.

12 changes: 12 additions & 0 deletions contrib/blockperf.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To have this file loaded in a bash session use
# set -a && source blockperf.env
#
BLOCKPERF_NODE_CONFIG="/opt/cardano/cnode/files/config.json"
BLOCKPERF_RELAY_PUBLIC_IP="35.158.252.71"
#BLOCKPERF_RELAY_PUBLIC_PORT="3001"
BLOCKPERF_OPERATOR="devmanuel"
BLOCKPERF_CLIENT_CERT="/home/ubuntu/devmanuel-certificate.pem"
BLOCKPERF_CLIENT_KEY="/home/ubuntu/devmanuel-private.key"
BLOCKPERF_TOPIC_BASE="blockperf"
BLOCKPERF_BROKER_URL="a12j2zhynbsgdv-ats.iot.eu-central-1.amazonaws.com"
#BLOCKPERF_BROKER_PORT="8883"
2 changes: 1 addition & 1 deletion contrib/blockperf.service
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Type=simple
Restart=always
RestartSec=20
User=ubuntu
Environment=someenvfile
Environment=/opt/cardano/cnode/blockperf/contrib/blockperf.env
ExecStart=/opt/cardano/cnode/blockperf/venv/bin/blockperf run /opt/cardano/cnode/blockperf/blockperf.ini
KillSignal=SIGINT
SyslogIdentifier=blockperf
Expand Down
13 changes: 6 additions & 7 deletions src/blockperf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

logging.basicConfig(
level=logging.DEBUG,
filename='/home/ubuntu/src/blockperf/blockperf.log',
filename='/opt/cardano/cnode/blockperf/blockperf.log',
filemode='w',
format="%(name)s %(threadName)s [%(asctime)s %(levelname)s] %(message)s",
datefmt='%H:%M:%S'
Expand All @@ -24,20 +24,19 @@
def main(verbose):
"""Blockperf.py - Cardano-network block performance measurement and analysis.
This script is based off of blockperf.sh which collects certain metrics from
the cardano-node and sends it to an aggregation services for further
analysis.
This script is based on blockperf.sh which collects data from the cardano-node
and sends it to an aggregation services for further analysis.
"""
# dont print() but click.echo()
click.echo("Main runs")
pass


@click.command("run", short_help="Runs blockperf with given configuration")
@click.command("run", short_help="Runs blockperf")
@click.argument(
"config_file_path", required=True, type=click.Path(resolve_path=True, exists=True)
"config_file_path", required=False, type=click.Path(resolve_path=True, exists=True)
)
def cmd_run(config_file_path):
def cmd_run(config_file_path=None):
"""Run blockperf with given configuration"""
try:
LOG.info("Start blockperf")
Expand Down
53 changes: 40 additions & 13 deletions src/blockperf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
Why configparser? Because its simple. There is a blockperf.ini file in the
contrib/ folder which has all options and a short explanation of what they do.
"""
from pathlib import Path
from configparser import ConfigParser
import os
import json
import os
from configparser import ConfigParser
from pathlib import Path
from typing import Union


class ConfigError(Exception):
Expand All @@ -15,9 +16,10 @@ class ConfigError(Exception):
class AppConfig:
config_parser: ConfigParser

def __init__(self, config: Path):
def __init__(self, config: Union[Path, None]):
self.config_parser = ConfigParser()
self.config_parser.read(config)
if config:
self.config_parser.read(config)

# def validate_config(self):
# node_config_folder = node_config_path.parent
Expand Down Expand Up @@ -75,33 +77,48 @@ def network_magic(self) -> int:

@property
def relay_public_ip(self) -> str:
relay_public_ip = self.config_parser.get("DEFAULT", "relay_public_ip")
relay_public_ip = os.getenv(
"BLOCKPERF_RELAY_PUBLIC_IP",
self.config_parser.get("DEFAULT", "relay_public_ip", fallback=None)
)
if not relay_public_ip:
raise ConfigError("'relay_public_ip' not set!")
return relay_public_ip

@property
def relay_public_port(self) -> int:
relay_public_port = int(self.config_parser.get("DEFAULT", "relay_public_port", fallback=3001))
relay_public_port = int(os.getenv(
"BLOCKPERF_RELAY_PUBLIC_PORT",
self.config_parser.get("DEFAULT", "relay_public_port", fallback=3001)
))
return relay_public_port

@property
def client_cert(self) -> str:
client_cert = self.config_parser.get("DEFAULT", "client_cert")
client_cert = os.getenv(
"BLOCKPERF_CLIENT_CERT",
self.config_parser.get("DEFAULT", "client_cert", fallback=None)
)
if not client_cert:
raise ConfigError("No client_cert set")
return client_cert

@property
def client_key(self) -> str:
client_key = self.config_parser.get("DEFAULT", "client_key")
client_key = os.getenv(
"BLOCKPERF_CLIENT_KEY",
self.config_parser.get("DEFAULT", "client_key", fallback=None)
)
if not client_key:
raise ConfigError("No client_key set")
return client_key

@property
def operator(self) -> str:
operator = self.config_parser.get("DEFAULT", "operator")
operator = os.getenv(
"BLOCKPERF_OPERATOR",
self.config_parser.get("DEFAULT", "operator", fallback=None)
)
if not operator:
raise ConfigError("No operator set")
return operator
Expand All @@ -112,21 +129,31 @@ def lock_file(self) -> str:

@property
def topic_base(self) -> str:
return self.config_parser.get("DEFAULT", "topic_base", fallback="develop")
topic_base = os.getenv(
"BLOCKPERF_TOPIC_BASE",
self.config_parser.get("DEFAULT", "topic_base", fallback="develop")
)
return topic_base

@property
def mqtt_broker_url(self) -> str:
return str(
broker_url = os.getenv(
"BLOCKPERF_BROKER_URL",
self.config_parser.get(
"DEFAULT",
"mqtt_broker_url",
fallback="a12j2zhynbsgdv-ats.iot.eu-central-1.amazonaws.com",
)
)
return broker_url

@property
def mqtt_broker_port(self) -> int:
return int(self.config_parser.get("DEFAULT", "mqtt_broker_port", fallback=8883))
broker_port = int(os.getenv(
"BLOCKPERF_BROKER_PORT",
self.config_parser.get("DEFAULT", "mqtt_broker_port", fallback=8883)
))
return broker_port

@property
def enable_tracelogs(self) -> bool:
Expand Down

0 comments on commit 68cb3e2

Please sign in to comment.