Graphite in IcingaWeb2 einbinden (Performancedaten)

Graphite in IcingaWeb2 einbinden (Performancedaten)

Graphite ist eine Open Source Graphing Lösung, die stark auf Flexibilität und Performance ausgelegt ist. Somit eignet sich Graphite perfekt zum Erfassen von Daten aus einem Monitoring System wie Icinga2.
Installation unter CentOS7 mit Icinga2, IcingaWeb2.

Derzeit befindet sich Graphite noch in einer Vorabversion, daher wird es offiziell nicht unterstützt.

Voraussetzungen:
CentOS7 Betriebsystem
Icinga2 & IcingaWeb2 Installation

Keine Voraussetzung aber interessant:

Windows Clients via Icinga Agent überwachen
Icinga Director installieren
Dashing für Icinga2 installieren

Installation:

Benötigte Pakete nachinstallieren

[root@centos7_icinga2_demo ~]# yum install python-whisper python-carbon graphite-web MySQL-python uwsgi-plugin-carbon

Abhängigkeiten aufgelöst

================================================================================
 Package                           Arch       Version            Paketquelle
                                                                          Größe
================================================================================
Installieren:
 MySQL-python                      x86_64     1.2.3-11.el7       base      82 k
 graphite-web                      noarch     0.9.15-1.el7       epel     1.8 M
 python-carbon                     noarch     0.9.15-1.el7       epel     109 k
 python-whisper                    noarch     0.9.15-1.el7       epel      42 k
 uwsgi-plugin-carbon               x86_64     2.0.12-2.el7       epel      22 k
Als Abhängigkeiten installiert:
 mod_wsgi                          x86_64     3.4-12.el7_0       base      76 k
 pyOpenSSL                         x86_64     0.13.1-3.el7       base     133 k
 pyserial                          noarch     2.6-5.el7          base     124 k
 python-django                     noarch     1.6.11-5.el7       epel     4.0 M
 python-django-bash-completion     noarch     1.6.11-5.el7       epel      16 k
 python-django-tagging             noarch     0.3.1-11.el7       epel      58 k
 python-simplejson                 x86_64     3.3.3-1.el7        epel     171 k
 python-twisted-core               x86_64     12.2.0-4.el7       base     2.5 M
 python-zope-interface             x86_64     4.0.5-4.el7        base     138 k
 uwsgi                             x86_64     2.0.12-2.el7       epel     359 k
 uwsgi-plugin-common               x86_64     2.0.12-2.el7       epel      47 k

Transaktionsübersicht
================================================================================
Installieren  5 Pakete (+11 Abhängige Pakete)

IcingaWeb2 Modul herunterladen

wget https://github.com/philiphoy/icingaweb2-module-graphite/archive/master.zip

Entpacken

unzip master.zip -d /usr/share/icingaweb2/modules

Ordner in das Icinga Modul Verzeichnis verschieben

mv /usr/share/icingaweb2/modules/icingaweb2-module-graphite-master/ /usr/share/icingaweb2/modules/graphite/

Pyton Carbon Konfiguration anpassen

vim /etc/carbon/carbon.conf

Vorher: 
ENABLE_LOGROTATION = False

Nachher:
ENABLE_LOGROTATION = True

Storage-Schema Konfiguration anpassen

vim /etc/carbon/storage-schemas.conf

[carbon]
pattern = ^carbon\.
retentions = 60:90d
 
[icinga2_default]
pattern = ^icinga2\.
retentions = 1m:2d,5m:10d,30m:90d,360m:4y
 
[default_1min_for_1day]
pattern = .*
retentions = 60s:1d

 

SQL-Datenbank anlegen

mysql -h localhost -u root -p


MariaDB [(none)]> CREATE DATABASE graphite;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON graphite.* TO 'graphite_user'@'localhost' IDENTIFIED BY 'BUsq4abGxrPysYeqdq61eujDlSHKv1xNyww';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON graphite.* TO 'graphite_user'@'127.0.0.1' IDENTIFIED BY 'BUsq4abGxrPysYeqdq61eujDlSHKv1xNyww';
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> GRANT ALL ON graphite.* TO 'graphite_user'@'::1' IDENTIFIED BY 'BUsq4abGxrPysYeqdq61eujDlSHKv1xNyww';
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit

