diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-02-20 01:14:57 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-02 08:34:12 +0900 |
commit | d5911e2a10d55974da8466cc820beedd36785b63 (patch) | |
tree | d5e080f553c797eeae249f18e70a51534da6c145 | |
parent | a45bd1f290746c447dac1e127477c4b118691aa1 (diff) |
server: use raw data as downtime/uptime instead of duration
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | gobgp/cmd/neighbor.go | 23 | ||||
-rw-r--r-- | server/peer.go | 4 |
2 files changed, 14 insertions, 13 deletions
diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go index ab89c9e7..c8ac5696 100644 --- a/gobgp/cmd/neighbor.go +++ b/gobgp/cmd/neighbor.go @@ -27,6 +27,7 @@ import ( "net" "sort" "strings" + "time" ) func getNeighbors() (peers, error) { @@ -85,26 +86,26 @@ func showNeighbors() error { sort.Sort(m) + now := time.Now() for _, p := range m { if len(p.Conf.RemoteIp) > maxaddrlen { maxaddrlen = len(p.Conf.RemoteIp) } - if len(fmt.Sprint(p.Conf.RemoteAs)) > maxaslen { maxaslen = len(fmt.Sprint(p.Conf.RemoteAs)) } - var t string - if p.Timers.State.Uptime == 0 { - t = "never" - } else if p.Info.BgpState == "BGP_FSM_ESTABLISHED" { - t = formatTimedelta(int64(p.Timers.State.Uptime)) - } else { - t = formatTimedelta(int64(p.Timers.State.Downtime)) + timeStr := "never" + if p.Timers.State.Uptime != 0 { + t := int64(p.Timers.State.Downtime) + if p.Info.BgpState == "BGP_FSM_ESTABLISHED" { + t = int64(p.Timers.State.Uptime) + } + timeStr = formatTimedelta(int64(now.Sub(time.Unix(int64(t), 0)).Seconds())) } - if len(t) > maxtimelen { - maxtimelen = len(t) + if len(timeStr) > maxtimelen { + maxtimelen = len(timeStr) } - timedelta = append(timedelta, t) + timedelta = append(timedelta, timeStr) } var format string format = "%-" + fmt.Sprint(maxaddrlen) + "s" + " %" + fmt.Sprint(maxaslen) + "s" + " %" + fmt.Sprint(maxtimelen) + "s" diff --git a/server/peer.go b/server/peer.go index 07a1288b..da305894 100644 --- a/server/peer.go +++ b/server/peer.go @@ -303,11 +303,11 @@ func (peer *Peer) ToApiStruct() *api.Peer { uptime := int64(0) if timer.State.Uptime != 0 { - uptime = int64(time.Now().Sub(time.Unix(timer.State.Uptime, 0)).Seconds()) + uptime = timer.State.Uptime } downtime := int64(0) if timer.State.Downtime != 0 { - downtime = int64(time.Now().Sub(time.Unix(timer.State.Downtime, 0)).Seconds()) + downtime = timer.State.Downtime } timerconf := &api.TimersConfig{ |