mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
feat: add connection statistics for workspace agents (#6469)
* fix: don't make session counts cumulative This made for some weird tracking... we want the point-in-time number of counts! * Add databasefake query for getting agent stats * Add deployment stats endpoint * The query... works?!? * Fix aggregation query * Select from multiple tables instead * Fix continuous stats * Increase period of stat refreshes * Add workspace counts to deployment stats * fmt * Add a slight bit of responsiveness * Fix template version editor overflow * Add refresh button * Fix font family on button * Fix latest stat being reported * Revert agent conn stats * Fix linting error * Fix tests * Fix gen * Fix migrations * Block on sending stat updates * Add test fixtures * Fix response structure * make gen
This commit is contained in:
@@ -330,3 +330,65 @@ WHERE
|
||||
-- During build time, the template max TTL will still be used if the
|
||||
-- workspace TTL is NULL.
|
||||
AND ttl IS NOT NULL;
|
||||
|
||||
-- name: GetDeploymentWorkspaceStats :one
|
||||
WITH workspaces_with_jobs AS (
|
||||
SELECT
|
||||
latest_build.* FROM workspaces
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT
|
||||
workspace_builds.transition,
|
||||
provisioner_jobs.id AS provisioner_job_id,
|
||||
provisioner_jobs.started_at,
|
||||
provisioner_jobs.updated_at,
|
||||
provisioner_jobs.canceled_at,
|
||||
provisioner_jobs.completed_at,
|
||||
provisioner_jobs.error
|
||||
FROM
|
||||
workspace_builds
|
||||
LEFT JOIN
|
||||
provisioner_jobs
|
||||
ON
|
||||
provisioner_jobs.id = workspace_builds.job_id
|
||||
WHERE
|
||||
workspace_builds.workspace_id = workspaces.id
|
||||
ORDER BY
|
||||
build_number DESC
|
||||
LIMIT
|
||||
1
|
||||
) latest_build ON TRUE
|
||||
), pending_workspaces AS (
|
||||
SELECT COUNT(*) AS count FROM workspaces_with_jobs WHERE
|
||||
started_at IS NULL
|
||||
), building_workspaces AS (
|
||||
SELECT COUNT(*) AS count FROM workspaces_with_jobs WHERE
|
||||
started_at IS NOT NULL AND
|
||||
canceled_at IS NULL AND
|
||||
updated_at - INTERVAL '30 seconds' < NOW() AND
|
||||
completed_at IS NULL
|
||||
), running_workspaces AS (
|
||||
SELECT COUNT(*) AS count FROM workspaces_with_jobs WHERE
|
||||
completed_at IS NOT NULL AND
|
||||
canceled_at IS NULL AND
|
||||
error IS NULL AND
|
||||
transition = 'start'::workspace_transition
|
||||
), failed_workspaces AS (
|
||||
SELECT COUNT(*) AS count FROM workspaces_with_jobs WHERE
|
||||
(canceled_at IS NOT NULL AND
|
||||
error IS NOT NULL) OR
|
||||
(completed_at IS NOT NULL AND
|
||||
error IS NOT NULL)
|
||||
), stopped_workspaces AS (
|
||||
SELECT COUNT(*) AS count FROM workspaces_with_jobs WHERE
|
||||
completed_at IS NOT NULL AND
|
||||
canceled_at IS NULL AND
|
||||
error IS NULL AND
|
||||
transition = 'stop'::workspace_transition
|
||||
)
|
||||
SELECT
|
||||
pending_workspaces.count AS pending_workspaces,
|
||||
building_workspaces.count AS building_workspaces,
|
||||
running_workspaces.count AS running_workspaces,
|
||||
failed_workspaces.count AS failed_workspaces,
|
||||
stopped_workspaces.count AS stopped_workspaces
|
||||
FROM pending_workspaces, building_workspaces, running_workspaces, failed_workspaces, stopped_workspaces;
|
||||
|
||||
Reference in New Issue
Block a user