1
0
Fork 0

Merge pull request #1 from tcpcloud/client

Client role
This commit is contained in:
Aleš Komárek 2016-10-28 11:50:09 +02:00 committed by GitHub
commit a927d2162c
29 changed files with 50171 additions and 28 deletions

View File

@ -5,31 +5,195 @@ Grafana
A beautiful, easy to use and feature rich Graphite dashboard replacement and graph editor.
Sample pillars
==============
Sample pillar installed from system package
Server deployments
------------------
Server installed from system package
.. code-block:: yaml
grafana:
server:
enabled: true
admin:
user: admin
password: passwd
database:
engine: sqlite
Server installed with PostgreSQL database
.. code-block:: yaml
grafana:
server:
enabled: true
admin:
user: admin
password: passwd
database:
engine: postgresql
host: localhost
port: 5432
data_source:
metrics1:
engine: graphite
host: metrics1.domain.com
ssl: true
name: grafana
user: grafana
password: passwd
Server installed with default StackLight JSON dashboards
.. code-block:: yaml
grafana:
server:
enabled: true
admin:
user: admin
password: passwd
dashboards:
enabled: true
path: /var/lib/grafana/dashboards
Collector setup
---------------
Used to aggregate dashboards from monitoring node.
.. code-block:: yaml
grafana:
collector:
enabled: true
Client setups
-------------
Client enforced data sources
.. code-block:: yaml
grafana:
client:
enabled: true
server:
protocol: https
host: grafana.host
port: 3000
token: token
datasource:
graphite:
type: graphite
host: mtr01.domain.com
protocol: https
port: 443
user: test
metrics2:
engine: elasticsearch
host: metrics2.domain.com
elasticsearch:
type: elasticsearch
host: log01.domain.com
port: 80
user: test
index: grafana-dash
Client defined and enforced dashboard
.. code-block:: yaml
grafana:
client:
enabled: true
server:
host: grafana.host
port: 3000
token: token
dashboard:
system_metrics:
title: "Generic system metrics"
style: dark
editable: false
row:
top:
title: "First row"
Client enforced dashboards defined in salt-mine
.. code-block:: yaml
grafana:
client:
enabled: true
remote_data:
engine: salt_mine
server:
host: grafana.host
port: 3000
token: token
Usage
=====
There's a difference between JSON dashboard representation and models we us.
The lists used in JSON format [for rows, panels and target] were replaced by
dictionaries. This form of serialization allows better merging and overrides
of hierarchical data structures that dashboard models are.
The default format of Grafana dashboards with lists for rows, panels and targets.
.. code-block:: yaml
system_metrics:
title: graph
editable: true
hideControls: false
rows:
- title: Usage
height: 250px
panels:
- title: Panel Title
span: 6
editable: false
type: graph
targets:
- refId: A
target: "support_prd.cfg01_iot_tcpcloud_eu.cpu.0.idle"
datasource: graphite01
renderer: flot
showTitle: true
The modified version of Grafana dashboard format with dictionary declarations.
Please note that dictionary keys are only for logical separation and are not
displayed in generated dashboards.
.. code-block:: yaml
system_metrics:
system_metrics2:
title: graph
editable: true
hideControls: false
row:
usage:
title: Usage
height: 250px
panel:
usage-panel:
title: Panel Title
span: 6
editable: false
type: graph
target:
A:
refId: A
target: "support_prd.cfg01_iot_tcpcloud_eu.cpu.0.idle"
datasource: graphite01
renderer: flot
showTitle: true
Read more
=========

72
grafana/client.sls Normal file
View File

