Puppet Class: profile::mediawiki::php::monitoring

Defined in:
modules/profile/manifests/mediawiki/php/monitoring.pp

Overview

Parameters:

  • prometheus_nodes (Any) (defaults to: hiera('prometheus_nodes'))
  • auth_passwd (Any) (defaults to: hiera('profile::mediawiki::php::monitoring::password'))
  • auth_salt (Any) (defaults to: hiera('profile::mediawiki::php::monitoring::salt'))
  • fcgi_port (Optional[Wmflib::UserIpPort]) (defaults to: hiera('profile::php_fpm::fcgi_port', undef))
  • fcgi_pool (String) (defaults to: hiera('profile::mediawiki::fcgi_pool', 'www'))
  • monitor_page (Boolean) (defaults to: hiera('profile::mediawiki::php::monitoring::monitor_page', true))
  • deployment_nodes (Array[String]) (defaults to: hiera('deployment_hosts', []))
  • monitor_opcache (Boolean) (defaults to: lookup('profile::mediawiki::php::monitoring::monitor_opcache', {default_value => true}))


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
# File 'modules/profile/manifests/mediawiki/php/monitoring.pp', line 1

class profile::mediawiki::php::monitoring(
    $prometheus_nodes = hiera('prometheus_nodes'),
    $auth_passwd = hiera('profile::mediawiki::php::monitoring::password'),
    $auth_salt = hiera('profile::mediawiki::php::monitoring::salt'),
    Optional[Wmflib::UserIpPort] $fcgi_port = hiera('profile::php_fpm::fcgi_port', undef),
    String $fcgi_pool = hiera('profile::mediawiki::fcgi_pool', 'www'),
    Boolean $monitor_page = hiera('profile::mediawiki::php::monitoring::monitor_page', true),
    Array[String] $deployment_nodes = hiera('deployment_hosts', []),
    Boolean $monitor_opcache = lookup('profile::mediawiki::php::monitoring::monitor_opcache', {default_value => true}),
) {
    require ::network::constants
    require ::profile::mediawiki::php
    $fcgi_proxy = mediawiki::fcgi_endpoint($fcgi_port, $fcgi_pool)
    $admin_port = 9181
    $docroot = '/var/www/php-monitoring'
    $htpasswd_file = '/etc/apache2/htpasswd.php7adm'
    $prometheus_nodes_str = join($prometheus_nodes, ' ')
    # Admin interface (and prometheus metrics) for APCu and opcache
    file { $docroot:
        ensure  => directory,
        recurse => true,
        owner   => 'root',
        group   => 'www-data',
        mode    => '0555',
        source  => 'puppet:///modules/profile/mediawiki/php/admin'
    }
    httpd::conf { 'php-admin-port':
        ensure  => present,
        content => "# This file is managed by puppet\nListen ${admin_port}\n"
    }
    httpd::site { 'php-admin':
        ensure  => present,
        content => template('profile/mediawiki/php-admin.conf.erb')
    }

    $htpasswd_string = htpasswd($auth_passwd, $auth_salt)
    file { $htpasswd_file:
        ensure  => present,
        content => "root:${htpasswd_string}\n",
        owner   => 'root',
        group   => 'www-data',
        mode    => '0440'
    }

    # Needed to allow scap to perform opcache invalidation.
    ferm::service { 'phpadmin_deployment':
        ensure => present,
        proto  => 'tcp',
        port   => $admin_port,
        srange => '$DEPLOYMENT_HOSTS',
    }

    $ferm_srange = "(@resolve((${prometheus_nodes_str})) @resolve((${prometheus_nodes_str}), AAAA))"
    ferm::service { 'prometheus-php-cache-exporter':
        proto  => 'tcp',
        port   => $admin_port,
        srange => $ferm_srange,
    }

    ## Admin script
    file { '/usr/local/bin/php7adm':
        ensure => present,
        source => 'puppet:///modules/profile/mediawiki/php/php7adm.sh',
        owner  => 'root',
        group  => 'root',
        mode   => '0555',
    }
    file { '/etc/php7adm.netrc':
        ensure  => present,
        content => "machine localhost login root password ${auth_passwd}\n",
        owner   => 'root',
        group   => 'ops',
        mode    => '0440',
    }
    ## Monitoring
    # Check that php-fpm is running
    $svc_name = "php${profile::mediawiki::php::php_version}-fpm"
    nrpe::monitor_systemd_unit_state{ $svc_name: }
    # Export basic php-fpm stats using a textfile exporter
    class { '::prometheus::node_phpfpm_statustext':
        service => "${svc_name}.service",
    }

    if $monitor_page {
        # Check that a simple page can be rendered via php-fpm.
        # If a service check happens to run while we are performing a
        # graceful restart of Apache, we want to try again before declaring
        # defeat.
        monitoring::service { 'appserver_http_php7':
            description    => 'PHP7 rendering',
            check_command  => 'check_http_wikipedia_main_php7',
            retries        => 2,
            retry_interval => 2,
            notes_url      => 'https://wikitech.wikimedia.org/wiki/Application_servers/Runbook#PHP7_rendering',
        }
    }
    else {
        # Check that the basic health check url can be rendered via php-fpm.
        monitoring::service { 'appserver_health_php7':
            description    => 'PHP7 rendering',
            check_command  => 'check_http_jobrunner_php7',
            retries        => 2,
            retry_interval => 2,
            notes_url      => 'https://wikitech.wikimedia.org/wiki/Application_servers/Runbook#PHP7_rendering',
        }
    }
    # Monitor opcache status
    file { '/usr/local/lib/nagios/plugins/nrpe_check_opcache':
        ensure => present,
        source => 'puppet:///modules/profile/mediawiki/php/nrpe_check_opcache.sh',
        owner  => 'root',
        group  => 'root',
        mode   => '0555',
    }

    if $monitor_opcache {
        nrpe::monitor_service { 'opcache':
            description  => 'PHP opcache health',
            nrpe_command => '/usr/local/lib/nagios/plugins/nrpe_check_opcache -w 100 -c 50',
            notes_url    => 'https://wikitech.wikimedia.org/wiki/Application_servers/Runbook#PHP7_opcache_health',
        }
    }
}