Skip to content

Commit

Permalink
feat: add usename to pg_process_idle metric
Browse files Browse the repository at this point in the history
Signed-off-by: rezaxd <[email protected]>
  • Loading branch information
rezaxd authored and Muhammad Reza Khani committed Nov 11, 2023
1 parent 68c176b commit 883e7b0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions collector/pg_process_idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch
SELECT
state,
application_name,
usename,
SUM(EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - state_change))::bigint)::float AS process_idle_seconds_sum,
COUNT(*) AS process_idle_seconds_count
FROM pg_stat_activity
WHERE state ~ '^idle'
GROUP BY state, application_name
GROUP BY state, application_name, usename
),
buckets AS (
SELECT
Expand All @@ -78,12 +79,13 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch
SELECT
state,
application_name,
usename,
process_idle_seconds_sum as seconds_sum,
process_idle_seconds_count as seconds_count,
ARRAY_AGG(le) AS seconds,
ARRAY_AGG(bucket) AS seconds_bucket
FROM metrics JOIN buckets USING (state, application_name)
GROUP BY 1, 2, 3, 4;`)
GROUP BY 1, 2, 3, 4, 5;`)

var state sql.NullString
var applicationName sql.NullString
Expand Down

0 comments on commit 883e7b0

Please sign in to comment.