Home Top Ad

How to monitor your Ubuntu 16.04 server with pyDash and Apache with mod_wsgi

Share:

Introduction


PyDash is a simple web based monitoring tool that can be installed on most Linux distributions. PyDash is written in Python and Django and it uses Chart.js to generate nice looking graphs to get an insight on your servers performance. PyDash has been tested in the following Linux distributions: CentOS, Fedora, Ubuntu, Debian, Arch Linux, Raspbian and Pidora.


PyDash can be used to monitor multiple aspects of your server like CPUs, RAM, network stats, online users and more. PyDash provides a simple to use dashboard that is easy to install and configure.


In this article, we will show you how to install pydash on a fresh Ubuntu 16.04.1 installation using Apache with mod_WSGI (Web Server Gateway Interface) HTTP Server.


For more info visit the PyDash Wiki


Install


Connect to your server via SSH.
ssh [email protected]

Always update your package sources so that you always have the latest versions of the packages that you may need to download or install.


sudo apt-get update

sudo apt-get upgrade

Now we will download and install all of the dependencies that PyDash requires


sudo apt-get install git python-pip apache2 libapache2-mod-wsgi

Now we will clone the project repository in the /var/www directory


cd /var/www

sudo git clone https://github.com/k3oni/pydash.git

Now we will generate a random key to add to the PyDash configuration file


date +%s | sha256sum | base64 | head -c 32 ; echo

Add the generated key to the configuration file


sudo nano pydash/pydash/settings.py

.............

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'YTdmNDMwYTdiMjU2ODM0ODRlZjNlZTg4'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

.............

Save and close the file by pressing CTRL + X and Y for Yes


Now we need to upgrade pip to the latest version


pip install --upgrade pip

Now we need to activate the installation and install the requirements using pip


cd pydash

sudo pip install -r requirements.txt

Now we will run the following Python script to create the project database and install the authentication system and create a project super user.


sudo ./manage.py syncdb

Fill the required fields



You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no):yes
Username (leave blank to use 'user'):username
Email address: [email protected]
Password:********
Password (again):********
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)


Now we grant correct permissions to the files


sudo chown -R www-data:www-data /var/www

Now we edit the Apache config file to match the one below


sudo nano /etc/apache2/sites-enabled/pydash.conf:

Here are the contents


  WSGISocketPrefix /var/run/apache2/wsgi
<VirtualHost *:8080>
ServerAdmin [email protected]
ServerName ubuntuboss.com

WSGIDaemonProcess pydash display-name=%{GROUP} python-path=/var/www/pydash
WSGIProcessGroup pydash
WSGIScriptAlias / /var/www/pydash/pydash/wsgi.py

Alias /static /var/www/pydash/static/
Alias /media /var/www/pydash/media/

<Directory /var/www/pydash/pydash>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

#CustomLog logs/pydash-access_log common
#ErrorLog logs/pydash-error_log
</VirtualHost>

Edit the Apache ports config and add line to listen on port 8080


# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80
Listen 8080
<IfModule ssl_module>
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Open the port that you would like to run the web server on the firewall using ufw, in mi case i chose port 8080 as you can see on the Apache config above


sudo ufw allow 8080/tcp

Now we will start the Apache web server:


 sudo service apache2 start

Testing the dashboard:


http://Server-IP:8080/


If the memory chart is not displaying, perform the following change, otherwise you are done.


sudo nano /var/www/pydash/main/views.py

Change free -tmo in the following line to free -tm


..........
def get_mem():
"""
Get memory usage
"""
try:
pipe = os.popen(
"free -tmo | " + "grep 'Mem' | " + "awk '{print $2,$4,$6,$7}'")
data = pipe.read().strip().split()
pipe.close()
..........

Should look like the function bellow


..........
def get_mem():
"""
Get memory usage
"""
try:
pipe = os.popen(
"free -tm | " + "grep 'Mem' | " + "awk '{print $2,$4,$6,$7}'")
data = pipe.read().strip().split()
pipe.close()
..........

Now we will restart the Apache web server:


 sudo service apache2 restart

Access the dashboard:


http://Server-IP:8080/


PyDash Dashboard