Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: collect database metrics#17635

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
dannykopping merged 5 commits intomainfromdk/db-metrics
May 2, 2025
Merged

feat: collect database metrics#17635

dannykopping merged 5 commits intomainfromdk/db-metrics
May 2, 2025

Conversation

dannykopping
Copy link
Contributor

Currently we don't have a way to get insight into Postgres connections being exhausted.

By using the prometheus'DBStats collector, we get some insight out-of-the-box.

# HELP go_sql_idle_connections The number of idle connections.# TYPE go_sql_idle_connections gaugego_sql_idle_connections{db_name="coder"} 1# HELP go_sql_in_use_connections The number of connections currently in use.# TYPE go_sql_in_use_connections gaugego_sql_in_use_connections{db_name="coder"} 2# HELP go_sql_max_idle_closed_total The total number of connections closed due to SetMaxIdleConns.# TYPE go_sql_max_idle_closed_total countergo_sql_max_idle_closed_total{db_name="coder"} 112# HELP go_sql_max_idle_time_closed_total The total number of connections closed due to SetConnMaxIdleTime.# TYPE go_sql_max_idle_time_closed_total countergo_sql_max_idle_time_closed_total{db_name="coder"} 0# HELP go_sql_max_lifetime_closed_total The total number of connections closed due to SetConnMaxLifetime.# TYPE go_sql_max_lifetime_closed_total countergo_sql_max_lifetime_closed_total{db_name="coder"} 0# HELP go_sql_max_open_connections Maximum number of open connections to the database.# TYPE go_sql_max_open_connections gaugego_sql_max_open_connections{db_name="coder"} 10# HELP go_sql_open_connections The number of established connections both in use and idle.# TYPE go_sql_open_connections gaugego_sql_open_connections{db_name="coder"} 3# HELP go_sql_wait_count_total The total number of connections waited for.# TYPE go_sql_wait_count_total countergo_sql_wait_count_total{db_name="coder"} 28# HELP go_sql_wait_duration_seconds_total The total time blocked waiting for a new connection.# TYPE go_sql_wait_duration_seconds_total countergo_sql_wait_duration_seconds_total{db_name="coder"} 0.086936235

go_sql_wait_count_total is the metric I'm most interested in gaining, but the others are also very useful.

Changing the prefix is easy (prometheus.WrapRegistererWithPrefix), but getting rid of thego_ segment is not quite so easy. I've kept the changeset small for now.

NOTE: I imported a library to determine the database name from the given conn string. It'snot as simple as one might hope. The database name is used for thedb_name label.

Signed-off-by: Danny Kopping <dannykopping@gmail.com>
@dannykoppingdannykopping changed the titlefeat: use go's sqldatabase metricsfeat: collect database metricsMay 1, 2025
Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

This should probably be done instead inenablePrometheus().
I don't see a point registering the collector if prometheus is not enabled for the deployment.

Signed-off-by: Danny Kopping <dannykopping@gmail.com>
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
@dannykoppingdannykopping merged commitc278662 intomainMay 2, 2025
29 checks passed
@dannykoppingdannykopping deleted the dk/db-metrics branchMay 2, 2025 10:17
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsMay 2, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

@spikecurtisspikecurtisAwaiting requested review from spikecurtis

Assignees

@dannykoppingdannykopping

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@dannykopping@johnstcn@spikecurtis

[8]ページ先頭

©2009-2025 Movatter.jp