Introduces a new command-line tool for managing mc-proxy via the gRPC admin API over Unix socket. Commands include route and firewall rule CRUD operations, health checks, and status queries. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
43 lines
1013 B
Go
43 lines
1013 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func statusCmd() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "status",
|
|
Short: "Show server status",
|
|
Long: "Show server status including version, uptime, and listener information.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client := clientFromContext(cmd.Context())
|
|
|
|
ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
|
|
defer cancel()
|
|
|
|
status, err := client.GetStatus(ctx)
|
|
if err != nil {
|
|
return fmt.Errorf("getting status: %w", err)
|
|
}
|
|
|
|
fmt.Printf("mc-proxy %s\n", status.Version)
|
|
if !status.StartedAt.IsZero() {
|
|
uptime := time.Since(status.StartedAt).Truncate(time.Second)
|
|
fmt.Printf("uptime: %s\n", uptime)
|
|
}
|
|
fmt.Printf("connections: %d\n", status.TotalConnections)
|
|
fmt.Println()
|
|
|
|
for _, ls := range status.Listeners {
|
|
fmt.Printf(" %s routes=%d active=%d\n", ls.Addr, ls.RouteCount, ls.ActiveConnections)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
}
|