📜 ⬆️ ⬇️

Installing the Carbon + Graphite + Grafana + Nginx + MySQL bundle to collect and display metrics in Ubuntu

I want to share the experience of installing and configuring a service for collecting and displaying Graphite + Grafana .
I searched for a long time, I read a lot, I found 2 articles in English, I added my own, this article turned out as a result.


A little background ..


Graphite is a system for displaying metrics (numeric values) for any server or home PC properties.


Carbon is a daemon / backend in which metrics are written.


Grafana - more beautiful and convenient Web-muzzle for Graphite .


And so, let's get started.


Install and configure Php + Nginx + MySQL


Install Php + Nginx + MySQL


It's all pretty simple.


 sudo apt install php5-fpm php5-json php5-mysql sudo apt install nginx nginx-extras sudo apt install mysql-server 

During installation, you will be prompted for a password for the MySQL root .


Install phpMyAdmin


For more convenient access to MySQL install phpMyAdmin .


Download the latest version from here.


 cd /usr/share/ sudo wget https://files.phpmyadmin.net/phpMyAdmin/4.6.2/phpMyAdmin-4.6.2-all-languages.zip sudo unzip phpMyAdmin-4.6.2-all-languages.zip sudo rm phpMyAdmin-4.6.2-all-languages.zip sudo mv phpMyAdmin-4.6.2-all-languages phpmyadmin 

Configuring Nginx for phpMyAdmin


In the settings file /etc/nginx/conf.d/pma.conf we write the following:


 server { server_name pma.your.site; listen 80; location / { root /usr/share/phpmyadmin/; index index.php index.html index.htm; location ~ ^/(.+\.php)$ { try_files $uri =404; root /usr/share/phpmyadmin/; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include /etc/nginx/fastcgi_params; } location ~* ^/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/phpmyadmin/; } } } 

And restart Nginx


 sudo service nginx restart 

MySQL Presets


We go to the address pma.your.site , which you registered in the settings above, log in as root user with the password that you set during the installation of MySQL .


Create a graphite database and a graphite user, and give this user all the privileges on this database.


Install and configure Graphite + Carbon


Install Graphite + Carbon


Here, too, everything is quite simple:


 sudo apt-get install graphite-web graphite-carbon 

Graphite Setup


Edit the configuration file /etc/graphite/local_settings.py .


 SECRET_KEY = 'MY NICE RANDOM SALT' TIME_ZONE = 'UTC' USE_REMOTE_USER_AUTHENTICATION = True DATABASES = { 'default': { 'NAME': 'graphite', 'ENGINE': 'django.db.backends.mysql', 'USER': 'graphite', 'PASSWORD': 'mypassword', 'HOST': '127.0.0.1', 'PORT': '' } } 

Sync Database


Synchronize the database with the following command


 sudo graphite-manage syncdb 

Carbon Setup


Editing the following configuration files


/etc/default/graphite-carbon


 CARBON_CACHE_ENABLED = true 

/etc/carbon/carbon.conf


 ENABLE_LOGROTATION = True 

Copy the default storage aggregation settings


 sudo cp /usr/share/doc/graphite-carbon/examples/storage-aggregation.conf.example /etc/carbon/storage-aggregation.conf 

And restart Carbon


 sudo service carbon-cache start 

UWSGI installation


To install uWSGI run the following commands.


  sudo apt-get install python-dev sudo pip install uwsgi 

If pip is not installed on your system, install it


 sudo apt-get install python-pip 

And we execute the commands above.


Copy the standard configuration file


 sudo cp /usr/share/graphite-web/graphite.wsgi /usr/share/graphite-web/graphite_wsgi.py 

Create a configuration file:


 sudo nano /etc/init/uwsgi-graphite.conf 

And enter the following lines there:


  env UWSGI_BIN=/usr/local/bin/uwsgi env PYTHONPATH=/usr/share/graphite-web expect fork umask 0000 start on runlevel [2345] stop on runlevel [!2345] script exec $UWSGI_BIN --socket /var/run/graphite.sock --master --need-app \ --catch-exceptions --reload-on-exception --pp $PYTHONPATH \ -w graphite_wsgi:application --buffer-size 32768 -p 4 -O 2 >>/var/log/graphite.log 2>&1 & end script 

And run Graphite


 sudo service uwsgi-graphite start 

Configure Nginx for Graphite


Editing the configuration file /etc/nginx/conf.d/graphite.conf


 server { server_name graphite.your.site; listen 80; access_log /var/log/nginx/graphite.access.log; error_log /var/log/nginx/graphite.error.log; root /usr/share/graphite-web; location = /favicon.ico { return 204; } location /content { alias /usr/share/graphite-web/static; expires max; } location / { uwsgi_pass unix:/var/run/graphite.sock; include uwsgi_params; } } 

Restart Nginx and go to graphite.your.site


It looks like Graphite


Graphite Testing


To test the Graphite functionality, it’s enough to execute one simple command:


 echo "test.count 9 `date +%s`" | nc -q0 127.0.0.1 2003; 

Well, or run a cycle:


 for i in 4 6 8 16 2; do echo "test.count $i `date +%s`" | nc -q0 127.0.0.1 2003; sleep 6; done 

Now in Graphite it is fashionable to observe the following:


It looks like Graphite


Install and configure a beautiful Web-muzzle Grafana


Install Grafana


This is the graphics in grafana


To install Grafana execute the following commands:


 echo 'deb https://packagecloud.io/grafana/stable/debian/ wheezy main' | sudo tee -a /etc/apt/sources.list curl https://packagecloud.io/gpg.key | sudo apt-key add - sudo apt-get update sudo apt-get install grafana 

Configuring MySQL for Grafana


Create a database in grafana in MySQL and give all privileges to it to the graphite user we created earlier.


Editing the configuration file /etc/grafana/grafana.ini


 [database] type = mysql host = 127.0.0.1:3306 name = grafana user = graphite password = mypassword [server] protocol = http http_addr = 127.0.0.1 http_port = 3000 domain = grafana.your.site enforce_domain = true root_url = %(protocol)s://%(domain)s/ [security] admin_user = admin # - admin_password = your_secure_password #  - secret_key = your_random_secret_salt 

And run Grafana


 sudo service grafana-server start 

Configuring Nginx for Grafana


Editing the configuration file /etc/nginx/conf.d/grafana.conf


 server { server_name grafana.your.site; listen 80; access_log /var/log/nginx/grafana.access.log; error_log /var/log/nginx/grafana.error.log; location = /robots.txt { echo "User-agent: *\nDisallow: /\n"; } location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; } } 

Restart Nginx and go to grafana.your.site


This is the Grafana login page.


Enter the administrator login / password that you set above, and get into the admin panel Grafana .


It looks like the admin Grafana


Before creating dashboards and displaying metrics, you need to configure data sources.


Go to the section Data Source -> Add New


Enter the following data



Here is an example:


Grafana datasource configuration example


Now go to the main page, click New Dashboard -> New ,
On the left there will be an inconspicuous green button, when you hover on it, it crawls out from the edge of the screen. Click on it and then Add Panel -> Graph


Below you will see the metrics that we created with the test command above, test and count .


Display graphics


That’s all for now, later I’ll tell you about the plugins for Grafana .


More information


Please follow the links below to learn more about Grafana and its amazing settings.



Thanks


The article was based on the following articles:



Original article published on my blog.


')

Source: https://habr.com/ru/post/302720/


All Articles