Puppet Class: graphite::web

Defined in:
modules/graphite/manifests/web.pp

Overview

Class: graphite::web

Configures the Graphite webapp, a Django webapp for browsing metric data and constructing graphs, with uWSGI as the application server.

Parameters

uwsgi_processes

Number of uWSGI workers to run (default: 8).

memcached_size

Size of memcached store, in megabytes (default: 200).

admin_user

Username for Django admin account (default: 'admin').

admin_pass

Password for Django admin account.

secret_key

This is used to provide cryptographic signing, and should be set to a unique, unpredictable value.

storage_dir

Carbon storage directory. This is where the app will look for whisper databases.

documentation_url

Overrides the Documentation link used in the header of the Graphite Composer (default: 'graphite.readthedocs.org/').

remote_user_auth

If true, enable authentication via REMOTE_USER. See <docs.djangoproject.com/en/1.8/howto/auth-remote-user/>.

cors_origins

An optional array of HTTP Origin header values or regexp patterns for which graphite-web should set CORS headers.

cluster_servers

An optional array of servers running graphite-web to be queried for metrics.

uwsgi_max_request_duration_seconds

If specified, have uwsgi kill a worker that takes longer than this to execute a request.

uwsgi_max_request_rss_megabytes

If specified, have uwsgi kill a worker whose RSS exceeds this value.

Parameters:

  • admin_pass (Any)
  • secret_key (Any)
  • storage_dir (Any)
  • uwsgi_processes (Any) (defaults to: 8)
  • memcached_size (Any) (defaults to: 200)
  • admin_user (Any) (defaults to: 'admin')
  • documentation_url (Any) (defaults to: 'http://graphite.readthedocs.org/')
  • remote_user_auth (Any) (defaults to: false)
  • cors_origins (Any) (defaults to: undef)
  • cluster_servers (Any) (defaults to: undef)
  • uwsgi_max_request_duration_seconds (Any) (defaults to: undef)
  • uwsgi_max_request_rss_megabytes (Any) (defaults to: undef)


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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'modules/graphite/manifests/web.pp', line 50

class graphite::web(
    $admin_pass,
    $secret_key,
    $storage_dir,
    $uwsgi_processes   = 8,
    $memcached_size    = 200,
    $admin_user        = 'admin',
    $documentation_url = 'http://graphite.readthedocs.org/',
    $remote_user_auth  = false,
    $cors_origins      = undef,
    $cluster_servers   = undef,
    $uwsgi_max_request_duration_seconds = undef,
    $uwsgi_max_request_rss_megabytes = undef,
) {
    include ::graphite

    validate_bool($remote_user_auth)

    require_package('memcached')

    $python_version = $::lsbdistcodename ? {
        buster  => 'python3',
        stretch => 'python',
        jessie  => 'python',
    }

    require_package("${python_version}-memcache")
    require_package('libapache2-mod-uwsgi')

    if os_version('debian < buster') {
        package { 'graphite-web':
            ensure          => 'present',
            install_options => ['-t', "${::lsbdistcodename}-backports"],
        }
    } else {
        require_package('graphite-web')
    }

    file { '/etc/graphite/cors.py':
        source  => 'puppet:///modules/graphite/cors.py',
        require => Package['graphite-web'],
        notify  => Service['uwsgi-graphite-web'],
    }

    file { '/etc/graphite/local_settings.py':
        content => template('graphite/local_settings.py.erb'),
        require => Package['graphite-web'],
        notify  => Service['uwsgi-graphite-web'],
    }


    file { [ '/var/lib/graphite-web', '/var/log/graphite-web' ]:
        ensure  => directory,
        owner   => 'www-data',
        group   => 'www-data',
        mode    => '0755',
        require => Package['graphite-web'],
    }

    # django 1.9 compat, remove once the jessie -> stretch or buster migration is completed
    $syncdb_command = $::lsbdistcodename ? {
        buster  => '/usr/bin/graphite-manage migrate --run-syncdb --noinput',
        stretch  => '/usr/bin/graphite-manage migrate --run-syncdb --noinput',
        jessie  => '/usr/bin/graphite-manage syncdb --noinput',
    }

    exec { 'graphite_syncdb':
        command   => $syncdb_command,
        user      => 'www-data',
        subscribe => File['/etc/graphite/local_settings.py'],
        creates   => '/var/lib/graphite-web/graphite.db',
        require   => [
            Package['graphite-web', "${python_version}-memcache"],
            File['/var/lib/graphite-web'],
        ],
    }

    file { '/etc/memcached.conf':
        content => template('graphite/memcached.conf.erb'),
        require => Package['memcached'],
    }

    service { 'memcached':
        ensure    => running,
        enable    => true,
        require   => Package['memcached'],
        subscribe => File['/etc/memcached.conf'],
    }

    uwsgi::app { 'graphite-web':
        settings => {
            # uwsgi::app will happily generate a config with 'key=undef' in the ini file.
            # So, some messy stuff to only include our optional configuration settings iff
            # they are provided.
            uwsgi => merge({
                'plugins'   => $python_version,
                'socket'    => '/run/uwsgi/graphite-web.sock',
                'stats'     => '/run/uwsgi/graphite-web-stats.sock',
                'wsgi-file' => '/usr/share/graphite-web/graphite.wsgi',
                'master'    => true,
                'processes' => $uwsgi_processes,
            },
            if $uwsgi_max_request_duration_seconds != undef  { {'harakiri' => $uwsgi_max_request_duration_seconds} },
            if $uwsgi_max_request_rss_megabytes != undef     { {'evil-reload-on-rss' => $uwsgi_max_request_rss_megabytes} })
        },
        routes   => [ # do not cache renders
            {'route' => '^/render', 'action' => 'delheader:Cache-Control'},
            {'route' => '^/render', 'action' => 'addheader:Cache-Control: no-store'},
        ],
        require  => File['/var/log/graphite-web'],
    }

    file { '/usr/local/sbin/graphite-index':
        source  => "puppet:///modules/graphite/graphite-index.${::lsbdistcodename}.py",
        mode    => '0555',
        require => Uwsgi::App['graphite-web'],
    }

    file { '/usr/local/sbin/graphite-auth':
        source  => "puppet:///modules/graphite/graphite-auth.${::lsbdistcodename}.py",
        mode    => '0555',
        require => Uwsgi::App['graphite-web'],
    }

    cron { 'update_graphite_index':
        command => '/usr/local/sbin/graphite-index',
        user    => 'www-data',
        hour    => '*',
        minute  => '*/5',
        require => File['/usr/local/sbin/graphite-index'],
    }

    exec { 'create_graphite_admin':
        command => "/usr/local/sbin/graphite-auth set ${admin_user} ${admin_pass}",
        unless  => "/usr/local/sbin/graphite-auth check ${admin_user} ${admin_pass}",
        user    => 'www-data',
        require => File['/usr/local/sbin/graphite-auth'],
    }

    logrotate::rule { 'graphite-web':
        file_glob   => '/var/log/graphite-web/*.log',
        frequency   => 'daily',
        compress    => true,
        size        => '100M',
        rotate      => 3,
        missing_ok  => true,
        post_rotate => '/usr/sbin/service uwsgi-graphite-web restart > /dev/null',
    }

}