I want to know is there anyway to get CPU usage per user in MySQL? for example I have 3 different users 'user1', 'user2' and 'user3'. I want to get the average/real time memory usage and CPU usage of these users.I googled a lot but I did not find any suitable tool. Maybe I can get these data from MySQL queries, but I don't know where are they stored.
Mysql – How to get CPU usage in MySQL per user
cpumonitoringMySQL
Related Solutions
That's not really a PostgreSQL monitoring tool, that's PostgreSQL's internal facilities for diagnostics, monitoring and database statistics.
For host monitoring you want a tool like Icinga (modernized Nagios) or Zabbix. When monitoring PostgreSQL the check_postgres
tool is likely to be of interest.
If you're interested in getting the CPU use of a particular PostgreSQL backend process from your own custom programs, you must SELECT pg_backend_pid()
or get the pid of the task of interest from pg_stat_activity
then use OS-level tools and APIs to collect the desired information.
If you desired, you could write a PostgreSQL C extension function to collect the information and return it as a row or rowset over the PostgreSQL protocol, so you could SELECT my_system_stats()
. See:
Essentially, you write a library in C using the PostgreSQL APIs, compile it using the pgxs
make helper and have the server dynamically load the resulting shared object. Then you tell it what C functions are callable from SQL using CREATE FUNCTION
. You can then call them like any other function. C extensions can call OS-level APIs or do pretty much whatever they want, though it is generally very unwise for them to create threads, write directly to PostgreSQL files/filehandles, or read/write PostgreSQL sockets.
Looking at this my.cnf, InnoDB for MySQL 5.5 has more firepower you can configure.
I would add the following settings:
innodb_read_io_threads=64
innodb_write_io_threads=64
innodb_fast_shutdown=0
innodb_log_buffer_size=256M
innodb_log_file_size=512M
innodb_flush_method=O_DIRECT
query_cache_size=0
What are these for?
- innodb_read_io_threads and innodb_write_io_threads (both since MySQL 5.1.38) allocate the specified number of threads for reads and writes. Default is 4 and maximum is 64.
- innodb_fast_shutdown set to 0 completely purges transactional changes to disk. This also makes for a faster startup.
- innodb_log_file_size is 5MB by default in MySQL 5.5. I am merely suggesting they be much bigger. The documentation says : The size in bytes of each log file in a log group. The combined size of log files cannot exceed 3.99999999068677 GB which is equal to the 4294967295 range limit. A pair of 2047 MB log files, for example, would allow you to approach the range limit but not exceed it. The default value is 5MB. Sensible values range from 1MB to 1/N-th of the size of the buffer pool, where N is the number of log files in the group. The larger the value, the less checkpoint flush activity is needed in the buffer pool, saving disk I/O. But larger log files also mean that recovery is slower in case of a crash.
- innodb_flush_method tells InnoDB to bypass caching anything in the OS. All needed caching is done internally (within the InnoDB Architecture)
- query_cache_size is set to 128M. It shoudl be 0 because InnoDB checks the query cache very frequently. In fact, it's preferred that this be disabled for InnoDB (See my earlier post from Sep 05, 2012 : Is the overhead of frequent query cache invalidation ever worth it?)
- innodb_log_buffer_size set higher decreases Disk I/O.
You are probably running with default log files, so I would do this:
STEP 01 : Log in to mysql and run this:
mysql> SET GLOBAL innodb_fast_shutdown = 0;
STEP 02 : Shutdown MySQL
service mysql stop
STEP 03 : Rename InnoDB Log Files
cd /var/lib/mysql
mv ib_logfile0 ib_logfile0.bak
mv ib_logfile1 ib_logfile1.bak
STEP 04 : Startup MySQL
service mysql start
Extra time is needed to recreate the new ib_logfile0 and new ib_logfile1
This should increase InnoDB's overall performance in terms of CPU and Disk Usage
Give it a Try !!!
As a side point, here is what InnoDB looks like under the hood:
Best Answer
Some resource limitations: https://dev.mysql.com/doc/refman/5.6/en/user-resources.html and https://mariadb.com/kb/en/library/grant/#resource-limit-options
Switch to MariaDB to get "user stats" (connections, bytes, rows, CPU, etc): https://mariadb.com/kb/en/library/information-schema-user_statistics-table/ and https://mariadb.com/kb/en/library/user-statistics/