### Configure and Start Confettysh SSH Server (Go) Source: https://context7.com/charmbracelet/confettysh/llms.txt This Go code sets up and starts the Confettysh SSH server. It configures listening addresses, ports for SSH and metrics, and defines endpoints for 'Confetti' and 'Fireworks' effects using the Wish framework and Bubbletea middleware. Prometheus metrics are integrated for monitoring. ```go package main import ( "fmt" "log" "net" "runtime/debug" "strconv" "strings" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/promwish" "github.com/charmbracelet/ssh" "github.com/charmbracelet/wish" "github.com/charmbracelet/wish/activeterm" bm "github.com/charmbracelet/wish/bubbletea" lm "github.com/charmbracelet/wish/logging" "github.com/charmbracelet/wishlist" "github.com/maaslalani/confetty/confetti" "github.com/maaslalani/confetty/fireworks" "github.com/prometheus/client_golang/prometheus" "github.com/spf13/pflag" ) var ( listen = pflag.String("listen", "localhost", "address to listen to") port = pflag.Int("port", 2222, "port to listen on") metricsPort = pflag.Int("metrics-port", 9222, "port to listen on") ) func main() { pflag.Parse() version := "devel" if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" { version = info.Main.Version } log.Printf("Running confettysh %s", version) // Start Prometheus metrics server go promwish.Listen(net.JoinHostPort(*listen, strconv.Itoa(*metricsPort))) cfg := &wishlist.Config{ Listen: *listen, Port: int64(*port), Factory: func(e wishlist.Endpoint) (*ssh.Server, error) { return wish.NewServer( wish.WithAddress(e.Address), wish.WithHostKeyPath(fmt.Sprintf(".ssh/%s", strings.ToLower(e.Name))), wish.WithMiddleware( append( e.Middlewares, promwish.MiddlewareRegistry( prometheus.DefaultRegisterer, prometheus.Labels{"app": e.Name}, promwish.DefaultCommandFn, ), lm.Middleware(), activeterm.Middleware(), )... ), ) }, Endpoints: []*wishlist.Endpoint{ { Name: "Confetti", Middlewares: []wish.Middleware{ bm.Middleware(teaHandler("confetti")), }, }, { Name: "Fireworks", Middlewares: []wish.Middleware{ bm.Middleware(teaHandler("fireworks")), }, }, }, } if err := wishlist.Serve(cfg); err != nil { log.Fatalln(err) } } ``` -------------------------------- ### Run confettysh locally Source: https://github.com/charmbracelet/confettysh/blob/main/README.md This command executes the confettysh application on the local machine, likely to start a server or display local effects. ```sh confettysh ``` -------------------------------- ### Prometheus Metrics Integration for Confettysh Source: https://context7.com/charmbracelet/confettysh/llms.txt Shows how to integrate Prometheus metrics using the promwish middleware. This Go code starts a metrics server and configures the middleware with application-specific labels. ```go import ( "github.com/charmbracelet/promwish" "github.com/prometheus/client_golang/prometheus" ) // Metrics server starts in a goroutine go promwish.Listen(net.JoinHostPort("localhost", "9222")) // Middleware configuration with per-endpoint labels promwish.MiddlewareRegistry( prometheus.DefaultRegisterer, prometheus.Labels{ "app": "Confetti", // or "Fireworks" }, promwish.DefaultCommandFn, ) ``` -------------------------------- ### Query Prometheus Metrics Endpoint Source: https://context7.com/charmbracelet/confettysh/llms.txt Demonstrates how to query the Prometheus metrics endpoint using curl and shows examples of the expected output, including SSH-specific metrics. ```bash # Query metrics endpoint curl http://localhost:9222/metrics # Expected output includes SSH-specific metrics: # ssh_session_total{app="Confetti"} 42 # ssh_session_duration_seconds{app="Confetti"} 123.45 # ssh_command_total{app="Confetti",command="confetti"} 42 ``` -------------------------------- ### Connect to confettysh server via SSH Source: https://github.com/charmbracelet/confettysh/blob/main/README.md These commands demonstrate how to connect to a confettysh server running on localhost via SSH. It includes examples for a custom port and for triggering specific effects like 'confetti' or 'fireworks'. ```sh ssh -p2222 localhost ssh -p2222 localhost -t confetti ssh -p2222 localhost -t fireworks ``` -------------------------------- ### Build and Run Confettysh Docker Image (Dockerfile) Source: https://context7.com/charmbracelet/confettysh/llms.txt This Dockerfile uses a minimal 'scratch' base image to create a small container for the Confettysh application. It copies the compiled binary into the image and sets it as the entrypoint, enabling containerized deployment. ```dockerfile FROM scratch COPY confettysh /usr/local/bin/confettysh ENTRYPOINT [ "confettysh" ] ``` -------------------------------- ### Run Confettysh Container with Docker Source: https://context7.com/charmbracelet/confettysh/llms.txt Demonstrates how to run the Confettysh container with default and custom port mappings. These commands are essential for deploying and accessing the Confettysh service. ```bash docker run -p 2222:2222 -p 9222:9222 confettysh ``` ```bash docker run -p 3333:3333 -p 9090:9090 confettysh --listen 0.0.0.0 --port 3333 --metrics-port 9090 ``` -------------------------------- ### Create Bubbletea Model for Terminal Effects (Go) Source: https://context7.com/charmbracelet/confettysh/llms.txt This Go function, `teaHandler`, generates a Bubbletea model for terminal animations. It returns a closure that initializes either a 'confetti' or 'fireworks' model based on the effect string, suitable for use with the Wish SSH middleware. It defaults to confetti if an unknown effect is requested. ```go const ( effectConfetti = "confetti" effectFireworks = "fireworks" ) func teaHandler(effect string) func(s ssh.Session) (tea.Model, []tea.ProgramOption) { return func(_ ssh.Session) (tea.Model, []tea.ProgramOption) { var m tea.Model switch effect { case effectConfetti: m = confetti.InitialModel() case effectFireworks: m = fireworks.InitialModel() default: // Falls back to confetti if unknown effect m = confetti.InitialModel() } return m, []tea.ProgramOption{tea.WithAltScreen()} } } ``` -------------------------------- ### Connect to Confettysh Server via SSH Source: https://context7.com/charmbracelet/confettysh/llms.txt Provides the SSH command to connect to a running Confettysh server. This command assumes the server is accessible on localhost with the default port. ```bash ssh -p2222 localhost -t confetti ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.