grafana dashboard

Monitor Server with Prometheus and Grafana

Prometheus is used an open source software, that can collect metrics and alerting.

You can download latest version oof Prometheus from

https://prometheus.io/download/

Create a user

Download and Install prometheus

Create a service file

Add following content

Enable prometheus to start on boot

Start prometheus

Prometheus runs on port 9090, you can access promethus at

It will look like

Prometheus have some basic graphing features, but you can’t use it for monitoring. To create dash board and monitor, you need to use grafana.

Collecting Data

Node Exporter is used to collect data from servers. All monitored servers need Node Exporter installed.

Lets create a user for Node Exporter to run

Install Node Exporter

Create a systemd service file for node exporter

Add

Enable and start Node Exporter

Node Exporter run on port 9100 and expose system metrics on url

Node Exporter

Adding Servers to Prometheus

Once Node Exporter installed on a server, you need to tell Prometheus to get data from the Node Exporter you just installed. To do this, edit Prometheus configuration file.

Add following

To monitor multiple servers, you can dd more servers in targets line. Here is an example config

https://gist.github.com/serverok/83a622e7577da36384f87fe60c9930af/raw

Restart prometheus

Grafana

Grafana is used to visualise data collected by Prometheus. You can download Grafana from

https://grafana.com/grafana/download

Grafana offers free cloud hosted version with some limitation (1 user, 5 dashboards). Free version is suitable if you are getting started and don’t want to install your own. You can signup for cloud hosted version at

https://grafana.com/get

If you decide to install your own Grafana, you can run

Enable and start grafana

If you did your own install, grafana runs on port 3000. To access, use url

Default username and passwords are “admin”. Once logged in you will be asked to set password for grafana admin user.

Before you can use Grafana, you need to set a data source and create dash board. In our case, data source is prometheus. To connect Grafana to your Prometheus insallation, go to Settings > Data Sources

Grafana Data Sources

On next page, select Prometheus

Grafana Add data source

On next page, for URL, enter http://PROMETHUS_SERVER_IP:9090, scroll down, click on “Save & Test” button. If grafana can connect to your prometheus installation, you should see success message with “Data source is working”. If not, you need to check your firewall rules.

Creating Grafana Dashboards

Grafana displays data in dash boards. You can create your own or use pre existing dash boards. You can find pre-made dash boards at

https://grafana.com/grafana/dashboards

On my grafana installation, i used dashboard

https://grafana.com/grafana/dashboards/11074

To add this dash board to your Grafana, click on the + button, then select Import. On next screen, you can enter ID for the dash board you need to import. In this case 11074. Click “Load” button to import the dash board.

Here is a dash board for one of the server

grafana dashboard

You can edit Panels in grafana dash board to see how it is created. You can create a new dash board with panel you need. This way your dashboards only show required information.

Related Posts

Server Monitoring

PHP Script to monitor Apache/php-fpm

I moved a web site to new dedicated server. But for some reason, php-fpm crashed. I increased the max_children settings, but it happend again. I do not want down time while i am investigating the problem. So i created a PHP script, that will check if site is working or not.

Script have 2 part.

health-check.php

It is simple PHP script, that get a param and print it.

This file is placed on root of your web site, so it can be accessed using URL http://yoursite/health-check.php

monitor-server.php

Create

Add following content

On the script, replace YOUR_DOMAIN_HERE with your actual domain name.

systemctl restart apache2 is for restart apache web server. If you use nginx, replace it. systemctl restart php7.2-fpm restart php-fpm, if you have differnt version of php, you need to change it.

The script is generate a random number, pass it to health-check.php script. Compared the value returned with generated random number to make sure the value is correct. If web server or php-fpm fail, this check will fail.

Now set a cronjob

Add

Related Posts

Server Monitoring

ISPConfig LetsEncrypt Free SSL

Add SSL for ISPConfig Control Panel

To add SSL for ISPConfig control panel, add server hostname as a web site in ISPConfig and enable the LetsEnrypt checkbox. That will get SSL installed for your hostname. Make sure you verify hostname resolve to the ISPConfig server before doing this or SSL validation fail.

Once you have valid LetsEncrypt SSL certficate installed on your site, create file

Add following content

If you use nginx, replace apache2 on last line with nginx.

Now set a cronjob

Add

Now you should be able to access ISPConfig with url https://HOSTNAME:8080

Related Posts

ispconfig

Split Large file into smaller files

Today i was transfer a large 7 GB backp file into another server. Every time i copy it get disconnected after some time and i have to transfer again. When trasftering large file, it is better split it into smaller files, this way if one of the file trafer failed, you only need to trasfer this specific file again. With rsync, it make it easy as you can sync all files to remote server.

To split a large file into smaller parts, run

This command will split large file into smaller files with 500 MB size each. You can specify a differnt size if you need.

Once all files are on new server, you can combine it into one file with command

When you do cat *, make sure only split files are in current folder.

Related Posts

tar
rsync

ISPConfig

ISPConfig fail to create MySQL database

Whem creating MySQL database in ISPConfig, no database get created. To debug, i disabled the cronjob. Created a database in ISPConfig control panel, run cronjob manually, it shows following error

This is because ISPConfig can’t connect to MySQL server for creating new MySQL database. To fix, edit file /usr/local/ispconfig/server/lib/mysql_clientdb.conf

Update MySQL password for user root on this file. The content of the file look like

Related Posts

ISPConfig

ISPConfig

Install SSL for ISPConfig Control Panel

First find hostname for the server using command

Login to ISPConfig, add this web site. Get an SSL issued for this web site. Verify SSL works for this site.

Now create file

Add following content to the file

Excute the script

When you run first time, you may get missing file error, you can ignore it.

Set a cronjob

Related Posts

ISPconfig

VestaCP Free Hosting Control Panel

VestaCP SSL for mail server

VestaCP install self signed SSL for mail server by default. To install valid SSL, login to VestCP, go to sites. You will see a site with your sites hostname. If you don’t see it, create a site with your server hostname. Make sure DNS edited so hostname resolve to server IP. Now you should be able to get free LetsEncrypt SSL for this site.

if you check Apache Virtual Host for the site, you will see someting like

In VeataCP the config files for exim and dovecot located at

These configs use SSL located at /usr/local/vesta/ssl/certificate.crt and /usr/local/vesta/ssl/certificate.key.

To use the FREE SSL, create a bash script.

Add

make the file executable

Run the script

Now SSL will work for mail server and VestaCP. To access VestaCP, use

Verify Mail Server SSL

You can view mail server SSL with command

Replace HOSTNAME with actual hostname of your server.

Auto Renew SSL

LetsEncrypt SSL expire every 90 days. So we will create a cronjob to auto renew SSL. Ff you have a paid SSL, you don’t need this cronjob

Create a cronjob with

Add

Related Posts

VestaCP Free Hosting Control Panel

Disable Native Notification on Google Chrome Ubuntu

On Ubuntu, Google chrome had a disable native notification option. On Chrome 78, this option is removed. But you still can manually enable it.

To enbale chrome notification, edit file

Find

Replace with

Save and exit the file. Now restart google chrome.

Related Posts

Google Chrome