scx_stats/scripts/scxstats_to_openmetrics: Retry connection

It now retries until told to exit. This is a bit easier to use and matches
`scx_layered --monitor`.
This commit is contained in:
Tejun Heo 2024-08-19 12:52:57 -10:00
parent f6bc52d31e
commit 4e859d067e

View File

@ -90,21 +90,7 @@ def update_om_metrics(resp, omid, labels, meta_db, om_metrics):
else:
dbg(f'skpping {k_omid}')
def main():
global verbose
parser = argparse.ArgumentParser(
prog='scxstats_to_openmetrics',
description='Read from scx_stats server and output in OpenMetrics format')
parser.add_argument('-i', '--intv', metavar='SECS', type=float, default='2.0',
help='Polling interval (default: %(default)s)')
parser.add_argument('-v', '--verbose', action='count')
parser.add_argument('-p', '--path', metavar='PATH', default='/var/run/scx/root/stats',
help='UNIX domain socket path to connect to (default: %(default)s)')
args = parser.parse_args()
verbose = args.verbose
def connect_and_monitor(args):
# Connect to the stats server.
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(args.path)
@ -160,4 +146,29 @@ def main():
time.sleep(args.intv)
def main():
global verbose
parser = argparse.ArgumentParser(
prog='scxstats_to_openmetrics',
description='Read from scx_stats server and output in OpenMetrics format')
parser.add_argument('-i', '--intv', metavar='SECS', type=float, default='2.0',
help='Polling interval (default: %(default)s)')
parser.add_argument('-v', '--verbose', action='count')
parser.add_argument('-p', '--path', metavar='PATH', default='/var/run/scx/root/stats',
help='UNIX domain socket path to connect to (default: %(default)s)')
args = parser.parse_args()
verbose = args.verbose
last_e = None
while True:
try:
connect_and_monitor(args)
except Exception as e:
if type(e) is not type(last_e):
info(f'{e}, retrying...')
last_e = e
time.sleep(1)
main()