Home Server • Install Observium on ArchLinux

Install Observium on ArchLinux


Hamster-transparentRecently I’ve obtained an old 8-port switch from the office (a WWP LightningEdge 310). That switch has a management port for managing the switch via cli but also is capable of sending SNMP data so we can monitor the status of the switch in tools like Cacti or Observium. I’ve tried Cacti before and although it’s very mature and has a lot of functions it’s also a big puzzle to find out how it works with all of it’s templates and graphs. I’ve also tried Observium and this does the job perfectly. Since the installation of Observium is well documented for RedHat and Debian like systems and I only have ArchLinux based systems I’ve tried installing it on Arch, this post will therefore describe the process of installing and running Observium on a ArchLinux install.

Why Observium?
Observium is able to poll SNMP data like Cacti but it’s much more convenient in what it is able to show and graph. By default Cacti has some basic templates for traffic monitoring but it’s not very thorough. Observium is able to graph all SNMP data that is available for processing and does the work almost completely for you. In my case with the LE-310 switch it is able to show all interface statistics, optic status, system status etcetera as where Cacti was able to only monitor the first.

System requirements:
Observium has pretty high system requirements. Since I’m only monitoring 1 switch in this install I can imagine that the actual requirements would be much lower. My testing case was done on a very old HP machine (s7720.nl) with the following specs:

CPU: AMD X2 3800+ 2GHz dualcore
LAN: Realtek 8101CP 100Mbit
HDD: 1TB Seagate Constellation 7200RPM

As said, the machine is very old (almost 9 years). As it’s only used for testing purposes I found the machine handling Observium pretty well. The web pages are generated pretty fast with PHP7 and no Opcode caching. The only thing that was notably slower was the generation of the graphs which in this case is the CPU intensive part. It could take up to several seconds to load ~15 – ~20 graphs on a page, still okay for me. Should you want more speed you might want to consider a more modern machine with a newer CPU for processing the graph data.

Installing required software:
Before we can install Observium we need to install some packages that consist of a LAMP stack, some PHP modules and software that is needed so Observium can do it’s work properly. From the commandline/terminal elevate to root and install the required software:

pacman -Sy apache mariadb php php-apache php-mcrypt php-gd php-snmp net-snmp fping rrdtool whois mtr ipmitool graphviz imagemagick python-pip nmap

For the cron scripts to work we need to have pymysql installed as well:
pip3 install pymysql

Then go back to your normal user account and install the php-pear package, I’ve done this like (as root):
su jeffrey
yaourt- Sy php-pear

Configuring the installed software:
By default the Apache and MariaDB services are not started and have to be “enabled” so they start at boot and have to be “started” in order for them to work.

Enable the apache and MariaDB services:
systemctl enable httpd.service
systemctl enable mariadb.service

If you have just installed MariaDB and haven’t set it up before it’s best to do now to finish and secure your installation. To finish the installation run:
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

This will take a couple of seconds to finish and results in a working MariaDB server setup but with no password for the root account, start MariaDB and set it via:
systemctl start mariadb.service

The script makes most of the default choices for you, it’s best to keep them as suggested!

We haven’t started Apache yet as we have to change the default config as well and saves us a Apache restart. Open the main configuration file:
vim /etc/httpd/conf/httpd.conf

Locate the following line:
#LoadModule rewrite_module modules/mod_rewrite.so

And replace it with:
LoadModule rewrite_module modules/mod_rewrite.so

Next locate the following line:
LoadModule mpm_event_module modules/mod_mpm_event.so

Replace it with:
#LoadModule mpm_event_module modules/mod_mpm_event.so

And change the line underneath it from:
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

In that same LoadModule list add to the end of the list the following line so that PHP scripts work as well:
LoadModule php7_module modules/libphp7.so

Search in the file for Include and insert the following line underneath the last Include:
Include conf/extra/php7_module.conf

Later in the file there is a DocumentRoot section, within the Directory directive, replace everything with:
DirectoryIndex index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted

Change the DocumentRoot and Directory itself as well from:
DocumentRoot "/srv/http"

DocumentRoot "/srv/http/html"

Save the changes and exit the file.

