Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion modules/grafana.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@


def generate(host, *args):
prometheus_servers = {}
for server in sorted(lib.get_nodes_with_package('prometheus').keys()):
try:
domain = lib.get_domain(server).lower()
except lib.NoDomainError:
domain = 'unknown'
prometheus_servers[server] = domain

info = {
'grafana': {
'current_event': lib.get_current_event()
'current_event': lib.get_current_event(),
'prometheus_servers': prometheus_servers,
}
}

Expand Down
11 changes: 10 additions & 1 deletion modules/grafana/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# for package details such as default paths etc.
#

class grafana($current_event) {
class grafana($current_event, $prometheus_servers = []) {

# Adding the apt repository
package { 'apt-transport-https':
Expand Down Expand Up @@ -110,6 +110,15 @@
}
}

# Prometheus datasource provisioning
file { 'grafana-prometheus-datasources':
path => '/etc/grafana/provisioning/datasources/prometheus.yaml',
content => template('grafana/prometheus-datasource.yaml.erb'),
mode => '0644',
require => Package['grafana'],
notify => Service['grafana-server'],
}

# Setting up the Apache proxy
apache::proxy { 'grafana-backend':
url => '/',
Expand Down
12 changes: 12 additions & 0 deletions modules/grafana/templates/prometheus-datasource.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Managed by Puppet - do not edit manually
apiVersion: 1

datasources:
<% @prometheus_servers.each do |server, domain| -%>
- name: prometheus_<%= domain %>
type: prometheus
url: http://<%= server %>:9090
access: proxy
isDefault: false
editable: false
<% end -%>
Loading