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.
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
.
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
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
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.
Here, too, everything is quite simple:
sudo apt-get install graphite-web graphite-carbon
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': '' } }
Synchronize the database with the following command
sudo graphite-manage syncdb
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
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
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
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:
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
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
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
Enter the administrator login / password that you set above, and get into the admin panel 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:
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
.
That’s all for now, later I’ll tell you about the plugins for Grafana
.
Please follow the links below to learn more about Grafana
and its amazing settings.
The article was based on the following articles:
Original article published on my blog.
Source: https://habr.com/ru/post/302720/
All Articles