Skip to content

Commit c656d09

Browse files
rezaxdMuhammad Reza Khani
authored and
Muhammad Reza Khani
committed
feat: add usename to pg_process_idle metric
Signed-off-by: rezaxd <r324r11@gmail.com>
1 parent 68c176b commit c656d09

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

collector/pg_process_idle.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch
5252
SELECT
5353
state,
5454
application_name,
55+
usename,
5556
SUM(EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - state_change))::bigint)::float AS process_idle_seconds_sum,
5657
COUNT(*) AS process_idle_seconds_count
5758
FROM pg_stat_activity
5859
WHERE state ~ '^idle'
59-
GROUP BY state, application_name
60+
GROUP BY state, application_name, usename
6061
),
6162
buckets AS (
6263
SELECT
@@ -78,12 +79,13 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch
7879
SELECT
7980
state,
8081
application_name,
82+
usename,
8183
process_idle_seconds_sum as seconds_sum,
8284
process_idle_seconds_count as seconds_count,
8385
ARRAY_AGG(le) AS seconds,
8486
ARRAY_AGG(bucket) AS seconds_bucket
8587
FROM metrics JOIN buckets USING (state, application_name)
86-
GROUP BY 1, 2, 3, 4;`)
88+
GROUP BY 1, 2, 3, 4, 5;`)
8789

8890
var state sql.NullString
8991
var applicationName sql.NullString

0 commit comments

Comments
 (0)