26Aug
longview_mysql_stats

How To Enable Longview Metrics for MySQL in Linode Servers

Linode is a very popular Virtual Private Servers (VPS) provider, that offer simplified interfaces to create and manage your servers. This post discusses one of their features: Longview, and how you can utilize it if you’re running MySQL Databases on your VPS.

Longview allows you to collect many metrics on your server in good details. It is also a free service that you get with your subscription – although you can upgrade it for unlimited data retention and more granular metric data. Using Longview, you can monitor stuff like CPU, Memory, Network Utilization and other resources. What we want to do is utilize it to display metrics of our MySQL Database.

The added value of this is that using Longview, you will be able to know what your database is doing (CRUD, Number of Connections, etc). However, I faced issues with enabling it on one node that has cPanel installed, too. What turned out to be the issue is that cPanel is using some custom perl modules that aren’t compatible with what’s in Centos default repos. To overcome this, perform the following:

Add a new client under your Longview tab in Linode dashboard. It should give you something similar to this to perform from the server:

# curl -s https://lv.linode.com/AE29B14B-ADAB-E682-DA3FE68829210D | sudo bash

This will download and install a custom Longview client for your server, as well as start collecting metrics which should display on Longview Dashboard in a few minutes. After that, go to the MySQL tab under your Longview client. You’re likely to see the following error:

Unable to connect to the database, no credentials found.

That’s normal as Longview doesn’t yet have credentials to access your DB metrics. Create an account for Longview in your database using the following:

# mysql -u root -p
Enter password:

Then, create an account using:

mysql> CREATE USER 'linode-longview'@'localhost' IDENTIFIED BY '******';

Replace stars with your desired password, and then:

mysql> flush privileges;

So far so good. Now, edit the following file to append the newly created account in it:

# vim /etc/linode/longview.d/MySQL.conf

Add the following two lines:

username linode-longview
password ***************

Save the file and restart the Longview service:

# service longview restart

Check the service status:

# service longview status

By this point we will have either of the two following states:

longview (pid 12345) is running...

Meaning that everything is good to go! You should be seeing MySQL metrics by now. The other case is:

longview dead but pid file exists

This one means that the service wasn’t able to start normally. Let’s check the logs:

# tail -10 /var/log/linode/longview.log

In my case, the following was the issue:

07/20 06:15:08 WARN Longview[6130] - install_driver(mysql) failed: Can't load '/usr/lib64/perl5/auto/DBD/mysql/mysql.so' for module DBD::mysql: libmysqlclient.so.16: cannot open shared object file: No such file or directory at /usr/lib64/perl5/DynaLoader.pm line 200.
at (eval 447) line 3
Compilation failed in require at (eval 447) line 3.
Perhaps a required shared library or dll isn't installed where expected
at /opt/linode/longview/Linode/Longview/DataGetter/Applications/MySQL.pm line 69

As mentioned earlier, due to cPanel using custom perl modules, we will have to apply the following workaround to get what we need:

# perl -MCPAN -e shell
cpan> force install DBD::mysql
cpan>exit

Let’s restart longview again:

# service longview restart
# service longview status
longview (pid 12365) is running...

Awesome! You can now get your DB metrics from Linode Longview dashboard.

Share this Story

2 comments

  1. Good site you’ve got here.. It’s hard to find excellent writing like yours these days.
    I honestly appreciate people like you! Take care!!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Written with love ♥