Skip to content

Commit

Permalink
docs: update example to have custom metrics
Browse files Browse the repository at this point in the history
closes #30
  • Loading branch information
caarlos0 committed Jan 11, 2024
1 parent ba901cc commit b31c9c2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions _examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@ import (
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
bm "github.com/charmbracelet/wish/bubbletea"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var keyTypeCounter = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "wish_auth_by_type_total",
Help: "Custom metric example",
}, []string{"type"})

func main() {
s, err := wish.NewServer(
wish.WithAddress("localhost:2223"),
wish.WithPublicKeyAuth(func(ssh.Context, ssh.PublicKey) bool { return true }),
wish.WithMiddleware(
bm.Middleware(func(s ssh.Session) (tea.Model, []tea.ProgramOption) {
keyTypeCounter.WithLabelValues(s.PublicKey().Type()).Inc()
pty, _, active := s.Pty()
if !active {
fmt.Println("no active terminal, skipping")
Expand Down

0 comments on commit b31c9c2

Please sign in to comment.