Skip to content
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

Rewrite processlist collector #603

Merged
merged 3 commits into from
Jan 5, 2022
Merged

Conversation

roman-vynar
Copy link
Contributor

@roman-vynar roman-vynar commented Dec 2, 2021

Hello,

Rewritten processlist collector to include both Command and State columns and stop doing state remapping.

Couple of reasons for this:

  • The existing collector has been last updated 3 years ago when we had no MySQL 8.0. Since that time we have got more process states and changes to the existing ones https://dev.mysql.com/doc/refman/8.0/en/general-thread-states.html
    The old re-mapping is not accurate, somewhat outdated and requires constant maintaining. With this PR, we won't bother about thread state mapping and it will flexible for anyone to do what they want to do on the expression side.
  • The existing collector does incorrect grouping by Command/State. For example, anything Command=Query is considered as State=executing which may include:
{command="query", state="checking_permissions"}
{command="query", state="executing"}
{command="query", state="reading_event_from_the_relay_log"}
{command="query", state="sending_to_client"}
{command="query", state="slave_has_read_all_relay_log_waiting_for_more_updates"}
{command="query", state="waiting_for_global_read_lock"}
{command="query", state="waiting_for_handler_commit"}

As you can see it is not always an execution phase of regular queries but a whole bunch of stuff that we may want to exclude for alerting and which is the normal thing, for say Group Replication waiting_for_handler_commit (it is a phase of group commit where it is waiting and not consuming CPU) as opposite to the user queries (consuming CPU).
It becomes very handy when we want to sum all queries and exclude some particular states, or just see on the graph how those state are distributed to decide what to do.

  • There are other commands like "Connect", "Daemon", "Binlog dump" which we may want to see w/o being grouped/remapped into some states.

Breaking changes:

  • Added "command" label to processlist "threads" and "seconds" metrics. No much increase in number of time-series.
  • Stop doing remapping of the existing states. Just simple text normalization for command/state values.
  • Metrics has been renamed to be easily found by name of the collector and for consistency that they belong to the same one:
mysql_info_schema_threads > mysql_info_schema_processlist_threads
mysql_info_schema_threads_seconds > mysql_info_schema_processlist_seconds
mysql_info_schema_processes_by_user > mysql_info_schema_processlist_processes_by_user
mysql_info_schema_processes_by_host > mysql_info_schema_processlist_processes_by_host

Also added a test.

There is a similar PR #442 but it just adds "command" and retains the state remapping.
Another PR #381 complaining about remapping.

Sample output:

# TYPE mysql_info_schema_processlist_processes_by_host gauge
mysql_info_schema_processlist_processes_by_host{client_host="10.0.7.154"} 8
mysql_info_schema_processlist_processes_by_host{client_host="10.0.7.224"} 1
mysql_info_schema_processlist_processes_by_host{client_host="10.0.7.234"} 24
mysql_info_schema_processlist_processes_by_host{client_host="blank"} 2
mysql_info_schema_processlist_processes_by_host{client_host="localhost"} 1
# HELP mysql_info_schema_processlist_processes_by_user The number of processes by user.
# TYPE mysql_info_schema_processlist_processes_by_user gauge
mysql_info_schema_processlist_processes_by_user{mysql_user="manager"} 20
mysql_info_schema_processlist_processes_by_user{mysql_user="store"} 1
mysql_info_schema_processlist_processes_by_user{mysql_user="event_scheduler"} 1
mysql_info_schema_processlist_processes_by_user{mysql_user="feedback"} 1
mysql_info_schema_processlist_processes_by_user{mysql_user="message"} 4
mysql_info_schema_processlist_processes_by_user{mysql_user="root"} 1
mysql_info_schema_processlist_processes_by_user{mysql_user="system user"} 2
# HELP mysql_info_schema_processlist_threads The number of threads split by current state.
# TYPE mysql_info_schema_processlist_threads gauge
mysql_info_schema_processlist_threads{command="connect",state="waiting_for_handler_commit"} 1
mysql_info_schema_processlist_threads{command="daemon",state="waiting_on_empty_queue"} 1
mysql_info_schema_processlist_threads{command="query",state="slave_has_read_all_relay_log_waiting_for_more_updates"} 1
mysql_info_schema_processlist_threads{command="sleep",state="blank"} 36
# HELP mysql_info_schema_processlist_seconds The number of seconds threads have used split by current state.
# TYPE mysql_info_schema_processlist_seconds gauge
mysql_info_schema_processlist_seconds{command="connect",state="waiting_for_handler_commit"} 7.339619e+06
mysql_info_schema_processlist_seconds{command="daemon",state="waiting_on_empty_queue"} 7.339619e+06
mysql_info_schema_processlist_seconds{command="query",state="slave_has_read_all_relay_log_waiting_for_more_updates"} 7.339619e+06
mysql_info_schema_processlist_seconds{command="sleep",state="blank"} 1030

@roman-vynar roman-vynar force-pushed the processlist-new branch 2 times, most recently from 6f4c12b to a5a6dc0 Compare December 2, 2021 10:45
@SuperQ SuperQ self-requested a review December 2, 2021 11:20
@SuperQ
Copy link
Member

SuperQ commented Dec 2, 2021

Thanks!

One question, this drops the ORDER BY null, I seem to remember this was a small performance optimization. Possibly for a very old version of MySQL.

