Mostly cosmetic changes

A few things I noticed while porting this code to the JSON script. The only real change here is fixing the bulk history output to print UTC time instead of local time.
This commit is contained in:
sparky8512 2021-02-21 13:57:48 -08:00
parent 258a33d62d
commit e10c9dbb7f
3 changed files with 12 additions and 12 deletions

View file

@ -74,8 +74,8 @@ def create_arg_parser(output_description, bulk_history=True):
metavar="N")
if bulk_history:
sample_help = ("Number of data samples to parse; normally applies to first loop "
"iteration only, default: -1 in bulk mode, loop interval if loop interval "
"set, else " + str(SAMPLES_DEFAULT))
"iteration only, default: all in bulk mode, loop interval if loop "
"interval set, else " + str(SAMPLES_DEFAULT))
no_counter_help = ("Don't track sample counter across loop iterations in non-bulk "
"modes; keep using samples option value instead")
else:

View file

@ -65,7 +65,7 @@ def parse_args():
opts = dish_common.run_arg_parser(parser, no_stdout_errors=True)
if len(opts.mode) > 1 and "bulk_history" in opts.mode:
if (opts.history_stats_mode or opts.satus_mode) and opts.bulk_mode:
parser.error("bulk_history cannot be combined with other modes for CSV output")
return opts
@ -148,8 +148,8 @@ def loop_body(opts, gstate):
def cb_add_bulk(bulk, count, timestamp, counter):
if opts.verbose:
print("Time range (UTC): {0} -> {1}".format(
datetime.fromtimestamp(timestamp).isoformat(),
datetime.fromtimestamp(timestamp + count).isoformat()))
datetime.utcfromtimestamp(timestamp).isoformat(),
datetime.utcfromtimestamp(timestamp + count).isoformat()))
for key, val in bulk.items():
print("{0:22} {1}".format(key + ":", ", ".join(str(subval) for subval in val)))
if opts.loop_interval > 0.0:
@ -157,7 +157,7 @@ def loop_body(opts, gstate):
else:
for i in range(count):
timestamp += 1
fields = [datetime.fromtimestamp(timestamp).isoformat()]
fields = [datetime.utcfromtimestamp(timestamp).isoformat()]
fields.extend(["" if val[i] is None else str(val[i]) for val in bulk.values()])
print(",".join(fields))

View file

@ -883,7 +883,7 @@ def history_ping_stats(parse_samples, verbose=False, context=None):
def history_stats(parse_samples, start=None, verbose=False, context=None, history=None):
"""Fetch, parse, and compute the packet loss stats.
"""Fetch, parse, and compute ping and usage stats.
Note:
See module level docs regarding brackets in field names.
@ -918,10 +918,10 @@ def history_stats(parse_samples, start=None, verbose=False, context=None, histor
except grpc.RpcError as e:
raise GrpcError(e)
sample_range, parse_samples, current = _compute_sample_range(history,
parse_samples,
start=start,
verbose=verbose)
sample_range, parsed_samples, current = _compute_sample_range(history,
parse_samples,
start=start,
verbose=verbose)
tot = 0.0
count_full_drop = 0
@ -1051,7 +1051,7 @@ def history_stats(parse_samples, start=None, verbose=False, context=None, histor
deciles_full = [None] * 11
return {
"samples": parse_samples,
"samples": parsed_samples,
"end_counter": current,
}, {
"total_ping_drop": tot,