feat(chalice): CH optimized resources_count_by_type feat(chalice): CH optimized calls_errors_4xx feat(chalice): CH optimized calls_errors_5xx feat(chalice): CH optimized calls_errors feat(chalice): CH optimized sessions_per_browser feat(chalice): CH optimized errors_per_domains feat(chalice): CH optimized domains_errors_4xx feat(chalice): CH optimized domains_errors_5xx feat(chalice): CH optimized domains_errors feat(chalice): CH optimized crashes feat(chalice): CH optimized top_metrics feat(chalice): CH optimized busiest_time_of_day feat(chalice): CH optimized pages_response_time_distribution feat(chalice): CH optimized sessions_location feat(chalice): CH optimized network feat(chalice): CH optimized missing_resources widget feat(chalice): CH optimized slowest_images widget feat(chalice): CH optimized errors_trend widget feat(chalice): CH optimized sessions widget feat(chalice): CH optimized count_requests widget feat(chalice): CH optimized avg_visited_pages widget feat(chalice): CH optimized resources_by_party widget feat(chalice): CH fixed avg_response_time widget feat(chalice): CH client settings changes
47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
import logging
|
|
|
|
import clickhouse_driver
|
|
from decouple import config
|
|
|
|
logging.basicConfig(level=config("LOGLEVEL", default=logging.INFO))
|
|
logging.getLogger('apscheduler').setLevel(config("LOGLEVEL", default=logging.INFO))
|
|
|
|
settings = {}
|
|
if config('ch_timeout', cast=int, default=-1) > 0:
|
|
logging.info(f"CH-max_execution_time set to {config('ch_timeout')}s")
|
|
settings = {**settings, "max_execution_time": config('ch_timeout', cast=int)}
|
|
|
|
if config('ch_receive_timeout', cast=int, default=-1) > 0:
|
|
logging.info(f"CH-receive_timeout set to {config('ch_receive_timeout')}s")
|
|
settings = {**settings, "receive_timeout": config('ch_receive_timeout', cast=int)}
|
|
|
|
|
|
class ClickHouseClient:
|
|
__client = None
|
|
|
|
def __init__(self):
|
|
self.__client = clickhouse_driver.Client(host=config("ch_host"),
|
|
database="default",
|
|
port=config("ch_port", cast=int),
|
|
settings=settings) \
|
|
if self.__client is None else self.__client
|
|
|
|
def __enter__(self):
|
|
return self
|
|
|
|
def execute(self, query, params=None, **args):
|
|
results = self.__client.execute(query=query, params=params, with_column_types=True, **args)
|
|
keys = tuple(x for x, y in results[1])
|
|
return [dict(zip(keys, i)) for i in results[0]]
|
|
|
|
def insert(self, query, params=None, **args):
|
|
return self.__client.execute(query=query, params=params, **args)
|
|
|
|
def client(self):
|
|
return self.__client
|
|
|
|
def format(self, query, params):
|
|
return self.__client.substitute_params(query, params, self.__client.connection.context)
|
|
|
|
def __exit__(self, *args):
|
|
pass
|