Puppet Plan: puppet_operational_dashboards::load_metrics
- Defined in:
- plans/load_metrics.pp
Summary
A plan created with bolt plan new.Overview
The summary sets the description of the plan that will appear in ‘bolt plan show’ output. Bolt uses puppet-strings to parse the summary and parameters from the plan.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'plans/load_metrics.pp', line 33
plan puppet_operational_dashboards::load_metrics (
TargetSpec $targets,
Optional[String] $metrics_dir = undef,
Optional[String] $support_script_file = undef,
String $influxdb_org = 'puppetlabs',
String $influxdb_bucket = 'influxdb_puppet',
Integer $influxdb_port = 8086,
String $grafana_datasource = $influxdb_bucket,
String $telegraf_token = 'puppet telegraf token',
String $token_file = '/root/.influxdb_token',
String $conf_dir = '/tmp/telegraf',
# 40 day default for bucket retention
Array[Hash] $retention_rules = [{
'type' => 'expire',
'everySeconds' => 3456000,
'shardGroupDurationSeconds' => 604800,
}],
#TODO
Enum['local', 'remote'] $telegraf_process = 'remote',
String $dest_dir = '/tmp',
#TODO
Optional[String] $token = undef,
String $cleanup_metrics = 'true',
) {
unless get_targets($targets).size == 1 {
fail_plan('This plan only accepts a single target.')
}
unless $metrics_dir or $support_script_file {
fail_plan('Must specify one of $metrics_dir or $support_script_file')
}
if $metrics_dir and $support_script_file {
fail_plan('$metrics_dir and $support_script_file are mutually exclusive')
}
# Handle being passed a String or a Target
$target = get_targets($targets)[0].name
$target.apply_prep
apply ($target) {
$token_vars = {
name => $grafana_datasource,
token => Sensitive(Deferred('influxdb::retrieve_token', ["http://${target}:8086", $telegraf_token, $token_file])),
database => $influxdb_bucket,
url => "http://${target}:8086",
}
influxdb_org { $influxdb_org:
ensure => present,
use_ssl => false,
}
influxdb_bucket { $influxdb_bucket:
ensure => present,
use_ssl => false,
org => $influxdb_org,
token_file => $token_file,
retention_rules => $retention_rules,
require => Influxdb_org[$influxdb_org],
}
service { 'grafana-server':
ensure => running,
}
file { "/etc/grafana/provisioning/datasources/${influxdb_bucket}.yaml":
ensure => file,
mode => '0600',
owner => 'grafana',
content => Deferred('inline_epp',
[file('puppet_operational_dashboards/datasource.epp'), $token_vars]),
notify => Service['grafana-server'],
}
$telegraf_vars = {
bucket => $influxdb_bucket,
org => $influxdb_org,
port => $influxdb_port,
host => $target,
token => Sensitive(Deferred('influxdb::retrieve_token', ["http://${target}:8086", $telegraf_token, $token_file])),
}
file { $conf_dir:
ensure => directory,
}
file { "${conf_dir}/telegraf.conf":
ensure => file,
content => Deferred('inline_epp', [file('puppet_operational_dashboards/telegraf.conf'), $telegraf_vars]),
}
file { "${conf_dir}/telegraf.conf.d":
ensure => directory,
}
file { "${conf_dir}/sar2influx.rb":
ensure => file,
mode => '0775',
source => 'puppet:///modules/puppet_operational_dashboards/plan_files/sar2influx.rb',
}
# These are special because we don't want to load both and therefore don't write them to conf.d
[
'sar.conf',
'system_sar.conf',
].each |$script| {
file { "${conf_dir}/${script}":
ensure => file,
source => "puppet:///modules/puppet_operational_dashboards/plan_files/${script}",
}
}
[
'postgres.conf',
'puppetdb.conf',
'puppetserver.conf',
'system_cpu.conf',
'system_memory.conf',
'system_procs.conf',
'orchestrator.conf',
].each |$script| {
file { "${conf_dir}/telegraf.conf.d/${script}":
ensure => file,
source => "puppet:///modules/puppet_operational_dashboards/plan_files/${script}",
}
}
}
if $support_script_file {
$sup_script = split($support_script_file, '/')[-1]
upload_file($support_script_file, $dest_dir, $target)
return run_script(
'puppet_operational_dashboards/plan_files/import_archives.sh',
$target,
'arguments' => ['-t', $conf_dir, '-s', "${dest_dir}/${sup_script}", '-c', $cleanup_metrics]
)
}
else {
upload_file($metrics_dir, $dest_dir, $targets)
return run_script(
'puppet_operational_dashboards/plan_files/import_archives.sh',
$targets,
'arguments' => ['-t', $conf_dir, '-m', $dest_dir, '-c', $cleanup_metrics]
)
}
}
|