ManagedCloud Servers

High performance handled and monitored by us 24/7/365. A complete solution to provide you with our in house expertise 24/7 tailored to your specific needs. We'll setup a bespoke server for your site using the latest tehnologies so you can get the most out of your hardware and get your website loading quickly and reliably. Find out more..

cPanelCloud Servers

Recommended - High performance cloud servers with no technical knowledge required. If you're hosting multiple websites already and you're looking to consolidate, or if you're looking to isolate yourself from the shared hosting environment but you don't have the time or knoweldge to manage a server, then the Managed cPanel Servers are for you. Find out more..

UnmanagedCloud Servers

Our unmanaged range gives you complete control at rock bottom prices and our cloud platform boasts super fast multipath 40Gb/s network, the latest Intel Xeon V3 CPUs and enterprise grade redundant SSDs. If you're a sysadmin look no further, we offer some of the best specification to price ratio servers available. Find out more..

Want your very own server? Get our 1GB memory, Xeon V4, 20GB SSD VPS for £10.00 / month.

View Plans

Monitor Your CentOS 7 Server Using Monitorix

Monitorix is open source server monitoring software. It is very small and lightweight and is designed to monitor as many services and system resources as possible. Monitorix has been under development since 2005. The software mainly consists of two components, monitorix which is a data collector and starts automatically as system service, the other one is a cgi script called monitorix.cgi. It periodically collects the data and uses its in built web server to graphically display the data. Monitorix was originally developed for enterprise linux distributions, like RHEL, CentOS and Fedora but later it was also implemented in other Linux distributions. It was created for monitoring production Linux servers, but due to it's simplicity and small size, it can be used with embedded systems also. As it allows overall system monitoring it can help us detect the failures and other anomalies.

In this tutorial we will learn to install Monitorix on CentOS 7 system. We will also learn to configure the service to enable various features.

Requirements

Monitorix does not require any special hardware as it can be installed and used in very basic system. Although you will need root or sudo access to your system. If you are logged in as non root user, you can either execute sudo -i to switch to root account or you can use sudo command at the start of all the administrative command.

Installing Monitorix

Before installing any package, it is recommended to update the system and packages using the following command.

    yum -y update

There are two ways to install Monitorix, one is using the package available in EPEL repository, another one is using the RPM package available on Monitorix website. Both the methods of installing Monitorix are easy but it is recommended that you use RPM package available on Monitorix website as it will have the most updated version of the software available.

Installation Using the EPEL Repository

After updating the system we will need to add EPEL repository into our system as Monitorix is not available in the default repository of CentOS 7. To add the EPEL repository run the following commands.

    yum -y install epel-release
    yum -y update
    yum clean all

Now we can install Monitorix using the following command.

    yum -y install monitorix

That should install Monitorix on your server.

Installation Using an RPM Package

Before you can install the RPM package you will need to install the dependencies required. Some of the dependencies are only available on EPEL repository, hence you will need to install EPEL repository also.

    yum -y install epel-release
    yum -y update
    yum clean all

Now install the required dependencies, run the following command.

    yum install rrdtool rrdtool-perl perl-libwww-perl perl-MailTools perl-MIME-Lite perl-CGI perl-DBI perl-Config-General perl perl-HTTP-Server-Simple perl-IO-Socket-SSL perl-MIME-Lite perl-XML-Simple

Once the dependencies are installed, you can download the RPM package using the following command.

    wget http://www.monitorix.org/monitorix-3.9.0-1.noarch.rpm

If you do not have wget installed, you can run yum -y install wget to install the wget package. You can always check the Monitorix download page to check for the updated link.

Once you download the RPM package, install it using the following command.

    rpm -Uvh monitorix*.rpm

Once you have installed the software, you can start it using following command.

    systemctl start monitorix

To enable Monitorix to automatically start at boot time, run the following command.

    systemctl enable monitorix

You will get following output.

    [root@ip-172-31-11-153 ~]# systemctl enable monitorix
    monitorix.service is not a native service, redirecting to /sbin/chkconfig.
    Executing /sbin/chkconfig monitorix on

To check the status of the monitorix service, run the following command.

    systemctl status monitorix

