Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions cmd/lk/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,70 @@ func getAgentStatus(ctx context.Context, cmd *cli.Command) error {
Rows(rows...)

fmt.Println(t)

// Display events if any exist
hasEvents := false
for _, agent := range res.Agents {
for _, deployment := range agent.AgentDeployments {
if len(deployment.Events) > 0 {
hasEvents = true
break
}
}
if hasEvents {
break
}
}

if hasEvents {
fmt.Println()
fmt.Println("Recent Events (last 30 minutes):")
fmt.Println()

for _, agent := range res.Agents {
for _, deployment := range agent.AgentDeployments {
if len(deployment.Events) == 0 {
continue
}

fmt.Printf("Agent: %s (Version: %s, Region: %s)\n", agent.AgentId, agent.Version, deployment.Region)
for _, event := range deployment.Events {
eventTypeName := getEventString(event.Type)
eventTime := event.Timestamp.AsTime()
timeAgo := formatTimeAgo(time.Since(eventTime))
fmt.Printf(" x%d, last seen %s: %s\n", event.Count, timeAgo, eventTypeName)
}
fmt.Println()
}
}
}

return nil
}

func formatTimeAgo(d time.Duration) string {
minutes := int(d.Minutes())
if minutes < 1 {
return "just now"
}
return fmt.Sprintf("%dm ago", minutes)
}

// formatEventType formats the AgentEventType enum to a human-readable string
func getEventString(eventType lkproto.AgentEventType) string {
switch eventType {
case lkproto.AgentEventType_AGENT_EVENT_TYPE_APPLICATION_CRASHED:
return "Agent crashed due to an uncaught exception in the agent code. Please check the agent logs for more details."
case lkproto.AgentEventType_AGENT_EVENT_TYPE_RESTARTED_HIGH_MEMORY_USAGE:
return "Agent restarted due to high memory usage. Please check whether the agent is properly configured."
case lkproto.AgentEventType_AGENT_EVENT_TYPE_RESTARTED_HIGH_DISK_USAGE:
return "Agent restarted due to high disk usage. Please check whether the agent is downloading large files or storing large files to disk."
default:
// Fallback to string representation if unknown
return strings.TrimPrefix(strings.ReplaceAll(eventType.String(), "_", " "), "AGENT EVENT TYPE ")
}
}

func restartAgent(ctx context.Context, cmd *cli.Command) error {
agentID, err := getAgentID(ctx, cmd, workingDir, tomlFilename, false)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ require (
github.com/lithammer/shortuuid/v4 v4.2.0 // indirect
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 // indirect
github.com/livekit/mediatransportutil v0.0.0-20250922175932-f537f0880397 // indirect
github.com/livekit/psrpc v0.7.1-0.20251105165826-1016ad610a7e // indirect
github.com/livekit/psrpc v0.7.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magefile/mage v1.15.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
Expand Down Expand Up @@ -201,3 +201,5 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
mvdan.cc/sh/v3 v3.12.0 // indirect
)

replace github.com/livekit/protocol => ../protocol
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to revert before merging.

6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,8 @@ github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 h1:9x+U2HGLrSw5AT
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
github.com/livekit/mediatransportutil v0.0.0-20250922175932-f537f0880397 h1:Z7j2mY+bvG05UC80MpnJkitlJju8sSDWsr0Bb4dPceo=
github.com/livekit/mediatransportutil v0.0.0-20250922175932-f537f0880397/go.mod h1:mSNtYzSf6iY9xM3UX42VEI+STHvMgHmrYzEHPcdhB8A=
github.com/livekit/protocol v1.43.1-0.20251112192040-8bdcb749c402 h1:mMIddIE1wlvgwIDYZ48M4eptU4dzA2DqzWzeT7OTkcY=
github.com/livekit/protocol v1.43.1-0.20251112192040-8bdcb749c402/go.mod h1:TpqU2qCI1ES4Lk7PAWSgYO4RaexfVXb54ZO2hXv0Bmc=
github.com/livekit/psrpc v0.7.1-0.20251105165826-1016ad610a7e h1:K6GKMFGJW8U2RoEyi8Zar7pPwUB7RMsn3AEJXf/Mgfc=
github.com/livekit/psrpc v0.7.1-0.20251105165826-1016ad610a7e/go.mod h1:bZ4iHFQptTkbPnB0LasvRNu/OBYXEu1NA6O5BMFo9kk=
github.com/livekit/psrpc v0.7.1 h1:ms37az0QTD3UXIWuUC5D/SkmKOlRMVRsI261eBWu/Vw=
github.com/livekit/psrpc v0.7.1/go.mod h1:bZ4iHFQptTkbPnB0LasvRNu/OBYXEu1NA6O5BMFo9kk=
github.com/livekit/server-sdk-go/v2 v2.12.9-0.20251112193538-ed23dded48f9 h1:NjL66OFpkQJMhdvi0WCGWaPUr6XE1JGQwyKpNXWj4hg=
github.com/livekit/server-sdk-go/v2 v2.12.9-0.20251112193538-ed23dded48f9/go.mod h1:YGjcmx4bSoEWGFqd1nqfVw8a+KQuOHXpr/prKtWRZaQ=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
Expand Down
Loading