Merge pull request #35422 from bigo-sg/add_args_for_diagnose

Add some arguments for clickhouse-diagnostics
This commit is contained in:
Alexey Milovidov 2022-03-20 21:36:23 +03:00 committed by GitHub
commit d58fa08d93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -22,7 +22,7 @@ python3 -m pip install -r requirements.txt
## Usage
```
./clickhouse-diagnostics
./clickhouse-diagnostics --host localhost --port 8123 --user default --password xxx
```
Example output:

18
utils/clickhouse-diagnostics/clickhouse-diagnostics Normal file → Executable file
View File

@ -12,6 +12,7 @@ from datetime import datetime
from typing import MutableMapping
import jinja2
from pandas import describe_option
import requests
import sqlparse
import tenacity
@ -498,10 +499,11 @@ class ClickhouseClient:
ClickHouse client.
"""
def __init__(self, *, host, port=8123, user=None):
def __init__(self, *, host="localhost", port=8123, user="default", password):
self._session = requests.Session()
if user:
self._session.headers['X-ClickHouse-User'] = user
self._session.headers['X-ClickHouse-Key'] = password
self._url = f'http://{host}:{port}'
self._timeout = 60
self._ch_version = None
@ -598,9 +600,9 @@ class DiagnosticsData:
Diagnostics data.
"""
def __init__(self, args, host):
def __init__(self, args):
self.args = args
self.host = host
self.host = args.host
self._sections = [{'section': None, 'data': {}}]
def add_string(self, name, value, section=None):
@ -758,15 +760,13 @@ def main():
Program entry point.
"""
args = parse_args()
host = socket.getfqdn()
timestamp = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')
client = ClickhouseClient(host=host)
client = ClickhouseClient(host=args.host, port=args.port, user=args.user, password=args.password)
ch_config = ClickhouseConfig.load()
version = client.clickhouse_version
system_tables = [row[0] for row in execute_query(client, SELECT_SYSTEM_TABLES, format='JSONCompact')['data']]
diagnostics = DiagnosticsData(args, host)
diagnostics = DiagnosticsData(args)
diagnostics.add_string('Version', version)
diagnostics.add_string('Timestamp', timestamp)
diagnostics.add_string('Uptime', execute_query(client, SELECT_UPTIME))
@ -895,6 +895,10 @@ def parse_args():
parser.add_argument('--normalize-queries',
action='store_true',
default=False)
parser.add_argument('--host', dest="host", help="clickhouse host")
parser.add_argument('--port', dest="port", default=8123, help="clickhouse http port")
parser.add_argument('--user', dest="user", default="default", help="clickhouse user")
parser.add_argument('--password', dest="password", help="clickhouse password")
return parser.parse_args()