Puppet Class: puppet_operational_dashboards::profile::dashboards

Defined in:
manifests/profile/dashboards.pp

Summary

Installs Grafana and several dashboards to display Puppet metrics. Included via the base class.

Overview

Examples:

Basic usage

include puppet_operational_dashboards

class {'puppet_operational_dashboards::profile::dashboards':
  token         => '<my_sensitive_token>',
  influxdb_host => '<influxdb_fqdn>',
  influxdb_port => 8086,
  initial_bucket => '<my_bucket>',
}

Parameters:

  • token (Optional[Sensitive[String]]) (defaults to: $puppet_operational_dashboards::telegraf_token)

    Token in Sensitive format used to query InfluxDB. The token must grant priviledges to query the associated bucket in InfluxDB

  • grafana_host (String) (defaults to: $facts['networking']['fqdn'])

    FQDN of the Grafana host. Defaults to the FQDN of the agent receiving the catalog.

  • grafana_port (Integer) (defaults to: 3000)

    Port used by the Grafana service. Defaults to 3000

  • grafana_timeout (Integer) (defaults to: 10)

    How long to wait for the Grafana service to start. Defaults to 10 seconds.

  • grafana_password (Sensitive[String]) (defaults to: Sensitive('admin'))

    Grafana admin password in Sensitive format. Defaults to ‘admin’

  • grafana_version (String) (defaults to: '8.5.20')

    Version of the Grafana package to install. Defaults to ‘8.5.20’

  • grafana_datasource (String) (defaults to: 'influxdb_puppet')

    Name to use for the Grafana datasource. Defaults to ‘influxdb_puppet’

  • grafana_install (String) (defaults to: $facts['os']['family'] ? { /(RedHat|Debian)/ => 'repo', default => 'package')

    Method to use for installing Grafana. Defaults to using a repository on EL and Debian/Ubuntu, and package for other platforms

  • use_ssl (Boolean) (defaults to: $puppet_operational_dashboards::use_ssl)

    Whether to use SSL when querying InfluxDB. Defaults to true

  • manage_grafana (Boolean) (defaults to: true)

    Whether to manage installation and configuration of Grafana. Defaults to true

  • manage_grafana_repo (Boolean) (defaults to: true)

    Whether to manage the Grafana repository definition. Defaults to true.

  • influxdb_host (String) (defaults to: $puppet_operational_dashboards::influxdb_host)

    FQDN of the InfluxDB host. Defaults to the value of the base class, which looks up the value of influxdb::host with a default of $facts

  • influxdb_port (Integer) (defaults to: $puppet_operational_dashboards::influxdb_port)

    Port used by the InfluxDB service. Defaults to the value of the base class, which looks up the value of influxdb::port with a default of 8086

  • influxdb_bucket (String) (defaults to: $puppet_operational_dashboards::initial_bucket)

    Name of the InfluxDB bucket to query. Defaults to the value of the base class, which looks up the value of influxdb::initial_bucket with a default of ‘puppet_data’

  • telegraf_token_name (String) (defaults to: $puppet_operational_dashboards::telegraf_token_name)

    Name of the token to retrieve from InfluxDB if not given $token

  • influxdb_token_file (String) (defaults to: $puppet_operational_dashboards::influxdb_token_file)

    Location on disk of an InfluxDB admin token. This token is used in this class in a Deferred function call to retrieve a Telegraf token if $token is unset

  • provisioning_datasource_file (String) (defaults to: '/etc/grafana/provisioning/datasources/influxdb.yaml')

    Location on disk to store datasource definition

  • include_pe_metrics (Boolean) (defaults to: $puppet_operational_dashboards::include_pe_metrics)

    Whether to include Filesync and Orchestrator dashboards

  • manage_system_board (Boolean) (defaults to: $puppet_operational_dashboards::manage_system_board)

    Whether the System Performance dashboard should be created

  • system_dashboard_version (Enum['v1', 'v2', 'all']) (defaults to: 'v2')

    Version of the system dashboard to manage. v2 is compatible with puppet_metrics_collector version 7 and up



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'manifests/profile/dashboards.pp', line 55

class puppet_operational_dashboards::profile::dashboards (
  Optional[Sensitive[String]] $token = $puppet_operational_dashboards::telegraf_token,
  String $grafana_host = $facts['networking']['fqdn'],
  Integer $grafana_port = 3000,
  Integer $grafana_timeout = 10,
  #TODO: document using task to change
  Sensitive[String] $grafana_password = Sensitive('admin'),
  String $grafana_version = '8.5.20',
  String $grafana_datasource = 'influxdb_puppet',
  String $grafana_install = $facts['os']['family'] ? {
    /(RedHat|Debian)/ => 'repo',
    default           => 'package',
  },
  String $provisioning_datasource_file = '/etc/grafana/provisioning/datasources/influxdb.yaml',
  Boolean $use_ssl = $puppet_operational_dashboards::use_ssl,
  Boolean $manage_grafana = true,
  Boolean $manage_grafana_repo = true,
  String $influxdb_host = $puppet_operational_dashboards::influxdb_host,
  Integer $influxdb_port = $puppet_operational_dashboards::influxdb_port,
  String $influxdb_bucket = $puppet_operational_dashboards::initial_bucket,
  String $telegraf_token_name = $puppet_operational_dashboards::telegraf_token_name,
  String $influxdb_token_file = $puppet_operational_dashboards::influxdb_token_file,
  Boolean $include_pe_metrics = $puppet_operational_dashboards::include_pe_metrics,
  Boolean $manage_system_board = $puppet_operational_dashboards::manage_system_board,
  Enum['v1', 'v2', 'all'] $system_dashboard_version = 'v2',
) {
  $grafana_url = "http://${grafana_host}:${grafana_port}"

  $protocol = $use_ssl ? {
    true  => 'https',
    false => 'http',
  }
  $influxdb_uri = "${protocol}://${influxdb_host}:${influxdb_port}"

  if $manage_grafana {
    class { 'grafana':
      install_method      => $grafana_install,
      version             => $grafana_version,
      manage_package_repo => $manage_grafana_repo,
    }

    if $facts['os']['family'] == 'Debian' {
      # Workaround to override the key id for the Grafana apt source
      Apt::Source <| title == 'grafana' |> {
        key => {
          'id'     => '0E22EB88E39E12277A7760AE9E439B102CF3C0C6',
          'source' => 'https://apt.grafana.com/gpg.key',
        },
      }
    }

    file { 'grafana-conf-d':
      ensure => directory,
      path   => '/etc/systemd/system/grafana-server.service.d',
    }
    file { 'wait-for-grafana':
      ensure    => file,
      path      => '/etc/systemd/system/grafana-server.service.d/wait.conf',
      subscribe => Exec['puppet_grafana_daemon_reload'],
      content   => epp('puppet_operational_dashboards/grafana_wait.epp', { timeout => $grafana_timeout }),
    }

    exec { 'puppet_grafana_daemon_reload':
      command     => 'systemctl daemon-reload',
      path        => ['/bin', '/usr/bin'],
      refreshonly => true,
      notify      => Service['grafana-server'],
    }

    # Require the install class for any dashboards when managing Grafana
    Grafana_dashboard {
      require => Class['grafana::install'],
    }

    if $token {
      file { 'grafana_provisioning_datasource':
        ensure  => file,
        path    => $provisioning_datasource_file,
        mode    => '0600',
        owner   => 'grafana',
        content => inline_epp(file('puppet_operational_dashboards/datasource.epp'), {
            name     => $grafana_datasource,
            token    => $token,
            database => $influxdb_bucket,
            url      => $influxdb_uri,
        }),
        require => Class['grafana::install'],
        notify  => Service['grafana-server'],
      }
    }
    else {
      $token_vars = {
        name     => $grafana_datasource,
        token => Sensitive(Deferred('influxdb::retrieve_token', [$influxdb_uri, $telegraf_token_name, $influxdb_token_file])),
        database => $influxdb_bucket,
        url      => $influxdb_uri,
      }

      file { $provisioning_datasource_file:
        ensure  => file,
        mode    => '0600',
        owner   => 'grafana',
        content => Deferred('inline_epp',
        [file('puppet_operational_dashboards/datasource.epp'), $token_vars]),
        require => Class['grafana::install'],
        notify  => Service['grafana-server'],
      }
    }
  }

  ['Puppetserver', 'Puppetdb', 'Postgresql'].each |$service| {
    grafana_dashboard { "${service} Performance":
      grafana_user     => 'admin',
      grafana_password => $grafana_password.unwrap,
      grafana_url      => $grafana_url,
      content          => file("puppet_operational_dashboards/${service}_performance.json"),
    }
  }

  $ensure_system_performance =  $manage_system_board ? {
    true    => 'present',
    default => 'absent',
  }
  $system_dashboards = $system_dashboard_version ? {
    'all' => ['System', 'System_v2'],
    'v1'  => ['System'],
    'v2'  => ['System_v2'],
  }

  # ensure => absent should remove both versions of the system performance dashboards
  if $ensure_system_performance == 'absent' {
    ['System Performance', 'System_v2 Performance'].each |$board| {
      grafana_dashboard { $board:
        ensure           => 'absent',
        grafana_user     => 'admin',
        grafana_password => $grafana_password.unwrap,
        grafana_url      => $grafana_url,
        content          => '{}',
      }
    }
  }
  else {
    $system_dashboards.each |$board| {
      grafana_dashboard { "${board} Performance":
        ensure           => present,
        grafana_user     => 'admin',
        grafana_password => $grafana_password.unwrap,
        grafana_url      => $grafana_url,
        content          => file("puppet_operational_dashboards/${board}_performance.json"),
      }
    }
  }

  if $include_pe_metrics {
    ['Filesync', 'Orchestrator'].each |$pe_service| {
      grafana_dashboard { "${pe_service} Performance":
        grafana_user     => 'admin',
        grafana_password => $grafana_password.unwrap,
        grafana_url      => $grafana_url,
        content          => file("puppet_operational_dashboards/${pe_service}_performance.json"),
      }
    }
  }
  else {
    ['Filesync', 'Orchestrator'].each |$pe_service| {
      grafana_dashboard { "${pe_service} Performance":
        ensure           => absent,
        grafana_user     => 'admin',
        grafana_password => $grafana_password.unwrap,
        grafana_url      => $grafana_url,
      }
    }
  }
}