Skip to content

Commit

Permalink
feat: uptime
Browse files Browse the repository at this point in the history
  • Loading branch information
jon4hz committed Jul 24, 2022
1 parent effbc9a commit 5129ef5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ go 1.17

require (
github.com/charmbracelet/lipgloss v0.4.0
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/lukesampson/figlet v0.0.0-20190211215653-8a3ef4a6ac42
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/shirou/gopsutil/v3 v3.21.12
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
)
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b h1:wDUNC2eKiL35DbLvsDhiblTUXHxcOPwQSCzi7xpQUN4=
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b/go.mod h1:VzxiSdG6j1pi7rwGm/xYI5RbtpBgM8sARDXlvEvxlu0=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
Expand All @@ -28,6 +30,8 @@ github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:Om
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil/v3 v3.21.12 h1:VoGxEW2hpmz0Vt3wUvHIl9fquzYLNpVpgNNB7pGJimA=
github.com/shirou/gopsutil/v3 v3.21.12/go.mod h1:BToYZVTlSVlfazpDDYFnsVZLaoRG+g8ufT6fPQLdJzA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
22 changes: 22 additions & 0 deletions internal/pipe/uptime/uptime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package uptime

import (
"time"

"github.com/hako/durafmt"
"github.com/jon4hz/gmotd/internal/context"
"github.com/shirou/gopsutil/host"
)

type Pipe struct{}

func (Pipe) String() string { return "uptime" }

func (Pipe) Message(c *context.Context) string {
t, err := host.BootTime()
if err != nil {
return ""
}
uptime := time.Since(time.Unix(int64(t), 0)).Round(time.Second)
return "Uptime: " + durafmt.Parse(uptime).LimitFirstN(2).String()
}
2 changes: 2 additions & 0 deletions internal/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/jon4hz/gmotd/internal/context"
"github.com/jon4hz/gmotd/internal/pipe/hostname"
"github.com/jon4hz/gmotd/internal/pipe/sysinfo"
"github.com/jon4hz/gmotd/internal/pipe/uptime"
)

type Pipe interface {
Expand All @@ -15,5 +16,6 @@ type Pipe interface {

var Pipeline = []Pipe{
hostname.Pipe{},
uptime.Pipe{},
sysinfo.Pipe{},
}

0 comments on commit 5129ef5

Please sign in to comment.