Konfigurationsdatei „Graphite-Web“ anpassen

vim /etc/graphite-web/local_settings.py

vorher:
#SECRET_KEY = 'UNSAFE_DEFAULT'
#TIME_ZONE = 'America/Los_Angeles'

#DATABASES = {
#    'default': {
#        'NAME': '/opt/graphite/storage/graphite.db',
#        'ENGINE': 'django.db.backends.sqlite3',
#        'USER': '',
#        'PASSWORD': '',
#        'HOST': '',
#        'PORT': ''
#    }
#}
#

nachher: 
SECRET_KEY = '1r3ou$lSg71#cb2coery^hjbyc@6@yynfmd1$493^k8=l$lrs7'
TIME_ZONE = 'Europe/Berlin'

DATABASES = {
    'default': {
        'NAME': 'graphite',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'graphite_user',
        'PASSWORD': 'BUsq4abGxrPysYeqdq61eujDlSHKv1xNyww',
        'HOST': '127.0.0.1',
        'PORT': '3306'
    }
}

 

Whisper DB befüllen

[root@centos7_icinga2_demo ~]# /usr/lib/python*/site-packages/graphite/manage.py syncdb
Creating tables ...
Creating table account_profile
Creating table account_variable
Creating table account_view
Creating table account_window
Creating table account_mygraph
Creating table dashboard_dashboard_owners
Creating table dashboard_dashboard
Creating table events_event
Creating table url_shortener_link
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_session
Creating table django_admin_log
Creating table django_content_type
Creating table tagging_tag
Creating table tagging_taggeditem

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 'root'):
Email address:
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

 

Apache V-Host config anpassen

vim /etc/httpd/conf.d/graphite-web.conf

vorher:
<VirtualHost *:80>
    ServerName graphite-web
    DocumentRoot "/usr/share/graphite/webapp"
    ErrorLog /var/log/httpd/graphite-web-error.log
    CustomLog /var/log/httpd/graphite-web-access.log common

    # Header set Access-Control-Allow-Origin "*"
    # Header set Access-Control-Allow-Methods "GET, OPTIONS"
    # Header set Access-Control-Allow-Headers "origin, authorization, accept"
    # Header set Access-Control-Allow-Credentials true

    WSGIScriptAlias / /usr/share/graphite/graphite-web.wsgi
    WSGIImportScript /usr/share/graphite/graphite-web.wsgi process-group=%{GLOBAL} application-group=%{GLOBAL}

    <Location "/content/">
        SetHandler None
    </Location>

    Alias /media/ "/usr/lib/python2.7/site-packages/django/contrib/admin/media/"
    <Location "/media/">
        SetHandler None
    </Location>

   <Directory "/usr/share/graphite/">
       <IfModule mod_authz_core.c>
           # Apache 2.4
           Require local
       </IfModule>
       <IfModule !mod_authz_core.c>
           # Apache 2.2
           Order Deny,Allow
           Deny from all
           Allow from 127.0.0.1
           Allow from ::1
       </IfModule>
   </Directory>
</VirtualHost>



nachher:

  # Graphite Web Basic mod_wsgi vhost

<VirtualHost *:80>
    ServerName graphite-web
    DocumentRoot "/usr/share/graphite/webapp"
    ErrorLog /var/log/httpd/graphite-web-error.log
    CustomLog /var/log/httpd/graphite-web-access.log common

    # Header set Access-Control-Allow-Origin "*"
    # Header set Access-Control-Allow-Methods "GET, OPTIONS"
    # Header set Access-Control-Allow-Headers "origin, authorization, accept"
    # Header set Access-Control-Allow-Credentials true

    WSGIScriptAlias / /usr/share/graphite/graphite-web.wsgi
    WSGIImportScript /usr/share/graphite/graphite-web.wsgi process-group=%{GLOBAL} application-group=%{GLOBAL}

    <Location "/content/">
        SetHandler None
    </Location>

    Alias /media/ "/usr/lib/python2.7/site-packages/django/contrib/admin/media/"
    <Location "/media/">
        SetHandler None
    </Location>

   <Directory "/usr/share/graphite/">
    <IfModule mod_authz_core.c>
        # Apache 2.4
        <RequireAll>
            Require all granted
        </RequireAll>
    </IfModule>

    <IfModule !mod_authz_core.c>
        # Apache 2.2
        Order allow,deny
        Allow from all
    </IfModule>
   </Directory>
