try rdns, add hostname column

This commit is contained in:
lemmi 2020-01-23 09:44:38 +01:00
parent bd7116fff4
commit a98c697632
1 changed files with 16 additions and 3 deletions

19
main.go
View File

@ -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 {
<thead>
<tr>
<th>Net</th>
<th>Hostname</th>
<th colspan="3">Downtime</th>
</tr>
<tr>
<th></th>
<th></th>
<th>Counts</th>
<th>rel</th>
@ -269,7 +281,7 @@ func render(w io.Writer, rs []route) error {
</tr>
</thead>
<tbody>
<tr><td colspan="4"><hr/></td></tr>
<tr><td colspan="5"><hr/></td></tr>
{{- $now := .Now -}}
{{- range .R }}
<tr class="
@ -277,6 +289,7 @@ func render(w io.Writer, rs []route) error {
{{- if .Noise $now }} noise{{end -}}
">
<td class="dst">{{.Dst}}</td>
<td class="hostname">{{with .Hostname}}<a href="//{{.}}" target="_blank">{{.}}</a>{{end}}</td>
<td class="counter">{{.Counter}}</td>
<td class="downtime">{{.Downtime $now | printf "%.3f%%"}}</td>
<td class="duration">{{.DurationUntilRounded $now}}</td>