@ -0,0 +1,72 @@
{%- from "grafana/map.jinja" import client with context %}
{%- if client.enabled %}
/etc/salt/minion.d/_grafana.conf:
file.managed:
- source: salt://grafana/files/_grafana.conf
- template: jinja
- user: root
- group: root
{%- for datasource_name, datasource in client.datasource.iteritems() %}
grafana_client_datasource_{{ datasource_name }}:
grafana_datasource.present:
- name: {{ datasource_name }}
- type: {{ datasource.type }}
- url: http://{{ datasource.host }}:{{ datasource.get('port', 80) }}
{%- if datasource.access is defined %}
- access: proxy
{%- endif %}
{%- if datasource.user is defined %}
- basic_auth: true
- basic_auth_user: {{ datasource.user }}
- basic_auth_password: {{ datasource.password }}
{%- endif %}
{%- endfor %}
{%- set raw_dict = {} %}
{%- set final_dict = {} %}
{%- if client.remote_data.engine == 'salt_mine' %}
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
{%- if node_grains.grafana is defined %}
{%- set raw_dict = salt['grains.filter_by']({'default': raw_dict}, merge=node_grains.grafana.get('dashboard', {})) %}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if client.dashboard is defined %}
{%- set raw_dict = salt['grains.filter_by']({'default': raw_dict}, merge=client.dashboard) %}
{%- endif %}
{%- for dashboard_name, dashboard in raw_dict.iteritems() %}
{%- set rows = [] %}
{%- for row_name, row in dashboard.get('row', {}).iteritems() %}
{%- set panels = [] %}
{%- for panel_name, panel in row.get('panel', {}).iteritems() %}
{%- set targets = [] %}
{%- for target_name, target in panel.get('target', {}).iteritems() %}
{%- do targets.extend([target]) %}
{%- endfor %}
{%- do panel.update({'targets': targets}) %}
{%- do panels.extend([panel]) %}
{%- endfor %}
{%- do row.update({'panels': panels}) %}
{%- do rows.extend([row]) %}
{%- endfor %}
{%- do dashboard.update({'rows': rows}) %}
{%- do final_dict.update({dashboard_name: dashboard}) %}
{%- endfor %}
{%- for dashboard_name, dashboard in final_dict.iteritems() %}
grafana_client_dashboard_{{ dashboard_name }}:
grafana_dashboard.present:
- name: {{ dashboard_name }}
- dashboard: {{ dashboard }}
{%- endfor %}
{%- endif %}

50
grafana/collector.sls Normal file
View File

@ -0,0 +1,50 @@
{%- from "grafana/map.jinja" import collector with context %}
{%- if collector.enabled %}
grafana_grains_dir:
file.directory:
- name: /etc/salt/grains.d
- mode: 700
- makedirs: true
- user: root
{%- set service_grains = {} %}
{# Loading the other service support metadata for localhost #}
{%- for service_name, service in pillar.iteritems() %}
{%- macro load_grains_file(grains_fragment_file) %}{% include grains_fragment_file ignore missing %}{% endmacro %}
{%- set grains_fragment_file = service_name+'/meta/grafana.yml' %}
{%- set grains_yaml = load_grains_file(grains_fragment_file)|load_yaml %}
{%- set service_grains = salt['grains.filter_by']({'default': service_grains}, merge=grains_yaml) %}
{%- endfor %}
grafana_grain:
file.managed:
- name: /etc/salt/grains.d/grafana
- source: salt://grafana/files/grafana.grain
- template: jinja
- user: root
- mode: 600
- defaults:
service_grains:
grafana: {{ service_grains|yaml }}
- require:
- file: grafana_grains_dir
grafana_grains_file:
cmd.wait:
- name: cat /etc/salt/grains.d/* > /etc/salt/grains
- watch:
- file: grafana_grain
grafana_grains_publish:
module.run:
- name: mine.update
- watch:
- cmd: grafana_grains_file
{%- endif %}

View File

@ -0,0 +1,8 @@
{%- from "grafana/map.jinja" import client with context %}
grafana_version: 2
grafana:
grafana_timeout: 3
grafana_token: {{ client.server.token }}
grafana_url: 'http://{{ client.server.host }}:{{ client.server.get('port', 80) }}'

View File

@ -0,0 +1,898 @@
{
"annotations": {
"list": [
{
"datasource": "lma",
"enable": true,
"iconColor": "#C0C6BE",
"iconSize": 13,
"lineColor": "rgba(255, 96, 96, 0.592157)",
"name": "Status",
"query": "select title,tags,text from annotations where $timeFilter and cluster = 'apache'",
"showLine": true,
"tagsColumn": "tags",
"textColumn": "text",
"titleColumn": "title"
}
]
},
"editable": true,
"hideControls": false,
"id": null,
"links": [],
"originalTitle": "Apache",
"refresh": "1m",
"rows": [
{
"collapse": false,
"editable": true,
"height": "250px",
"panels": [
{
"cacheTimeout": null,
"colorBackground": true,
"colorValue": false,
"colors": [
"rgba(71, 212, 59, 0.4)",
"rgba(241, 181, 37, 0.73)",
"rgba(225, 40, 40, 0.59)"
],
"datasource": null,
"editable": true,
"error": false,
"format": "none",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"id": 11,
"interval": "> 60s",
"links": [],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"span": 3,
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"targets": [
{
"column": "value",
"condition": "",
"dsType": "influxdb",
"fill": "",
"function": "last",
"groupBy": [
{
"params": [
"$interval"
],
"type": "time"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"groupByTags": [],
"groupby_field": "",
"interval": "",
"measurement": "cluster_status",
"policy": "default",
"query": "SELECT last(\"value\") FROM \"cluster_status\" WHERE \"cluster_name\" = 'apache' AND $timeFilter GROUP BY time($interval) fill(null)",
"rawQuery": false,
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"value"
],
"type": "field"
},
{
"params": [],
"type": "last"
}
]
],
"tags": [
{
"key": "environment_label",
"operator": "=",
"value": "$environment"
},
{
"key": "cluster_name",
"operator": "=",
"value": "apache"
}
]
}
],
"thresholds": "1,3",
"title": "",
"type": "singlestat",
"valueFontSize": "80%",
"valueMaps": [
{
"op": "=",
"text": "no data",
"value": "null"
},
{
"op": "=",
"text": "OKAY",
"value": "0"
},
{
"op": "=",
"text": "WARN",
"value": "1"
},
{
"op": "=",
"text": "UNKN",
"value": "2"
},
{
"op": "=",
"text": "CRIT",
"value": "3"
},
{
"op": "=",
"text": "DOWN",
"value": "4"
}
],
"valueName": "current"
},
{
"aliasColors": {},
"bars": false,
"datasource": null,
"editable": true,
"error": false,
"fill": 1,
"grid": {
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"id": 9,
"interval": "> 60s",
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": false,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "connected",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [
{
"column": "value",
"dsType": "influxdb",
"function": "mean",
"groupBy": [
{
"params": [
"$interval"
],
"type": "time"
},
{
"params": [
"0"
],
"type": "fill"
}
],
"groupByTags": [],
"measurement": "apache_requests",
"policy": "default",
"query": "SELECT mean(\"value\") FROM \"apache_requests\" WHERE \"hostname\" = '$server' AND $timeFilter GROUP BY time($interval) fill(0)",
"rawQuery": false,
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"value"
],
"type": "field"
},
{
"params": [],
"type": "mean"
}
]
],
"tags": [
{
"key": "hostname",
"value": "$server"
}
]
}
],
"timeFrom": null,
"timeShift": null,
"title": "Number of requests",
"tooltip": {
"msResolution": false,
"shared": false,
"value_type": "cumulative"
},
"type": "graph",
"xaxis": {
"show": true
},
"yaxes": [
{
"format": "short",
"label": "per second",
"logBase": 1,
"max": null,
"min": 0,
"show": true
},
{
"format": "short",
"logBase": 1,
"max": null,
"min": null,
"show": true
}
]
},
{
"aliasColors": {},
"bars": false,
"datasource": null,
"editable": true,
"error": false,
"fill": 1,
"grid": {
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"id": 8,
"interval": "> 60s",
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": false,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "connected",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"span": 9,
"stack": false,
"steppedLine": false,
"targets": [
{
"column": "value",
"dsType": "influxdb",
"function": "mean",
"groupBy": [
{
"params": [
"$interval"
],
"type": "time"
},
{
"params": [
"0"
],
"type": "fill"
}
],
"groupByTags": [],
"measurement": "apache_bytes",
"policy": "default",
"query": "SELECT mean(\"value\") FROM \"apache_bytes\" WHERE \"hostname\" = '$server' AND $timeFilter GROUP BY time($interval) fill(0)",
"rawQuery": false,
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"value"
],
"type": "field"
},
{
"params": [],
"type": "mean"
}
]
],
"tags": [
{
"key": "hostname",
"value": "$server"
}
]
}
],
"timeFrom": null,
"timeShift": null,
"title": "Bytes/s transmitted",
"tooltip": {
"msResolution": false,
"shared": true,
"value_type": "cumulative"
},
"type": "graph",
"xaxis": {
"show": true
},
"yaxes": [
{
"format": "bytes",
"label": "Bytes/s",
"logBase": 1,
"max": null,
"min": 0,
"show": true
},
{
"format": "short",
"logBase": 1,
"max": null,
"min": null,
"show": true
}
]
},
{
"aliasColors": {},
"bars": false,
"datasource": null,
"editable": true,
"error": false,
"fill": 1,
"grid": {
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"id": 10,
"interval": "> 60s",
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": false,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "connected",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"span": 9,
"stack": false,
"steppedLine": false,
"targets": [
{
"column": "value",
"dsType": "influxdb",
"function": "mean",
"groupBy": [
{
"params": [
"$interval"
],
"type": "time"
},
{
"params": [
"0"
],
"type": "fill"
}
],
"groupByTags": [],
"measurement": "apache_connections",
"policy": "default",
"query": "SELECT mean(\"value\") FROM \"apache_connections\" WHERE \"hostname\" = '$server' AND $timeFilter GROUP BY time($interval) fill(0)",
"rawQuery": false,
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"value"
],
"type": "field"
},
{
"params": [],
"type": "mean"
}
]
],
"tags": [
{
"key": "hostname",
"value": "$server"
}
]
}
],
"timeFrom": null,
"timeShift": null,
"title": "Number of connections",
"tooltip": {
"msResolution": false,
"shared": true,
"value_type": "cumulative"
},
"type": "graph",
"xaxis": {
"show": true
},
"yaxes": [
{
"format": "short",
"logBase": 1,
"max": null,
"min": 0,
"show": true
},
{
"format": "short",
"logBase": 1,
"max": null,
"min": null,
"show": true
}
]
},
{
"cacheTimeout": null,
"colorBackground": false,
"colorValue": false,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"datasource": null,
"editable": true,
"error": false,
"format": "none",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"id": 6,
"interval": "> 60s",
"links": [],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"span": 3,
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": true
},
"targets": [
{
"column": "value",
"dsType": "influxdb",
"function": "last",
"groupBy": [
{
"params": [
"$interval"
],
"type": "time"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"groupByTags": [],
"measurement": "apache_connections",
"policy": "default",
"query": "SELECT last(\"value\") FROM \"apache_connections\" WHERE \"hostname\" = '$server' AND $timeFilter GROUP BY time($interval) fill(null)",
"rawQuery": false,
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"value"
],
"type": "field"
},
{
"params": [],
"type": "last"
}
]
],
"tags": [
{
"key": "hostname",
"value": "$server"
}
]
}
],
"thresholds": "",
"title": "Current connections",
"type": "singlestat",
"valueFontSize": "80%",
"valueMaps": [
{
"op": "=",
"text": "N/A",
"value": "null"
}
],
"valueName": "current"
},
{
"aliasColors": {},
"bars": false,
"datasource": null,
"decimals": null,
"editable": true,
"error": false,
"fill": 1,
"grid": {
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"id": 1,
"interval": "> 60s",
"legend": {
"alignAsTable": true,
"avg": false,
"current": false,
"max": false,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "connected",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"span": 9,
"stack": false,
"steppedLine": false,
"targets": [
{
"alias": "$m",
"column": "value",
"dsType": "influxdb",
"function": "mean",
"groupBy": [
{
"params": [
"$interval"
],
"type": "time"
},
{
"params": [
"0"
],
"type": "fill"
}
],
"groupByTags": [],
"measurement": "/apache_workers/",
"policy": "default",
"query": "SELECT mean(\"value\") FROM /apache_workers/ WHERE \"hostname\" = '$server' AND $timeFilter GROUP BY time($interval) fill(0)",
"rawQuery": false,
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"value"
],
"type": "field"
},
{
"params": [],
"type": "mean"
}
]
],
"tags": [
{
"key": "hostname",
"value": "$server"
}
]
}
],
"timeFrom": null,
"timeShift": null,
"title": "Workers states",
"tooltip": {
"msResolution": false,
"shared": true,
"value_type": "individual"
},
"transparent": false,
"type": "graph",
"xaxis": {
"show": true
},
"yaxes": [
{
"format": "short",
"logBase": 1,
"max": null,
"min": 0,
"show": true
},
{
"format": "short",
"logBase": 1,
"max": null,
"min": null,
"show": true
}
]
},
{
"cacheTimeout": null,
"colorBackground": false,
"colorValue": false,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"datasource": null,
"editable": true,
"error": false,
"format": "none",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"id": 4,
"interval": "> 60s",
"links": [],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"span": 3,
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": true
},
"targets": [
{
"column": "value",
"dsType": "influxdb",
"function": "last",
"groupBy": [
{
"params": [
"$interval"
],
"type": "time"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"groupByTags": [],
"measurement": "apache_idle_workers",
"policy": "default",
"query": "SELECT last(\"value\") FROM \"apache_idle_workers\" WHERE \"hostname\" = '$server' AND $timeFilter GROUP BY time($interval) fill(null)",
"rawQuery": false,
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"value"
],
"type": "field"
},
{
"params": [],
"type": "last"
}
]
],
"tags": [
{
"key": "hostname",
"value": "$server"
}
]
}
],
"thresholds": "",
"title": "Current Idle Workers",
"type": "singlestat",
"valueFontSize": "80%",
"valueMaps": [
{
"op": "=",
"text": "N/A",
"value": "null"
}
],
"valueName": "current"
}
],
"title": "Metrics"
}
],
"schemaVersion": 12,
"sharedCrosshair": true,
"style": "dark",
"tags": [],
"templating": {
"enable": true,
"list": [
{
"allFormat": "regex values",
"current": {},
"datasource": null,
"hide": 0,
"includeAll": false,
"name": "environment",
"options": [],
"query": "show tag values from cpu_idle with key = environment_label",
"refresh": 1,
"refresh_on_load": true,
"regex": "",
"type": "query"
},
{
"allFormat": "glob",
"current": {},
"datasource": null,
"hide": 0,
"includeAll": false,
"name": "server",
"options": [],
"query": "show tag values from apache_requests with key = hostname where environment_label = '$environment'",
"refresh": 1,
"refresh_on_load": true,
"regex": "",
"type": "query"
}
]
},
"time": {
"from": "now-1h",
"to": "now"
},
"timepicker": {
"collapse": false,
"enable": true,
"notice": false,
"now": true,
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"status": "Stable",
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
],
"type": "timepicker"
},
"timezone": "browser",
"title": "Apache",
"version": 2
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
{{ service_grains|yaml(False) }}

View File

@ -25,7 +25,7 @@
# The ip address to bind to, empty will bind to all interfaces
http_addr = {{ server.bind.address }}
# The http port to use
# The http port to use
http_port = {{ server.bind.port }}
# The public facing domain name used to access grafana from a browser
@ -55,21 +55,25 @@ http_port = {{ server.bind.port }}
[database]
# Either "mysql", "postgres" or "sqlite3", it's your choice
type = {% if server.database.engine == "postgresql" %}postgres{% else %}{{ server.database.engine }}{% endif %}
{%- if server.database.engine in ["postgresql", "mysql"] %}
host = {{ server.database.host }}:{{ server.database.port }}
name = {{ server.database.name }}
user = {{ server.database.user }}
password = {{ server.database.password }}
{%- endif %}
# For "postgres" only, either "disable", "require" or "verify-full"
;ssl_mode = disable
# For "sqlite3" only, path relative to data_path setting
;path = grafana.db
{%- if server.database.engine in ["sqlite"] %}
path = grafana.db
{%- endif %}
#################################### Session ####################################
[session]
# Either "memory", "file", "redis", "mysql", "postgres", default is "file"
provider = {{ server.get('session', {}).get('engine', 'file') }}
provider = {{ server.session.engine }}
# Provider config options
# memory: not have any config yet
@ -77,7 +81,7 @@ provider = {{ server.get('session', {}).get('engine', 'file') }}
# redis: config like redis server e.g. `addr=127.0.0.1:6379,pool_size=100,db=grafana`
# mysql: go-sql-driver/mysql dsn config string, e.g. `user:password@tcp(127.0.0.1:3306)/database_name`
# postgres: user=a password=b host=localhost port=5432 dbname=c sslmode=disable
{%- if server.get('session', {}).get('engine', 'file') == 'redis' %}
{%- if server.session.engine == 'redis' %}
provider_config = addr={{ server.session.get('host', '127.0.0.1') }}:{{ server.session.get('port', 6379) }},db={{ server.session.get('db', 'grafana') }}
{%- endif %}
@ -104,10 +108,10 @@ provider_config = addr={{ server.session.get('host', '127.0.0.1') }}:{{ server.s
#################################### Security ####################################
[security]
# default admin user, created on startup
;admin_user = admin
admin_user = {{ server.admin.user }}
# default admin password, can be changed before first start of grafana, or in profile settings
;admin_password = admin
admin_password = {{ server.admin.password }}
# used for signing
;secret_key = SW2YcwTIb9zpOOhoPsMm
@ -126,21 +130,21 @@ provider_config = addr={{ server.session.get('host', '127.0.0.1') }}:{{ server.s
#################################### Users ####################################
[users]
# disable user signup / registration
allow_sign_up = {{ server.get('users', {}).get('sign_up', True)|lower }}
allow_sign_up = {{ server.allow_sign_up|lower }}
# Allow non admin users to create organizations
allow_org_create = {{ server.get('users', {}).get('org_create', True)|lower }}
allow_org_create = {{ server.allow_org_create|lower }}
# Set to true to automatically assign new users to the default organization (id 1)
;auto_assign_org = true
# Default role new users will be automatically assigned (if disabled above is set to true)
;auto_assign_org_role = Viewer
auto_assign_org_role = {{ server.get('users', {}).get('auto_assign_role', 'Viewer') }}
auto_assign_org_role = {{ server.auto_assign_role }}
#################################### Anonymous Auth ##########################
[auth.anonymous]
{%- if server.get('auth', {}).get('engine', None) == 'anonymous' %}
{%- if server.auth.engine == 'anonymous' %}
enabled = true
{%- if server.auth.organization is defined %}
@ -189,7 +193,7 @@ org_name = {{ server.auth.role }}
#################################### Auth Proxy ##########################
[auth.proxy]
{%- if server.get('auth', {}).get('engine', None) == 'proxy' %}
{%- if server.auth.engine == 'proxy' %}
enabled = true
header_name = {{ server.auth.get('header', 'X-Forwarded-User') }}
header_property = {{ server.auth.get('header_property', 'username') }}
@ -198,10 +202,10 @@ auto_sign_up = true
#################################### Basic Auth ##########################
[auth.basic]
{%- if server.get('auth', {}).get('engine', 'basic') != 'basic' %}
enabled = false
{%- else %}
{%- if server.auth.engine == 'basic' %}
enabled = true
{%- else %}
enabled = false
{%- endif %}
#################################### Auth LDAP ##########################
@ -273,6 +277,11 @@ enabled = false
;#################################### Dashboard JSON files ##########################
[dashboards.json]
{%- if server.dashboards.enabled %}
enabled = true
path = {{ server.dashboards.path }}
{%- else %}
;enabled = false
;path = /var/lib/grafana/dashboards
{%- endif %}

View File

@ -4,4 +4,10 @@ include:
{%- if pillar.grafana.server is defined %}
- grafana.server
{%- endif %}
{%- if pillar.grafana.client is defined %}
- grafana.client
{%- endif %}
{%- if pillar.grafana.collector is defined %}
- grafana.collector
{%- endif %}
{%- endif %}

View File

@ -7,6 +7,31 @@ Debian:
bind:
address: 0.0.0.0
port: 3000
session:
engine: file
auth:
engine: application
admin:
user: admin
password: admin
allow_sign_up: False
allow_org_create: False
auto_assign_role: Viewer
dashboards:
enabled: false
{%- endload %}
{%- set server = salt['grains.filter_by'](base_defaults, merge=salt['pillar.get']('grafana:server')) %}
{%- set server = salt['grains.filter_by'](base_defaults, merge=salt['pillar.get']('grafana:server')) %}
{%- load_yaml as base_defaults %}
Debian:
server:
host: 127.0.0.1
port: 3000
remote_data:
engine: none
datasource: {}
dashboard: {}
{%- endload %}
{%- set client = salt['grains.filter_by'](base_defaults, merge=salt['pillar.get']('grafana:client')) %}

45
grafana/meta/grafana.yml Normal file
View File

@ -0,0 +1,45 @@
{%- if pillar.get('grafana').collector is defined %}
dashboard:
test-single-{{ grains.host }}:
title: Dashboard single {{ grains.host }}
editable: true
hideControls: false
row:
single:
title: Single row
height: 250px
showTitle: true
panel:
first:
title: Single Panel
span: 8
editable: false
type: graph
target:
A:
refId: A
target: "support_prd.cfg01_iot_tcpcloud_eu.cpu.0.idle"
datasource: graphite01
renderer: flot
test-merge:
title: Dashboard merge
editable: true
hideControls: false
row:
merge:
showTitle: true
title: Merge
height: 250px
panel:
merge:
title: Merge Panel
span: 8
editable: false
type: graph
target:
{{ grains.host }}:
refId: A
target: "support_prd.cfg01_iot_tcpcloud_eu.cpu.0.idle"
datasource: graphite01
renderer: flot
{%- endif %}

View File

@ -14,12 +14,26 @@ grafana_packages:
- require:
- pkg: grafana_packages
{%- if server.dashboards.enabled %}
grafana_copy_default_dashboards:
file.recurse:
- name: {{ server.dashboards.path }}
- source: salt://grafana/files/dashboards
- user: grafana
- group: grafana
- require:
- pkg: grafana_packages
{%- endif %}
grafana_service:
service.running:
- name: {{ server.service }}
- enable: true
- reload: true
- watch:
- file: /etc/grafana/grafana.ini
{%- if server.dashboards.enabled %}
- require:
- file: grafana_copy_default_dashboards
{%- endif %}
{%- endif %}
{%- endif %}