Longview is a system statistics graphing service by Linode. The statistics for CPU, memory, network, Disk I/O, MySQL, Apache and Nginx are collected by an agent program and are graphed in the Linode control panel. This service can also be used on servers that are not hosted on Linode. This article will show you how to setup Longview for monitoring a ServerPilot stack.
Add a Longview client
Login to the Linode manager, navigate to the Longview tab and click “Add Client”. The following popup appears:
Click go back and click the ‘i’ button:
Note down the API key, we’ll be using this in the next step.
Install Longview agent
We’re going to install Longview manually, so follow the instructions below to add the Longview APT repository.
sudo bash -c 'echo "deb http://apt-longview.linode.com/ trusty main" > /etc/apt/sources.list.d/longview.list' curl -s https://apt-longview.linode.com/linode.gpg | sudo apt-key add -
Create a directory for the Longview API and configuration files.
sudo mkdir /etc/linode sudo bash -c 'echo "<API KEY>" > /etc/linode/longview.key'
Install Longview:
sudo apt-get update sudo apt-get install linode-longview -y
Configure Apache
Create and edit the following file:
/etc/apache-sp/conf.d/status.conf
<IfModule mod_status.c> ExtendedStatus On <Location /server-status> <IfModule security2_module> SecRuleEngine Off </IfModule> <IfModule mod_rewrite.c> RewriteEngine Off </IfModule> SetHandler server-status Require ip 127.0.0.1 </Location> </IfModule>
The <IfModule security2_module>
block is not required if mod_security is not installed. Do a configuration test and restart Apache:
sudo /opt/sp/apache/bin/apachectl -t sudo service apache-sp restart
Access the Apache status URL using curl:
curl -v http://127.0.0.1:81/server-status?auto
This should display statistics on Apache processes, threads and workers.
Edit the Apache file in the Longview directory
sudo bash -c 'echo "location http://127.0.0.1:81/server-status?auto" > /etc/linode/longview.d/Apache.conf'
Restart the Longview service.
sudo service longview restart
Configure Nginx
Create a conf.d directory for Nginx:
sudo mkdir /etc/nginx-sp/conf.d/
Create the following file and paste the contents below it:
/etc/nginx-sp/conf.d/status.conf
server { listen 127.0.0.1:80; server_name 127.0.0.1; location /nginx_status { stub_status on; allow 127.0.0.1; deny all; } }
Do a configtest for Nginx and reload if there are no errors:
sudo service nginx-sp configtest sudo service nginx-sp reload
Test if the Nginx status URL displays connection information:
curl -v http://127.0.0.1/nginx_status
sudo bash -c 'echo "location http://127.0.0.1/nginx_status" > /etc/linode/longview.d/Nginx.conf'
Restart longview
sudo service longview restart
Wait for atleast 30 minutes for the Longview dashboard to be populated with statistics. No configuration is required for MySQL as the root password is saved in the /root/.my.cnf file. ServerPilot also comes configured with slow query logging so checkout Longview’s MySQL tab for this data.
Bradley says
Hi, when I tried install longview I get this error messages. ı was install serverpilot before longview :/
E: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
Jesin A says
Hi Bradley,
First restart your server and then try these commands, if they still don’t work execute the following and then try again.
Andy says
Thanks for this guide – super helpful!
Mathew says
I tried this, but for apache now I am getting the below error:
403 Forbidden (for the server-status)
Steve Mitchell says
Thanks for your clear guide and steps. Worked perfectly for me!
Sam says
Looking at this in February 2019. Are these instructions still all good to attempt?