Now we have to change some PHP settings as well, open the following file:
vim /etc/php/php.ini

Search for the following line:
extension_dir = "/usr/lib/php/modules/"

And add the following lines beneath it:

Save the changes and exit the file. Now let’s start Apache as well:
systemctl start httpd.service

Downloading Observium:
By default the docroot of Apache on ArchLinux is in /srv/http/. One thing that you must know is that Observium must run from within the docroot itself and will not run using a alias or subdirectory. This is because it’s programmed to always run from the docroot (and that is bad).

So first we navigate to the docroot directory:
cd /srv/http/

Download the latest Observium archive:
wget http://www.observium.org/observium-community-latest.tar.gz

And unpack it straight into the current docroot directory:
tar --strip-components=1 -vxzf observium-community-latest.tar.gz

Remove the downloaded installation archive:
rm -f observium-community-latest.tar.gz

Configuring Observium:
In order to use Observium we need to create a configfile with the database credentials and set up a database. First we will setup the database, so log in to MySQL as the root user with the password you’ve set earlier:
mysql -u root -p

Create a database, new database user and password:
mysql> CREATE DATABASE observium DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> GRANT ALL PRIVILEGES ON observium.* TO 'observium'@'localhost'

Exit MySQL and setup the config file:
cp config.php.default config.php
vim config.php

You have to change the following lines to what you have setup above with the MySQL database setup:
// Database config --- This MUST be configured
$config['db_extension'] = 'mysqli';
$config['db_host'] = 'localhost';
$config['db_user'] = 'USERNAME';
$config['db_pass'] = 'PASSWORD';
$config['db_name'] = 'observium';

You also need to change the Observium root directory from:
#$config['install_dir'] = "/opt/observium";

$config['install_dir'] = "/srv/http";

And save your changes. Now we are going to install the database schema, run the following:
./discovery.php -u

This will import the basic database schema into the Observium database. It may take up to a couple of minutes depending on the speed of the system, mostly disk related. The output is as shown below:
Install initial database schema ... done.
-- Updating database/file schema
252 -> 253 ... (db) done.
253 -> 254 ... (db) done.
254 -> 255 ... (db) done.
255 -> 256 ... (php)
256 -> 257 ... (php)
257 -> 258 ... (php)
258 -> 259 ... (db) done.
259 -> 260 ... (php)
260 -> 261 ... (db) done.
261 -> 262 ... (php)
262 -> 263 ... (db) done.
263 -> 264 ... (db) done.
264 -> 265 ... (db) done.
265 -> 266 ... (db) done.
-- Done.

We also need to create logging and RRD data directories:
mkdir /srv/http/rrd
mkdir /srv/http/logs
chmod 777 /srv/http/{rrd,logs}

The last step is to fix a issue with PEAR. Observium uses PEAR for several additional PHP modules, but looks for the PEAR.php file in it’s own pear directory which isn’t there. If you have the php-pear package installed before from yaourt you can solve this issue by copying the PEAR.php file from the pear directory over to the pear directory from Observium:
cp /usr/share/pear/PEAR.php /srv/http/libs/pear/

If you don’t copy the PEAR.php file you will not be able to add devices to your Observium install!

Creating a new user for Observium:
Before we can log in to the web interface of Observium we need to create a user for this purpose:
cd /srv/http/

Run the following command to create a user called “jeffrey” with a password “password” and admin rights “10”:
./adduser.php jeffrey password 10

Which should result in:
Observium CE
Add User

User jeffrey added successfully.

Logging in to the web interface of Observium:
In your browser you can navigate to the IP-address or hostname, this should result in the login screen of Observium like shown below:

When logged in you should be able to add hosts and devices. Do note that they cannot be added by IP-address and always have to be entered as hostnames. Should this be an issue you can use the local /etc/hosts file on your Observium machine of fix the hostnames your DHCP server hands out.

Automatic polling for Observium:
It’s possible to poll the data for Obserium automatically. For this we will use the cron mechanism from the system. As root, edit the current cron:
crontab -e

And add the following 3 lines:
33 */6 * * * /srv/http/discovery.php -h all > /dev/null 2>&1
*/5 * * * * /srv/http/discovery.php -h new > /dev/null 2>&1
*/5 * * * * /srv/http/poller-wrapper.py 2 > /dev/null 2>&1