You will see the status of the service, the output will look similar as shown.

    [root@ip-172-31-11-153 ~]# systemctl status monitorix
    ● monitorix.service - LSB: Start up the Monitorix daemon
       Loaded: loaded (/etc/rc.d/init.d/monitorix)
       Active: active (running) since Fri 2016-10-28 18:10:08 UTC; 14min ago
         Docs: man:systemd-sysv-generator(8)
      Process: 9739 ExecStop=/etc/rc.d/init.d/monitorix stop (code=exited, status=0/SUCCESS)
      Process: 9777 ExecStart=/etc/rc.d/init.d/monitorix start (code=exited, status=0/SUCCESS)
     Main PID: 9782 (/usr/bin/monito)
       CGroup: /system.slice/monitorix.service
               ├─9782 /usr/bin/monitorix -c /etc/monitorix/monitorix.conf -p /var...
               └─9833 monitorix-httpd listening on 8080

Oct 28 18:10:08 ip-172-31-11-153 systemd[1]: Starting LSB: Start up the Moni.... Oct 28 18:10:08 ip-172-31-11-153 monitorix[9777]: [37B blob data] Oct 28 18:10:08 ip-172-31-11-153 systemd[1]: Started LSB: Start up the Monit.... Hint: Some lines were ellipsized, use -l to show in full.

To check the version of the software, run the following command.

    monitorix -v

You will likely get following output.

    [root@ip-172-31-11-153 ~]# monitorix -v
    Monitorix version 3.9.0 (14-Oct-2016)
    by Jordi Sanfeliu 
    http://www.monitorix.org/

Configuring Monitorix

Monitorix is configured with a single plain text configuration file /etc/monitorix/monitorix.conf. We will need to make few changes in configuration file before using Monitorix. Before making changes to the configuration file, it is recommended that you take a backup of the file. So that you can restore it, if things break. Run the following command to take the backup of the file.

    cp /etc/monitorix/monitorix.conf /etc/monitorix/monitorix.conf.backup

Open the configuration file in your favorite text editor. In this tutorial we will use nano editor, if you don't have nano installed, you can run yum -y install nano.

    nano /etc/monitorix/monitorix.conf

In the configuration file change the basic settings available at the start of the file.

    # Monitorix - configuration file
    #
    # See monitorix.conf(5) manpage for a detailed description of each option.
    #

title = Place a title here hostname = theme_color = black refresh_rate = 150 iface_mode = graph enable_zoom = y netstats_in_bps = n disable_javascript_void = n temperature_scale = c show_gaps = n global_zoom = 1 max_historic_years = 1 accept_selfsigned_certs = y image_format = PNG

Provide a title of the application in title = replacing Place a title here. The title can be a description of the server; where it is located or the company name etc. Provide the hostname of your server in hostname = option. In the themes option you can choose either a black theme or white theme.

netstats_in_bps enables you to toggle the network speed shown in bits per second or bytes per second. The default value is bytes per seconds. You can set it to y to switch to bits per second. You can also choose the image format of graphs, either PNG or SVG.

After editing it should look like similar to shown below.

    title = My Server
    hostname = server1.example.com
    theme_color = white
    refresh_rate = 150
    iface_mode = graph
    enable_zoom = y
    netstats_in_bps = y
    disable_javascript_void = n
    temperature_scale = c
    show_gaps = n
    global_zoom = 1
    max_historic_years = 1
    accept_selfsigned_certs = y
    image_format = SVG

Next you will need to restrict the networks who can access the Monitorix built in http server. Scroll down to find these lines


enabled = y host = port = 8080 user = nobody group = nobody log_file = /var/log/monitorix-httpd hosts_deny = hosts_allow =

You can change the port number from 8080 to any free port in your server. Next change hosts_deny = to hosts_deny = all, this will restrict everybody to access the server except the IP address defined in hosts_allow =. Add the IP address or network range in hosts_allow =, from where the Monitorix web page will be accessible. If the IP address of your network is 192.168.0.0/24 then to allow this network, you can write hosts_allow = 192.168.0.0/24.

Once done, restart Monitorix using the following command.

    systemctl restart monitorix

Now you can access Monitorix by going to following link using your favorite browser.

    http://Server-IP-addr:8080/monitorix

You will see following screen.

Click the OK button and it will show you the graphs related to various services and resources into the system.

Enabling Basic Authentication

