Skip to content

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

Merged
merged 43 commits into from
Apr 14, 2023

Conversation

mtojek
Copy link
Member

@mtojek mtojek commented Apr 13, 2023

Related: #6724

This PR exposes agent stats stored in the database via the Prometheus endpoint.

# HELP coderd_agentstats_connection_count The number of established connections by agent
# TYPE coderd_agentstats_connection_count gauge
coderd_agentstats_connection_count{agent_name="main",username="admin",workspace_name="workspace1"} 2
# HELP coderd_agentstats_connection_median_latency The median agent connection latency
# TYPE coderd_agentstats_connection_median_latency gauge
coderd_agentstats_connection_median_latency{agent_name="main",username="admin",workspace_name="workspace1"} 0.002476
# HELP coderd_agentstats_rx_bytes Agent Rx bytes
# TYPE coderd_agentstats_rx_bytes gauge
coderd_agentstats_rx_bytes{agent_name="main",username="admin",workspace_name="workspace1"} 7726
# HELP coderd_agentstats_session_count_jetbrains The number of session established by JetBrains
# TYPE coderd_agentstats_session_count_jetbrains gauge
coderd_agentstats_session_count_jetbrains{agent_name="main",username="admin",workspace_name="workspace1"} 0
# HELP coderd_agentstats_session_count_reconnecting_pty The number of session established by reconnecting PTY
# TYPE coderd_agentstats_session_count_reconnecting_pty gauge
coderd_agentstats_session_count_reconnecting_pty{agent_name="main",username="admin",workspace_name="workspace1"} 1
# HELP coderd_agentstats_session_count_ssh The number of session established by SSH
# TYPE coderd_agentstats_session_count_ssh gauge
coderd_agentstats_session_count_ssh{agent_name="main",username="admin",workspace_name="workspace1"} 0
# HELP coderd_agentstats_session_count_vscode The number of session established by VSCode
# TYPE coderd_agentstats_session_count_vscode gauge
coderd_agentstats_session_count_vscode{agent_name="main",username="admin",workspace_name="workspace1"} 0
# HELP coderd_agentstats_tx_bytes Agent Tx bytes
# TYPE coderd_agentstats_tx_bytes gauge
coderd_agentstats_tx_bytes{agent_name="main",username="admin",workspace_name="workspace1"} 6623

@mtojek mtojek self-assigned this Apr 13, 2023
@mtojek mtojek changed the title feat: expose agent stats over Prometheus API feat: expose agent stats via Prometheus API Apr 13, 2023
@mtojek mtojek changed the title feat: expose agent stats via Prometheus API feat: expose agent stats via Prometheus endpoint Apr 13, 2023
@mtojek mtojek requested a review from mafredri April 13, 2023 14:52
@mtojek mtojek requested a review from deansheather April 13, 2023 14:52
@mtojek mtojek marked this pull request as ready for review April 13, 2023 14:52
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Looks good, had a few comments and observations but nothing critical.


stat.Username = user.Username

workspace, err := q.GetWorkspaceByID(ctx, agentStat.WorkspaceID)
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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?

@mtojek
Copy link
Member Author

mtojek commented Apr 14, 2023

@mafredri I addressed your suggestions regarding cancellation vs. closing, but now the code is flaky. I'm not sure what is wrong here: https://github.com/coder/coder/actions/runs/4699908242/jobs/8333944515

Would you mind throwing an eye on the output? It looks like it complains about dbauthz.

@mtojek
Copy link
Member Author

mtojek commented Apr 14, 2023

Ok, it looks like it's fixed now 👍

@mtojek mtojek merged commit 942aba3 into coder:main Apr 14, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants