Skip to content

Commit

Permalink
Added Graphite support & dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikesch-mp committed Mar 3, 2017
1 parent 8e314e1 commit d0958da
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 257 deletions.
15 changes: 12 additions & 3 deletions README.md
Expand Up @@ -10,16 +10,17 @@ Icinga Web 2 (>= 2.4.0)

Grafana (>= 4.1)

InfluxDB or any other valid data source
InfluxDB, Graphite and PNP(untested)

## Installation

* Extract this to your Icinga Web 2 module folder in a folder called grafana.
* Enable the module (Configuration -> Modules -> grafana -> enable).
* Configure the module and save configuration (Configuration -> Modules -> grafana -> Configuration).
* With InfluxDB Datasource: Import the 2 json files into your Grafana server. The default dashboard must be named 'icinga2-default'.
* Depending on your datasource import the 2 json files into your Grafana server.
The default dashboard name is 'icinga2-default', but you can configure it now too.

__*If you use Graphite or other datasources, you have to edit the 2 dashboards metric queries, or create new dashboards!__
__*If you use PNP datasources, you have to edit the 2 dashboards metric queries, or create new dashboards!__

## Configuration

Expand Down Expand Up @@ -49,6 +50,12 @@ The global time range for the graphs, default: *6h*
**Enable Link**
Enables/disable the graph as a link to Grafana dashboard, default: *yes*

**Default Dashboard**
The name of the defaut dashboard that should be used for not configured graphs. Important, panelID must be 1! Default: *icinga-default*

**Datasource type**
The type of your Grafana datasource (InfluxDB,Graphite or PNP),default: *InfluxDB*


Example (/etc/icingaweb2/modules/grafana/)config.ini
```
Expand All @@ -61,6 +68,8 @@ height = "280"
width = "640"
timerange = "3h"
enableLink = "yes"
defaultdashboard = "icinga2-default"
datasource = "influxdb"
```

## Graph configuration
Expand Down
25 changes: 24 additions & 1 deletion application/forms/Config/GeneralConfigForm.php
Expand Up @@ -43,7 +43,7 @@ public function createElements(array $formData)
'text',
'grafana_host',
array(
'value' => 'server.name:3000',
'placeholder' => 'server.name:3000',
'label' => $this->translate('Host'),
'description' => $this->translate('Host name of the Grafana server.'),
'required' => true
Expand Down Expand Up @@ -120,6 +120,29 @@ public function createElements(array $formData)
'description' => $this->translate('Image is an link to the dashboard on the Grafana server.')
)
);
$this->addElement(
'text',
'grafana_defaultdashboard',
array(
'value' => 'icinga-default',
'label' => $this->translate('Default dashboard'),
'description' => $this->translate('Name of the default dashboard.'),
)
);
$this->addElement(
'select',
'grafana_datasource',
array(
'label' => $this->translate('Datasource Type'),
'multiOptions' => array(
'influxdb' => $this->translate('InfluxDB'),
'graphite' => $this->translate('Graphite'),
'pnp' => $this->translate('PNP'),
),
'description' => $this->translate('Grafana Datasource Type.')
)
);

}
}

249 changes: 0 additions & 249 deletions dashboards/graphite/graphite-icinga2-default-1488559187047.json

This file was deleted.

File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion icingaexchange.yml
Expand Up @@ -9,7 +9,7 @@ license: gplv2
releases:
-
name: v1.0.2
description: "Current"
description: "Update 1.0.2"
files:
-
name: icingaweb2-module-grafana-1.0.2.tar.gz
Expand Down
13 changes: 11 additions & 2 deletions library/Grafana/Grapher.php
Expand Up @@ -25,6 +25,8 @@ class Grapher extends GrapherHook
protected $username = null;
protected $width = 640;
protected $enableLink = true;
protected $defaultDashboard = "icinga2-default";
protected $datasource = null;

protected function init()
{
Expand All @@ -42,6 +44,8 @@ protected function init()
$this->height = $this->config->get('height', $this->height);
$this->width = $this->config->get('width', $this->width);
$this->enableLink = $this->config->get('enableLink', $this->enableLink);
$this->defaultDashboard = $this->config->get('defaultdashboard', $this->defaultDashboard);
$this->datasource = $this->config->get('datasource', $this->datasource);

if($this->username != null){
if($this->password != null){
Expand All @@ -63,7 +67,7 @@ private function getGraphConf($serviceName)
$serviceName = strtok($serviceName, ' ');
}

$this->dashboard = $this->graphconfig->get($serviceName, 'dashboard', 'icinga2-default');
$this->dashboard = $this->graphconfig->get($serviceName, 'dashboard', $this->defaultDashboard);
$this->panelId = $this->graphconfig->get($serviceName, 'panelId', '1');
$this->timerange = $this->graphconfig->get($serviceName, 'timerange', $this->timerange);

Expand Down Expand Up @@ -130,14 +134,19 @@ public function getPreviewHtml(MonitoredObject $object)

$this->getGraphConf($serviceName);

if ($this->datasource == "graphite") {
$serviceName = preg_replace('/[^a-zA-Z0-9\*\-:]/', '_', $serviceName);
$hostName = preg_replace('/[^a-zA-Z0-9\*\-:]/', '_', $hostName);
}

if ($this->enableLink == "no")
{
return $this->getPreviewImage($serviceName, $hostName);
}

$html = '<a href="%s://%s/dashboard/db/%s?var-hostname=%s&var-service=%s&from=now-%s&to=now';

if ( $this->dashboard != "icinga2-default")
if ( $this->dashboard != $this->defaultDashboard )
{
$html .= '&panelId=' . $this->panelId .'&fullscreen';
}
Expand Down
2 changes: 1 addition & 1 deletion module.info
@@ -1,5 +1,5 @@
Module: grafana
Version: 1.0.2
Version: 1.0.3
Depends: monitoring
Description: Grafana - A perfdata visualisation module
Shows Grafana graphs for captured metrics.

0 comments on commit d0958da

Please sign in to comment.