监视mysql上使用的连接以调试“太多连接”

时间:2022-10-15 20:00:34

On LAMP production server I get the 'too many connections' error from MYSQL occasionally, I want to add monitoring to find if the reason is that I exceed the max-connections limit.

在LAMP生产服务器上,我偶尔会从MYSQL中得到“太多连接”的错误,我希望添加监视,以发现我是否超出了max-connections的限制。

My question: How can I query from mysql or from mysqladmin the current number of used connections? (I noticed that show status gives total connections and not the currently used ones.)

我的问题是:如何从mysql或mysqladmin查询当前使用的连接数量?(我注意到显示状态显示的是总连接,而不是当前使用的连接。)

5 个解决方案

#1


15  

A very powerful tool to monitor MySQL is innotop. You can find it here:

innotop是一个非常强大的MySQL监控工具。你可以在这里找到:

https://github.com/innotop/innotop

https://github.com/innotop/innotop

In Debian Lenny, it is part of the package mysql-client-5.0 and I guess it is available for other distros as well. It is especially powerful in monitoring InnoDB internals, but provides general monitoring of the server as well.

在Debian Lenny中,它是mysql-client-5.0软件包的一部分,我想它也适用于其他发行版。它在监视InnoDB内部构件方面特别强大,但也提供对服务器的一般监视。

In "Variables & Status" mode, it monitors the variables "Connections" and "Max_used_Connections" (among others). It displays absolute and incremental values - the latter might give you an idea about the current connections.

在“变量&状态”模式中,它监视变量“连接”和“Max_used_Connections”(以及其他)。它显示绝对值和增量值——后者可能会让您了解当前连接。

Since innotop provides a non-interactive mode, you can easily build fully automated monitoring by calling innotop from some customized scripts, nagios checks or whatever system you have.

由于innotop提供非交互式模式,您可以通过从一些定制脚本、nagios检查或任何系统调用innotop来轻松构建完全自动化的监视。

#2


3  

http://www.mail-archive.com/monit-general@nongnu.org/msg00830.html

http://www.mail-archive.com/monit-general@nongnu.org/msg00830.html

Take a look here mate - may be of some use.

看一看这里,伙计——可能有一些用处。

#3


2  

SHOW STATUS doesn't display total connections: it displays current connections. You get the too many connections error message when the number of open connections (idle or not) surpases the limit established for the server.

显示状态不显示总连接:它显示当前连接。当打开的连接(空闲或不空闲)的数量超过了为服务器建立的限制时,您将获得过多的连接错误消息。

From your comment about SHOW STATUS, I looks like you have many idle connections in your server. That points to misuse of persistent connections; some libraries that claim to support persistent connections do not handle them properly and they tend to open new connections even when there're idle connections available.

从您对SHOW STATUS的评论来看,您的服务器中似乎有许多空闲连接。这指出了对持久连接的误用;一些声称支持持久连接的库不能正确地处理它们,并且即使有空闲连接,它们也会打开新的连接。

Find out what application is running such queries and configure it not to use persistent connections.

找出正在运行此类查询的应用程序,并将其配置为不使用持久连接。

#4


2  

To get total number of concurrent connections allowed by MySQL you should check

要获得MySQL允许的并发连接总数,您应该检查

show variables like 'max_connections'

显示变量如max_connections的

and how many concurrent connections are being used currently can be measured by

目前正在使用的并发连接有多少可以用。

show status like 'max_used_connections'

显示状态像“max_used_connections”

You should monitor these variables. If you need a commercial tool which monitors important MySQL metrics you can try MySQL Enterprise Monitor, MONyog etc..

您应该监视这些变量。如果您需要一个商业工具来监视重要的MySQL度量,您可以尝试MySQL企业监视器、MONyog等。

#5


1  

It might be easier for you to obtain the MySQL Admin, from that, you can easily monitor where the used connections are coming from. See here on this about the connections used...

您可能更容易获得MySQL Admin,您可以轻松地监视所使用的连接的来源。关于使用的连接,请参见这里。

#1


15  

A very powerful tool to monitor MySQL is innotop. You can find it here:

innotop是一个非常强大的MySQL监控工具。你可以在这里找到:

https://github.com/innotop/innotop

https://github.com/innotop/innotop

In Debian Lenny, it is part of the package mysql-client-5.0 and I guess it is available for other distros as well. It is especially powerful in monitoring InnoDB internals, but provides general monitoring of the server as well.

在Debian Lenny中,它是mysql-client-5.0软件包的一部分,我想它也适用于其他发行版。它在监视InnoDB内部构件方面特别强大,但也提供对服务器的一般监视。

In "Variables & Status" mode, it monitors the variables "Connections" and "Max_used_Connections" (among others). It displays absolute and incremental values - the latter might give you an idea about the current connections.

在“变量&状态”模式中,它监视变量“连接”和“Max_used_Connections”(以及其他)。它显示绝对值和增量值——后者可能会让您了解当前连接。

Since innotop provides a non-interactive mode, you can easily build fully automated monitoring by calling innotop from some customized scripts, nagios checks or whatever system you have.

由于innotop提供非交互式模式,您可以通过从一些定制脚本、nagios检查或任何系统调用innotop来轻松构建完全自动化的监视。

#2


3  

http://www.mail-archive.com/monit-general@nongnu.org/msg00830.html

http://www.mail-archive.com/monit-general@nongnu.org/msg00830.html

Take a look here mate - may be of some use.

看一看这里,伙计——可能有一些用处。

#3


2  

SHOW STATUS doesn't display total connections: it displays current connections. You get the too many connections error message when the number of open connections (idle or not) surpases the limit established for the server.

显示状态不显示总连接:它显示当前连接。当打开的连接(空闲或不空闲)的数量超过了为服务器建立的限制时,您将获得过多的连接错误消息。

From your comment about SHOW STATUS, I looks like you have many idle connections in your server. That points to misuse of persistent connections; some libraries that claim to support persistent connections do not handle them properly and they tend to open new connections even when there're idle connections available.

从您对SHOW STATUS的评论来看,您的服务器中似乎有许多空闲连接。这指出了对持久连接的误用;一些声称支持持久连接的库不能正确地处理它们,并且即使有空闲连接,它们也会打开新的连接。

Find out what application is running such queries and configure it not to use persistent connections.

找出正在运行此类查询的应用程序,并将其配置为不使用持久连接。

#4


2  

To get total number of concurrent connections allowed by MySQL you should check

要获得MySQL允许的并发连接总数,您应该检查

show variables like 'max_connections'

显示变量如max_connections的

and how many concurrent connections are being used currently can be measured by

目前正在使用的并发连接有多少可以用。

show status like 'max_used_connections'

显示状态像“max_used_connections”

You should monitor these variables. If you need a commercial tool which monitors important MySQL metrics you can try MySQL Enterprise Monitor, MONyog etc..

您应该监视这些变量。如果您需要一个商业工具来监视重要的MySQL度量,您可以尝试MySQL企业监视器、MONyog等。

#5


1  

It might be easier for you to obtain the MySQL Admin, from that, you can easily monitor where the used connections are coming from. See here on this about the connections used...

您可能更容易获得MySQL Admin,您可以轻松地监视所使用的连接的来源。关于使用的连接,请参见这里。