It is strongly recommended that you use basic authentication to secure Monitorix data from everyone. To use basic authentication find the following lines in the configuration file /etc/monitorix/monitorix.conf.


enabled = y host = port = 8080 user = nobody group = nobody log_file = /var/log/monitorix-httpd hosts_deny = hosts_allow =

enabled = n msg = Monitorix: Restricted access htpasswd = /var/lib/monitorix/htpasswd

Change enabled = n to enabled = y to enable basic authentication with password file. You can also remove the hosts_deny = and hosts_allow = with no values to allow access to the webpage to everyone. The page will still be protected with basic authentication. You can also modify the msg value to a more personalized text if you like. The message will be shown to the user in authentication dialog box.

Now you will need to initialize the password file. First of all you will need to install httpd-tools, which comes with a tool htpasswd which we will use to create an encrypted password file. Run the following command to install httpd-tools.

    yum -y install httpd-tools

Now use htpasswd tool to create a password file and add the user admin using the following command.

    htpasswd -d -c /var/lib/monitorix/htpasswd admin

The above command will create a new password file and will ask for the password twice and will add the user and the password into the file. You can use any username in place of admin.

    [root@ip-172-31-11-153 ~]# htpasswd -d -c /var/lib/monitorix/htpasswd admin
    New password:
    Re-type new password:
    Adding password for user admin

Once done restart the Monitorix service using the following command.

    systemctl restart monitorix

Now when you will try to access the graphs page, you will be greeted with a dialog box to provide the authentication details.

Once you provide correct login details you will be able to access the graphs.

Logs

Although Monitorix maintains separate logs for different services, the main log file of Monitorix can be found at /var/log/monitorix. You can periodically view the log file to find the errors and troubleshoot them. To view the last 10 log entries of the Monitorix log file, run the following command.

    tail /var/log/monitorix

You will see output similar to shown below.

    [root@ip-172-31-11-153 ~]# tail /var/log/monitorix
    Fri Oct 28 18:45:44 2016 - Exiting.
    Fri Oct 28 18:45:44 2016 - Starting Monitorix version 3.9.0 (pid 11478).
    Fri Oct 28 18:45:44 2016 - Loaded main configuration file '/etc/monitorix/monitorix.conf'.
    Fri Oct 28 18:45:44 2016 - Initializing graphs.
    Fri Oct 28 18:45:44 2016 - fs::fs_init: Unable to detect the device name of 'swap'. I/O stats for this filesystem won't be shown in graph. If this is really a mount point then consider using  to map it manually to a device name.
    Fri Oct 28 18:45:44 2016 - fs::fs_init: Unable to detect the device name of '/boot'. I/O stats for this filesystem won't be shown in graph. If this is really a mount point then consider using  to map it manually to a device name.
    Fri Oct 28 18:45:44 2016 - Generating the 'index.html' file.
    Fri Oct 28 18:45:44 2016 - Started built-in HTTP server (pid 11529).
    Fri Oct 28 18:45:44 2016 - Ok, ready.
    HTTPServer: You can connect to your server at http://localhost:8080/

Enabling or Disabling Graphs

By default only few graphs are enabled in Monitorix configuration. Also Monitorix does not collect the data of the service whose graph is not enabled. Below you can find the default list of graphs. You can also find the same in your default configuration file. To enable a specific graph, change the n to y, and restart the Monitorix service, it will automatically create the rrd file for the service and will start collecting and displaying the data for the service.

    # Graphs (de)activation
    # -----------------------------------------------------------------------------

system = y kern = y proc = y hptemp = n lmsens = n gensens = n nvidia = n disk = n fs = y zfs = n du = n net = y netstat = y tc = n libvirt = n process = n serv = y mail = n port = y user = y ftp = n apache = n nginx = n lighttpd = n mysql = n varnish = n pagespeed = n squid = n nfss = n nfsc = n bind = n ntp = n chrony = n fail2ban = n icecast = n raspberrypi = n phpapc = n memcached = n apcupsd = n nut = n wowza = n int = y verlihub = n

Conclusion

In this tutorial we have learned how to install Monitorix on CentOS 7 system. We also learnt howw to configure the software to enable various features like basic authentication, etc. You can now successfully deploy this open source lightweight tool to monitor your services and resources.

Want your very own server? Get our 1GB memory, Xeon V4, 20GB SSD VPS for £10.00 / month.

View Plans