</VirtualHost>

WebServer neustaten

systemctl restart httpd.service

Graphite Modul Konfiguration anlegen dabei ist zu beachten das man unter Konfiguration -> Module -> Graphite -> im Tab Configuration eine bsp. Config erhält.
Diese kopieren und in die config.ini einfügen.

Webkonfiguration
Konfiguration -> Module -> Graphite -> aktivieren

graphine_1

Config-Vorlage kopieren.

graphine_3

 

mkdir /etc/icingaweb2/modules/graphite

vim /etc/icingaweb2/modules/graphite/config.ini

 

[graphite]
metric_prefix = icinga2
base_url = http://<<IP-ADRESSE DES SERVERS>>/render?
legacy_mode = false
;if legacy mode is false (2.4 and newer):
service_name_template = "icinga2.$host.name$.services.$service.name$.$service.check_command$.perfdata.$metric$.value"
host_name_template = "icinga2.$host.name$.host.$host.check_command$.perfdata.$metric$.value"
;if legacy mode is true (pre 2.4):
;service_name_template = "icinga.$host.name$.services.$service.name$.$service.check_command$"
;host_name_template = "icinga.$host.name$.host.$host.check_command$"
;this template is used for the small image, macro $target$ can used.
graphite_args_template = "&target=$target$&source=0&width=300&height=120&hideAxes=true&lineWidth=2&hideLegend=true&colorList=049BAF"
;this template is used for the large image, macro $target$ can used.
;graphite_large_args_template = "&target=alias(color($target$_warn,'yellow'),'warning')&target=alias(color($target$_crit,'red'),'critical')&target=$target$&source=0&width=800&height=700&colorList=049BAF&lineMode=connected"
graphite_iframe_w=800px
graphite_iframe_h=700px

Diensteanpassungen durchführen

systemctl start carbon-cache.service

systemctl enable carbon-cache.service

systemctl status carbon-cache.service

Icinga2 Feature aktivieren

icinga2 feature enable graphite

systemctl restart icinga2

Dienst anschauen

graphine_2

 

 

About the author

mbrunner administrator

3 Comments so far

DSPosted on9:10 pm - Sep 17, 2016

Vielen Dank, hat super geklappt! Wäre es möglich, dass Sie zeigen wie man einen APC anschließt, damit man Eigenschaften wie Temperatur, Luftfeuchtigkeit, usw. auslesen kann?
Freundliche Grüße und nochmals Danke

muhammadPosted on4:42 pm - Feb 2, 2017

brilliant tutorial absolutely brilliant, really appreciate it.It is what I have been looking for for days. Keep up the good work and thank you mbrunner. Just having difficulty in getting the graphs to fully display. So a few questions :-

1) 127.0.0.1 – is this the IP of the host running icinga?
2) I’m getting the following error on the graphs – „Required parameter ‚host‘ missing“. Maybe due to me being tired after a long day i think there may be something wrong with my config.ini file, will try again tomorrow.

Also few corrections on syntax i came across

1) ‚None Setndler‘ on Apache config meant to be ‚Sethandler None‘.
2)Customize storage schema configuration 1m:2d , 30m:3d etc.. make sure no spaces in ‚1m:2d‘ as the following gave errors :- ‚1m :2d‘

MuhammadPosted on10:06 am - Feb 3, 2017

I managed then, was a bit tired yesterday end of day. Graphite is working like a charm.

Thanks again.

Leave a Reply