diff --git a/main.go b/main.go index 5bd83f2..565cf69 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,7 @@ type route struct { UnreachableDuration time.Duration UnreachableSince time.Time ReachableSince time.Time + Hostname string } func (r route) DurationUntilRounded(t time.Time) time.Duration { @@ -98,6 +99,15 @@ func (rs *routeStats) add(rm rtnetlink.RouteMessage) { r := rs.stats[key] if r == nil { r = &route{Dst: dst} + go func(r *route, rs *routeStats) { + names, err := net.LookupAddr(r.Dst.IP.String()) + if err != nil || len(names) == 0 { + return + } + rs.Lock() + r.Hostname = strings.TrimRight(names[0], ".") + rs.Unlock() + }(r, rs) } r.Counter++ @@ -226,7 +236,7 @@ func render(w io.Writer, rs []route) error { padding: 0.1em 2em; font-family: monospace; } - .dst { + .dst, .hostname { text-align: left; } .unreachable { @@ -236,7 +246,7 @@ func render(w io.Writer, rs []route) error { table tr.noise { display: none; } - tbody tr:hover { + tbody tr:nth-child(n+2):hover { background-color: silver; } #showAll:checked ~ table tr.noise { @@ -259,9 +269,11 @@ func render(w io.Writer, rs []route) error { Net + Hostname Downtime + Counts rel @@ -269,7 +281,7 @@ func render(w io.Writer, rs []route) error { -
+
{{- $now := .Now -}} {{- range .R }} {{.Dst}} + {{with .Hostname}}{{.}}{{end}} {{.Counter}} {{.Downtime $now | printf "%.3f%%"}} {{.DurationUntilRounded $now}}