8000 add --timeline option to draw virtical line every 10/60 seconds by shigechika · Pull Request #24 · upa/deadman · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add --timeline option to draw virtical line every 10/60 seconds #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions deadman
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ RESULT_STR_LENGTH = 10
DEFAULT_COLOR = 1
UP_COLOR = 2
DOWN_COLOR = 3
SEC_ZERO_COLOR = 4
SEC_TENS_COLOR = 5

RTT_SCALE = 10
TIMELINE = False

SSH_CONNECT_TIMEOUT = 3

Expand Down Expand Up @@ -96,6 +99,7 @@ class PingTarget:
self.result = []
self.ping = Ping(self.addr, osname, relay = relay, source = source,
tcp = tcp)
self.localtime = []

return

Expand All @@ -114,6 +118,7 @@ class PingTarget:
asyncio.run(self.async_send())

async def async_send(self):
self.localtime.insert(0, time.localtime())
res = await self.ping.async_send()
self.snt += 1
self.consume_ping_result(res)
Expand All @@ -135,6 +140,7 @@ class PingTarget:
self.result.insert(0, self.get_result_char(res))

while len(self.result) > RESULT_STR_LENGTH:
self.localtime.pop()
self.result.pop()

return
Expand Down Expand Up @@ -174,6 +180,7 @@ class PingTarget:
self.snt = 0
self.ttl = 0
self.result = []
self.localtime = []

return

Expand Down Expand Up @@ -468,6 +475,11 @@ class CursesCtrl():
self.waddstr(1, spacelen, TITLE_VERSION, curses.A_BOLD)
self.waddstr(2, len(ARROW),
"RTT Scale %dms. Keys: (r)efresh" % RTT_SCALE)
if TIMELINE:
self.disptime = time.localtime()
dispstr = time.strftime("%y/%m/%d %H:%M:%S", self.disptime)
spacelen = self.x - (len(ARROW) + len(dispstr))
self.waddstr(2, spacelen, dispstr)
self.stdscr.move(0, 0)
self.stdscr.refresh()
return
Expand Down Expand Up @@ -533,6 +545,11 @@ class CursesCtrl():
color = curses.color_pair(UP_COLOR)
else:
color = curses.color_pair(DOWN_COLOR)
if TIMELINE:
if target.localtime[n].tm_sec == 0:
color = curses.color_pair(SEC_ZERO_COLOR)
elif target.localtime[n].tm_sec % 10 == 0:
color = curses.color_pair(SEC_TENS_COLOR)

y, x = self.stdscr.getmaxyx()
if self.res_start + n > x:
Expand Down Expand Up @@ -688,7 +705,8 @@ class Deadman:
if BLINK_ARROW:
self.curs.erase_arrow(idx)

time.sleep(PING_ALLTARGET_INTERVAL)
if TIMELINE is False:
time.sleep(PING_ALLTARGET_INTERVAL)


def refresh_window(self, signum, frame):
Expand Down Expand Up @@ -788,6 +806,8 @@ def main(stdscr, configfile, async_mode):
curses.init_pair(DEFAULT_COLOR, -1, -1)
curses.init_pair(UP_COLOR, curses.COLOR_GREEN, -1)
curses.init_pair(DOWN_COLOR, curses.COLOR_RED, -1)
curses.init_pair(SEC_TENS_COLOR, -1, curses.COLOR_BLUE)
curses.init_pair(SEC_ZERO_COLOR, -1, curses.COLOR_CYAN)

"""
XXX: parse and validating config file shoud be done before curses.wrapper.
Expand All @@ -812,19 +832,25 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--scale", type = int, default = 10,
help = "scale of ping RTT bar gap, default 10 (ms)")
parser.add_argument("-a", "--async-mode", action = "store_true",
async_group = parser.add_argument_group('asynchronously')
async_group.add_argument("-a", "--async-mode", action = "store_true",
help = "send ping asynchronously")
parser.add_argument("-b", "--blink-arrow", action = "store_true",
help = "blink arrow in async mode")
parser.add_argument("-l", "--logging", default = None, dest = "logdir",
help = "directory for log files")
parser.add_argument("configfile", type = argparse.FileType("r"),
help = "config file for deadman")
async_group.add_argument("-t", "--timeline", action = "store_true",
help = "display timeline every 10 seconds")

args = parser.parse_args()
RTT_SCALE = args.scale
BLINK_ARROW = args.blink_arrow
LOGDIR = args.logdir
TIMELINE = args.timeline
if TIMELINE:
args.async_mode = True

try:
curses.wrapper(main, args.configfile, args.async_mode)
Expand Down
0