Save the cron and from now on every 5 minutes the new SNMP data will be polled for the devices you have configured!

In Server

Author:Jeffrey Langerak

5 responses to “Install Observium on ArchLinux”

  • Brian Morisette 06-02-2017 at 01:32 Reply 

    Great guide, thanks for putting it together.

    I’m running into an issue with the poller however. I wasn’t sure what was going on at first as the poller-wrapper.php was running fine with no error, I just was getting an Error drawing my graphs.

    I found the issue in the graph error details, and then ran a manual./poller.php -h all
    I ran debug on specific devices and the error is between them, and there isn’t anything further of use supplied in the output.

    I double checked I had done everything correctly, everything else is working, adding devices, etc. It’s pulling all the data from the devices except for graphs, and the rrd dir has device dir created, but no data within indicating my path and permissions are working.

    So I’m wondering if this may be a bug. Running latest community version

    Error output from ./poller.php -h all -d:

    o Device status Device is reachable by PING (1.46ms) and SNMP (162.67ms)
    PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function rrdtool_update_ng(), 3 passed in /srv/http/includes/polling/funct ions.inc.php on line 566 and at least 4 expected in /srv/http/includes/rrdtool.inc.php:484
    Stack trace:
    #0 /srv/http/includes/polling/functions.inc.php(566): rrdtool_update_ng(Array, ‘status’, Array)
    #1 /srv/http/poller.php(170): poll_device(Array, Array)
    #2 {main}
    thrown in /srv/http/includes/rrdtool.inc.php on line 484

    Fatal error: Uncaught ArgumentCountError: Too few arguments to function rrdtool_update_ng(), 3 passed in /srv/http/includes/polling/functions. inc.php on line 566 and at least 4 expected in /srv/http/includes/rrdtool.inc.php:484
    Stack trace:
    #0 /srv/http/includes/polling/functions.inc.php(566): rrdtool_update_ng(Array, ‘status’, Array)
    #1 /srv/http/poller.php(170): poll_device(Array, Array)
    #2 {main}
    thrown in /srv/http/includes/rrdtool.inc.php on line 484

  • Brian 07-02-2017 at 17:35 Reply 

    The poller isn’t currently compatible with php 7.1. Graphs won’t work and poller will get fatal errors unless you downgrade to php 7.0. Arch looks to have moved to 7.1 in Jan 2017.
    Obvervium devs are aware and the next version of CE will work with php 7.1

    • langerak 10-02-2017 at 15:49 Reply 


      That may seem correct indeed. I shifted to LibreNMS a while ago as Observium itself seems to be developed at a very slow rate and new features don’t seem to come. LibreNMS works with PHP 7.1 without a hassle as I have it running on ArchLinux with PHP 7.1!

      Kind regards,

      Jeffrey Langerak

      • Brian 27-05-2017 at 20:17 Reply 

        Well I’ve now certainly run into issues with both the slow pace of Observium’s development, and running Arch with PHP 7.0. So much that I’ve been trying to convert over to LibreNMS, but keep running into issues.

        It’s been hard to adapt the Ubuntu and CentOS install instructions. I was pleased I successfully adapted the cron jobs to systemd timers for observium, but this has me stumped.

        Running the validate.php and it seem to be getting stuck on what I believe pear should be handling:

        raspi# ./validate.php
        PHP Warning: require(Net/IPv4.php): failed to open stream: No such file or directory in /opt/librenms/includes/init.php on line 37
        PHP Fatal error: require(): Failed opening required ‘Net/IPv4.php’ (include_path=’.:’) in /opt/librenms/includes/init.php on line 37

        Librenms doesn’t have a libs/ dir, so I had copied my PEAR.php to lib/pear instead. Though this was just a guess.

        Would you be able to point me int he right direction?

  • Brian 28-05-2017 at 06:58 Reply 

    Sorted, needed to add the pear dir to open_basedir in the php.ini file.

    open_basedir = “.:/usr/share/pear/”

Leave a Reply

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



This site uses Akismet to reduce spam. Learn how your comment data is processed.