@roman-vynar
Copy link
Contributor Author

Yea, looks like it's from some very old MySQL. Normally, it shouldn't do anything useful but being present :)

Signed-off-by: Roman Vynar <roman.vynar@quiq.com>
collector/info_schema_processlist.go Outdated Show resolved Hide resolved
collector/info_schema_processlist_test.go Show resolved Hide resolved
collector/info_schema_processlist_test.go Outdated Show resolved Hide resolved
Signed-off-by: Roman Vynar <roman.vynar@quiq.com>
@SuperQ
Copy link
Member

SuperQ commented Dec 5, 2021

Looks like there are some unrelated mixin errors.

Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

There are some issues with the metric names.

collector/info_schema_processlist.go Outdated Show resolved Hide resolved
collector/info_schema_processlist.go Outdated Show resolved Hide resolved
Signed-off-by: Roman Vynar <roman.vynar@quiq.com>
@roman-vynar
Copy link
Contributor Author

You are right. I corrected the names and the description about breaking changes on the first post.

Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!

@SuperQ SuperQ merged commit 3c5f433 into prometheus:main Jan 5, 2022
SuperQ added a commit that referenced this pull request Jan 5, 2022
BREAKING CHANGES:

Metric names in the info_schema.processlist collector have been changed. #603
Metric names in the info_schema.replica_host collector have been changed. #496

* [CHANGE] Rewrite processlist collector #603
* [FEATURE] Add collector for `replica_host_status` #496
* [ENHANCEMENT] Expose dates as timestamps grom GLOBAL STATUS #561
* [BUGFIX] Fix mysql_slave_hosts_info for mysql 5.5 and mariadb 10.5 #577
* [BUGFIX] Fix logging issues #562 #602

Signed-off-by: SuperQ <superq@gmail.com>
@SuperQ SuperQ mentioned this pull request Jan 5, 2022
SuperQ added a commit that referenced this pull request Mar 3, 2022
BREAKING CHANGES:

Metric names in the info_schema.processlist collector have been changed. #603
Metric names in the info_schema.replica_host collector have been changed. #496

* [CHANGE] Rewrite processlist collector #603
* [FEATURE] Add collector for `replica_host_status` #496
* [ENHANCEMENT] Expose dates as timestamps grom GLOBAL STATUS #561
* [BUGFIX] Fix mysql_slave_hosts_info for mysql 5.5 and mariadb 10.5 #577
* [BUGFIX] Fix logging issues #562 #602

Signed-off-by: SuperQ <superq@gmail.com>
SuperQ added a commit that referenced this pull request Mar 3, 2022
BREAKING CHANGES:

Metric names in the info_schema.processlist collector have been changed. #603
Metric names in the info_schema.replica_host collector have been changed. #496

* [CHANGE] Rewrite processlist collector #603
* [FEATURE] Add collector for `replica_host_status` #496
* [ENHANCEMENT] Expose dates as timestamps grom GLOBAL STATUS #561
* [BUGFIX] Fix mysql_slave_hosts_info for mysql 5.5 and mariadb 10.5 #577
* [BUGFIX] Fix logging issues #562 #602

Signed-off-by: SuperQ <superq@gmail.com>
SuperQ added a commit that referenced this pull request Mar 3, 2022
BREAKING CHANGES:

Metric names in the info_schema.processlist collector have been changed. #603
Metric names in the info_schema.replica_host collector have been changed. #496

* [CHANGE] Rewrite processlist collector #603
* [FEATURE] Add collector for `replica_host_status` #496
* [ENHANCEMENT] Expose dates as timestamps grom GLOBAL STATUS #561
* [BUGFIX] Fix mysql_slave_hosts_info for mysql 5.5 and mariadb 10.5 #577
* [BUGFIX] Fix logging issues #562 #602

Signed-off-by: SuperQ <superq@gmail.com>
SuperQ added a commit that referenced this pull request Mar 4, 2022
BREAKING CHANGES:

Metric names in the info_schema.processlist collector have been changed. #603
Metric names in the info_schema.replica_host collector have been changed. #496

* [CHANGE] Rewrite processlist collector #603
* [FEATURE] Add collector for `replica_host_status` #496
* [ENHANCEMENT] Expose dates as timestamps grom GLOBAL STATUS #561
* [BUGFIX] Fix mysql_slave_hosts_info for mysql 5.5 and mariadb 10.5 #577
* [BUGFIX] Fix logging issues #562 #602

Signed-off-by: SuperQ <superq@gmail.com>
@maxemann96
Copy link

IvoGoman added a commit to sapcc/helm-charts that referenced this pull request Sep 7, 2023
mysql_info_schema_threads_seconds > mysql_info_schema_processlist_seconds
see prometheus/mysqld_exporter#603
IvoGoman added a commit to sapcc/helm-charts that referenced this pull request Sep 7, 2023
fix(mariadb): rename metric in alert

mysql_info_schema_threads_seconds > mysql_info_schema_processlist_seconds
see prometheus/mysqld_exporter#603
IvoGoman added a commit to sapcc/helm-charts that referenced this pull request Sep 18, 2023
fix(mariadb): rename metric in alert

mysql_info_schema_threads_seconds > mysql_info_schema_processlist_seconds
see prometheus/mysqld_exporter#603
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants