Puppet Class: profile::wmcs::prometheus::metricsinfra

Defined in:
modules/profile/manifests/wmcs/prometheus/metricsinfra.pp

Overview

Parameters:

  • projects (Array[Hash]) (defaults to: lookup('profile::wmcs::prometheus::metricsinfra::projects'))
  • ext_fqdn (Stdlib::Fqdn) (defaults to: lookup('profile::wmcs::prometheus::metricsinfra::ext_fqdn'))
  • keystone_api_fqdn (Stdlib::Fqdn) (defaults to: lookup('profile::openstack::eqiad1::keystone_api_fqdn'))
  • observer_password (String) (defaults to: lookup('profile::openstack::eqiad1::observer_password'))
  • observer_user (String) (defaults to: lookup('profile::openstack::base::observer_user'))
  • region (String) (defaults to: lookup('profile::openstack::eqiad1::region'))


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
# File 'modules/profile/manifests/wmcs/prometheus/metricsinfra.pp', line 1

class profile::wmcs::prometheus::metricsinfra(
    Array[Hash]  $projects          = lookup('profile::wmcs::prometheus::metricsinfra::projects'),
    Stdlib::Fqdn $ext_fqdn          = lookup('profile::wmcs::prometheus::metricsinfra::ext_fqdn'),
    Stdlib::Fqdn $keystone_api_fqdn = lookup('profile::openstack::eqiad1::keystone_api_fqdn'),
    String       $observer_password = lookup('profile::openstack::eqiad1::observer_password'),
    String       $observer_user     = lookup('profile::openstack::base::observer_user'),
    String       $region            = lookup('profile::openstack::eqiad1::region'),
) {
    # Base Prometheus data and configuration path
    $base_path = '/srv/prometheus/cloud'

    # Project node-exporter scrape configuration
    $project_configs = $projects.map |Hash $project| {
        {
            'job_name'             => "${project['name']}_node",
            'openstack_sd_configs' => [
                {
                    'role'              => 'instance',
                    'region'            => $region,
                    'identity_endpoint' => "http://${keystone_api_fqdn}:5000/v3",
                    'username'          => $observer_user,
                    'password'          => $observer_password,
                    'domain_name'       => 'default',
                    'project_name'      => $project['name'],
                    'all_tenants'       => false,
                    'refresh_interval'  => '5m',
                    'port'              => 9100,
                }
            ],
            'relabel_configs'      => [
                {
                    'source_labels' => ['__meta_openstack_project_id'],
                    'replacement'   => $project['name'],
                    'target_label'  => 'project',
                },
                {
                    'source_labels' => ['job'],
                    'replacement'   => 'node',
                    'target_label'  => 'job',
                },
                {
                    'source_labels' => ['__meta_openstack_instance_name'],
                    'target_label'  => 'instance',
                },
                {
                    'source_labels' => ['__meta_openstack_instance_status'],
                    'action'        => 'keep',
                    'regex'         => 'ACTIVE',
                },
            ]
        }
    }

    prometheus::server { 'cloud':
        # Localhost is being used here to pass prometheus module input validation
        alertmanager_url     => 'localhost:9093',
        external_url         => "https://${$ext_fqdn}/cloud",
        listen_address       => '127.0.0.1:9900',
        scrape_configs_extra => $project_configs,
    }

    # Prometheus alert rules
    File<|title == "${base_path}/rules/alerts_default.yml"|> {
        source => 'puppet:///modules/profile/wmcs/prometheus/metricsinfra/alerts_default.yml',
    }

    file { "${base_path}/rules/alerts_projects.yml":
        ensure  => file,
        mode    => '0444',
        owner   => 'root',
        group   => 'root',
        source  => 'puppet:///modules/profile/wmcs/prometheus/metricsinfra/alerts_projects.yml',
        notify  => Exec['prometheus@cloud-reload'],
        require => Class['prometheus'],
    }

    # Prometheus alert manager service setup and config
    package { 'prometheus-alertmanager':
        ensure => present,
    }

    service { 'prometheus-alertmanager':
        ensure => running,
    }

    exec { 'alertmanager-reload':
        command     => '/bin/systemctl reload prometheus-alertmanager',
        refreshonly => true,
    }

    exec { 'alertmanager-restart':
        command     => '/bin/systemctl restart prometheus-alertmanager',
        refreshonly => true,
    }

    file { '/etc/default/prometheus-alertmanager':
        content => template('profile/wmcs/prometheus/metricsinfra/prometheus-alertmanager-defaults.erb'),
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
        notify  => Exec['alertmanager-restart'],
    }

    file { "${base_path}/alertmanager.yml":
        content => template('profile/wmcs/prometheus/metricsinfra/alertmanager.yml.erb'),
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
        notify  => Exec['alertmanager-reload'],
    }

    # Apache config
    class { '::httpd':
        modules => ['proxy', 'proxy_http', 'rewrite', 'headers'],
    }

    httpd::site{ 'prometheus':
        priority => 10,
        content  => template('profile/wmcs/prometheus/prometheus-apache.erb'),
    }

    prometheus::web { 'cloud':
        proxy_pass => 'http://localhost:9900/cloud',
        require    => Httpd::Site['prometheus'],
    }

    ferm::service { 'prometheus-web':
        proto  => 'tcp',
        port   => '80',
        srange => '$DOMAIN_NETWORKS',
    }
}