mysqld_exporter icon indicating copy to clipboard operation
mysqld_exporter copied to clipboard

Feature request: CPU usage for mysqld process

Open perlun opened this issue 6 years ago • 6 comments

(Sorry if this is a borderline ML question; I searched briefly through the mailing list archives but couldn't find any thread directly related to this.)

Host operating system: output of uname -a

Linux some-server 4.15.0-62-generic #69-Ubuntu SMP Wed Sep 4 20:55:53 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

mysqld_exporter version: output of mysqld_exporter --version

mysqld_exporter, version 0.12.1 (branch: HEAD, revision: 48667bf7c3b438b5e93b259f3d17b70a7c9aff96)
  build user:       root@0b3e56a7bc0a
  build date:       20190729-12:35:58
  go version:       go1.12.7

MySQL server version

mysqld Ver 10.1.41-MariaDB-0ubuntu0.18.04.1 for debian-linux-gnu on x86_64 (Ubuntu 18.04)

mysqld_exporter command line flags

None. The DATA_SOURCE_NAME is set to exporter:<removed>@(localhost:3306)/

What did you expect to see?

CPU usage for the MySQL process.

What did you see instead?

Only CPU usage for the exporter process itself:

$ curl -s http://localhost:9104/metrics | grep cpu_seconds
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 2375.13

Details

Other exporters sometimes includes this figure (which is typically tms_utime+ tms_stime from the times system call). The JMX exporter has it, which is slightly different since it runs inside the same Java process. The Elasticsearch exporter also has it (elasticsearch_process_cpu_time_seconds_sum), which is interesting since it runs out-of-process; I guess ES provides a way for the exporter to determine the metrics.

The only thing I can see which is similar to this is the mysql_global_status_cpu_time, but interestingly enough it's always zero for me:

# HELP mysql_global_status_cpu_time Generic metric from SHOW GLOBAL STATUS.
# TYPE mysql_global_status_cpu_time untyped
mysql_global_status_cpu_time 0

Is the data available somewhere (and it's just me) or is this indeed something we do not support at the moment?

perlun avatar Sep 27 '19 10:09 perlun

This value is not zero for me. I'm using this version:

mysqld_exporter_build_info{branch="HEAD",goversion="go1.12.7",revision="48667bf7c3b438b5e93b259f3d17b70a7c9aff96",version="0.12.1"}

Here is the mysql_global_status_cpu_time metric:

# HELP mysql_global_status_cpu_time Generic metric from SHOW GLOBAL STATUS.
# TYPE mysql_global_status_cpu_time untyped
mysql_global_status_cpu_time 604.8426

The MariaDB version:

mysql_version_info{innodb_version="10.3.11",version="10.3.11-MariaDB-log",version_comment="MariaDB Server"}

CharlesJUDITH avatar Feb 15 '20 14:02 CharlesJUDITH

The best way to implement this is to look at how the bind_exporter does it. You pass the pid file to the exporter and it builds a process exporter for it. The only tricky part is sometimes mysql is wrapped in mysqld_safe, which obscures the real MySQL PID.

SuperQ avatar Feb 15 '20 15:02 SuperQ

I can't see the metrics mysql_global_status_cpu_time. Do I miss args when I running mysqld_exporter? I use mysqld_exporter version 0.13.0. MySQL Version is 5.7.28.

michael-liumh avatar Jun 04 '21 11:06 michael-liumh

I have encountered the same situation. I cannot see the mysql_global_status_cpu_time metric during the querying process.

version: image

StandardStudent avatar Jan 24 '24 09:01 StandardStudent

As you can see by the above thread, mysql_global_status_cpu_time does nothing. The way to support this is to add a PID monitor like I described above.

Or, for more complete monitoring, use cAdvisor to monitor the systemd unit CPU metrics by enabling DefaultCPUAccounting=yes.

SuperQ avatar Jan 24 '24 10:01 SuperQ

@SuperQ I actually want to privatize the collection of metrics for the hosted MySQL service. Do you have any good solutions for this?

StandardStudent avatar Jan 24 '24 11:01 StandardStudent