-
Notifications
You must be signed in to change notification settings - Fork 891
feat: expose agent stats via Prometheus endpoint #7115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8d4e67d
da729e6
9ad09b2
440657c
8764f89
663b5d5
63aff5e
3905481
f8d6f46
d487a77
7acbaf0
7418779
3a8e4e6
b5d0581
e4d708b
199e549
7307bd3
d0b8398
f0c0418
970d35a
229f546
7070e0e
8c6f96b
1ed37b4
7ee1bfc
2b8a9e4
322f7e8
c7af75a
9693fa8
28f7a13
7878167
d9e4903
0d37c85
f752c6f
9c7aef8
5290571
1cbe59b
f8f11eb
4ffae11
7ba16b5
2a4c674
201da83
ba52c45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3998,6 +3998,77 @@ func (q *fakeQuerier) GetWorkspaceAgentStats(_ context.Context, createdAfter tim | |
return stats, nil | ||
} | ||
|
||
func (q *fakeQuerier) GetWorkspaceAgentStatsAndLabels(ctx context.Context, createdAfter time.Time) ([]database.GetWorkspaceAgentStatsAndLabelsRow, error) { | ||
q.mutex.RLock() | ||
defer q.mutex.RUnlock() | ||
|
||
agentStatsCreatedAfter := make([]database.WorkspaceAgentStat, 0) | ||
latestAgentStats := map[uuid.UUID]database.WorkspaceAgentStat{} | ||
|
||
for _, agentStat := range q.workspaceAgentStats { | ||
if agentStat.CreatedAt.After(createdAfter) { | ||
agentStatsCreatedAfter = append(agentStatsCreatedAfter, agentStat) | ||
latestAgentStats[agentStat.AgentID] = agentStat | ||
} | ||
} | ||
|
||
statByAgent := map[uuid.UUID]database.GetWorkspaceAgentStatsAndLabelsRow{} | ||
|
||
// Session and connection metrics | ||
for _, agentStat := range latestAgentStats { | ||
stat := statByAgent[agentStat.AgentID] | ||
stat.SessionCountVSCode += agentStat.SessionCountVSCode | ||
stat.SessionCountJetBrains += agentStat.SessionCountJetBrains | ||
stat.SessionCountReconnectingPTY += agentStat.SessionCountReconnectingPTY | ||
stat.SessionCountSSH += agentStat.SessionCountSSH | ||
stat.ConnectionCount += agentStat.ConnectionCount | ||
if agentStat.ConnectionMedianLatencyMS >= 0 && stat.ConnectionMedianLatencyMS < agentStat.ConnectionMedianLatencyMS { | ||
stat.ConnectionMedianLatencyMS = agentStat.ConnectionMedianLatencyMS | ||
} | ||
statByAgent[agentStat.AgentID] = stat | ||
} | ||
|
||
// Tx, Rx metrics | ||
for _, agentStat := range agentStatsCreatedAfter { | ||
stat := statByAgent[agentStat.AgentID] | ||
stat.RxBytes += agentStat.RxBytes | ||
stat.TxBytes += agentStat.TxBytes | ||
statByAgent[agentStat.AgentID] = stat | ||
} | ||
|
||
// Labels | ||
for _, agentStat := range agentStatsCreatedAfter { | ||
stat := statByAgent[agentStat.AgentID] | ||
|
||
user, err := q.getUserByIDNoLock(agentStat.UserID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
stat.Username = user.Username | ||
|
||
workspace, err := q.GetWorkspaceByID(ctx, agentStat.WorkspaceID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These can be called whilst holding mutex? Wondering since the above call is to a nolock method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is RWMutex, and we're using here only RLocks, so I guess that is's safe? |
||
if err != nil { | ||
return nil, err | ||
} | ||
stat.WorkspaceName = workspace.Name | ||
|
||
agent, err := q.GetWorkspaceAgentByID(ctx, agentStat.AgentID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
stat.AgentName = agent.Name | ||
|
||
statByAgent[agentStat.AgentID] = stat | ||
} | ||
|
||
stats := make([]database.GetWorkspaceAgentStatsAndLabelsRow, 0, len(statByAgent)) | ||
for _, agent := range statByAgent { | ||
stats = append(stats, agent) | ||
} | ||
return stats, nil | ||
} | ||
|
||
func (q *fakeQuerier) GetWorkspacesEligibleForAutoStartStop(ctx context.Context, now time.Time) ([]database.Workspace, error) { | ||
q.mutex.RLock() | ||
defer q.mutex.RUnlock() | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.