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.2.7')

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

  • 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



49
50
51
52
53
54
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
# File 'manifests/profile/dashboards.pp', line 49

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.2.7',
  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,
) {
  $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,
    }

    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', 'Filesync', 'System'].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"),
    }
  }
}