class exporters::postgres_exporter ( String $db_pass, String $db_user = 'postgres_exporter', Stdlib::Host $db_host = $facts['networking']['ip'], Stdlib::Port $db_port = 5432, Boolean $enable = false, String $user = 'postgres_exporter', String $group = 'postgres_exporter', Boolean $manage_user = true, Boolean $manage_service = true, Stdlib::Port $port = 9187, Stdlib::Absolutepath $exec_path = '/usr/bin/postgres_exporter', Stdlib::Absolutepath $vars_path = '/etc/sysconfig/postgres_exporter', Boolean $cleanup_old_postgres_exporter = false, ){ if $cleanup_old_postgres_exporter { # remove the symlink file {'/usr/local/bin/postgres_exporter': ensure => absent } # remove the /opt/postgres_exporter-0.5.1.linux-amd64 directory file {'/opt/postgres_exporter-0.5.1.linux-amd64': ensure => absent, recurse => true, force => true, } } if $enable { # install required package package {'postgres_exporter': ensure => installed, } # manage the user/group if $manage_user { group { $group: ensure => present, } user { $user: ensure => present, shell => '/usr/sbin/nologin', groups => $group, managehome => true, } } # manage the environment file file { $vars_path: ensure => file, owner => 'root', group => 'root', mode => '0644', content => template('exporters/postgres_exporter_sysconfig.erb') } # manage the systemd service if $manage_service { # Use these in notifications or file resources systemd::unit_file { 'postgres_exporter.service': content => template('exporters/postgres_exporter.service.erb'), enable => true, active => true, subscribe => Package['postgres_exporter'], } } # manage consul service consul::service { 'postgres_exporter': service_name => 'postgres_exporter', address => $facts['networking']['ip'], port => $port, tags => [ 'metrics', 'metrics_scheme=http', 'metrics_job=postgres', ], checks => [ { id => 'postgres_exporter_http_check', name => 'postgres_exporter HTTP Check', http => "http://${facts['networking']['fqdn']}:${port}", method => 'GET', tls_skip_verify => true, interval => '10s', timeout => '1s', }, ], } } }