Skip to content

Instantly share code, notes, and snippets.

@fritshoogland-yugabyte
Last active April 13, 2021 13:58
Show Gist options
  • Save fritshoogland-yugabyte/979ab8f67bac5f64c99bd96e8fccb357 to your computer and use it in GitHub Desktop.
Save fritshoogland-yugabyte/979ab8f67bac5f64c99bd96e8fccb357 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import urllib.request as request
import json, time, sys, os, re
from timeit import default_timer as timer
url_to_read = [ { 'url': "http://localhost:13000/rpcz" } ]
os.system('clear')
while True:
clients_dbname = {}
clients_host = {}
clients_port = {}
clients_backend_status = {}
clients_application_name = {}
clients_status = {}
clients_query = {}
clients_process_running_for_ms = {}
clients_query_running_for_ms = {}
clients_transaction_running_for_ms = {}
for current_url in url_to_read:
try:
with request.urlopen(current_url['url']) as response:
http_response = response.read()
parsed_json = json.loads(http_response)
current_time = timer()
except:
print("server: %s not found." % (current_url['url']))
exit(1)
for connection in parsed_json['connections']:
if connection['backend_type'] == 'client backend':
clients_dbname[ connection['host']+':'+connection['port']+' '+connection['process_start_time']] = connection['db_name']
clients_host[ connection['host']+':'+connection['port']+' '+connection['process_start_time']] = connection['host']
clients_port[ connection['host']+':'+connection['port']+' '+connection['process_start_time']] = connection['port']
clients_backend_status[ connection['host']+':'+connection['port']+' '+connection['process_start_time']] = connection['backend_status']
clients_application_name[ connection['host']+':'+connection['port']+' '+connection['process_start_time']] = connection['application_name']
#clients_status[ connection['host']+':'+connection['port']+' '+connection['process_start_time']] = connection['status']
if 'query' in connection:
clients_query[ connection['host']+':'+connection['port']+' '+connection['process_start_time']] = connection['query']
else:
clients_query[connection['host']+':'+connection['port']+' '+connection['process_start_time']] = ''
if 'process_running_for_ms' in connection:
clients_process_running_for_ms[ connection['host']+':'+connection['port']+' '+connection['process_start_time']] = connection['process_running_for_ms']
else:
clients_process_running_for_ms[ connection['host']+':'+connection['port']+' '+connection['process_start_time']] = 0
if 'query_running_for_ms' in connection:
clients_query_running_for_ms[ connection['host']+':'+connection['port']+' '+connection['process_start_time']] = connection['query_running_for_ms']
else:
clients_query_running_for_ms[ connection['host']+':'+connection['port']+' '+connection['process_start_time']] = 0
if 'transaction_running_for_ms' in connection:
clients_transaction_running_for_ms[ connection['host']+':'+connection['port']+' '+connection['process_start_time']] = connection['transaction_running_for_ms']
else:
clients_transaction_running_for_ms[ connection['host']+':'+connection['port']+' '+connection['process_start_time']] = 0
print("%-20s %-20s %-10s %-80s %10s %10s %10s" % ("client address", "application name", "dbname", "query", "proc.run.ms", "tx.run.ms", "query.ms"))
for client in clients_backend_status:
if clients_backend_status[client] != 'idle':
print("%-20s %-20s %-10s %-80s %11d %10d %10d" % (clients_host[client]+':'+clients_port[client], clients_application_name[client], clients_dbname[client], clients_query[client][:80], clients_process_running_for_ms[client], clients_transaction_running_for_ms[client], clients_query_running_for_ms[client]))
try:
input("Press enter...")
except:
print('Cancelled.')
exit(0)
os.system('clear')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment