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 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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
|
Deployment
==========
There are several options available, depending on your setup.
Gunicorn + nginx
----------------
First, you need to install Gunicorn. The easiest way is to use ``pip``::
$ pip install gunicorn
If you have installed Graphite-API in a virtualenv, install Gunicorn in the
same virtualenv::
$ /usr/share/python/graphite/bin/pip install gunicorn
Next, create the script that will run Graphite-API using your process watcher
of choice.
*Upstart*
::
description "Graphite-API server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec gunicorn -w2 graphite_api.app:app -b 127.0.0.1:8888
*Supervisor*
::
[program:graphite-api]
command = gunicorn -w2 graphite_api.app:app -b 127.0.0.1:8888
autostart = true
autorestart = true
*systemd*
::
# This is /etc/systemd/system/graphite-api.socket
[Unit]
Description=graphite-api socket
[Socket]
ListenStream=/run/graphite-api.sock
ListenStream=127.0.0.1:8888
[Install]
WantedBy=sockets.target
::
# This is /etc/systemd/system/graphite-api.service
[Unit]
Description=Graphite-API service
Requires=graphite-api.socket
[Service]
ExecStart=/usr/bin/gunicorn -w2 graphite_api.app:app
Restart=on-failure
#User=graphite
#Group=graphite
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
.. note::
If you have installed Graphite-API and Gunicorn in a virtualenv, you
need to use the full path to Gunicorn. Instead of ``gunicorn``, use
``/usr/share/python/graphite/bin/gunicorn`` (assuming your virtualenv is
at ``/usr/share/python/graphite``).
See the `Gunicorn docs`_ for configuration options and command-line flags.
.. _Gunicorn docs: http://docs.gunicorn.org/en/latest/
Finally, configure the nginx vhost:
.. code-block:: nginx
# /etc/nginx/sites-available/graphite.conf
upstream graphite {
server 127.0.0.1:8888 fail_timeout=0;
}
server {
server_name graph;
listen 80 default;
root /srv/www/graphite;
location / {
try_files $uri @graphite;
}
location @graphite {
proxy_pass http://graphite;
}
}
Enable the vhost and restart nginx::
$ ln -s /etc/nginx/sites-available/graphite.conf /etc/nginx/sites-enabled
$ service nginx restart
Apache + mod_wsgi
-----------------
First, you need to install mod_wsgi.
See the `mod_wsgi InstallationInstructions`_ for installation instructions.
.. _mod_wsgi InstallationInstructions: https://code.google.com/p/modwsgi/wiki/InstallationInstructions
Then create the graphite-api.wsgi:
.. code-block:: bash
# /var/www/wsgi-scripts/graphite-api.wsgi
from graphite_api.app import app as application
Finally, configure the apache vhost:
.. code-block:: apache
# /etc/httpd/conf.d/graphite.conf
LoadModule wsgi_module modules/mod_wsgi.so
WSGISocketPrefix /var/run/wsgi
Listen 8013
<VirtualHost *:8013>
WSGIDaemonProcess graphite-api processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120
WSGIProcessGroup graphite-api
WSGIApplicationGroup %{GLOBAL}
WSGIImportScript /var/www/wsgi-scripts/graphite-api.wsgi process-group=graphite-api application-group=%{GLOBAL}
WSGIScriptAlias / /var/www/wsgi-scripts/graphite-api.wsgi
<Directory /var/www/wsgi-scripts/>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Adapt the mod_wsgi configuration to your requirements.
See the `mod_wsgi QuickConfigurationGuide`_ for an overview of configurations and `mod_wsgi ConfigurationDirectives`_ to see all configuration directives
.. _mod_wsgi QuickConfigurationGuide: https://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
.. _mod_wsgi ConfigurationDirectives: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives
Restart apache::
$ service httpd restart
Docker
------
Create a ``graphite-api.yaml`` configuration file with your desired config.
Create a ``Dockerfile``::
FROM brutasse/graphite-api
Build your container::
docker build -t graphite-api .
Run it::
docker run -t -i -p 8888:8888 graphite-api
``/srv/graphite`` is a docker ``VOLUME``. You can use that to provide whisper
data from the host (or from another docker container) to the graphite-api
container::
docker run -t -i -v /path/to/graphite:/srv/graphite -p 8888:8888 graphite-api
This container has all the :ref:`extra packages <extras>` included. Cyanite
backend and Sentry integration are available.
Nginx + uWSGI
-------------
First, you need to install uWSGI with Python support. On Debian, install ``uwsgi-plugin-python``.
Then create the uWSGI file for Graphite-API in
``/etc/uwsgi/apps-available/graphite-api.ini``:
.. code-block:: ini
[uwsgi]
processes = 2
socket = localhost:8080
plugins = python27
module = graphite_api.app:app
If you installed Graphite-API in a virtualenv, specify the virtualenv path:
.. code-block:: ini
home = /var/www/wsgi-scripts/env
If you need a custom location for Graphite-API's config file, set the
environment variable like this:
.. code-block:: ini
env = GRAPHITE_API_CONFIG=/var/www/wsgi-scripts/config.yml
Enable ``graphite-api.ini`` and restart uWSGI:
.. code-block:: bash
$ ln -s /etc/uwsgi/apps-available/graphite-api.ini /etc/uwsgi/apps-enabled
$ service uwsgi restart
Finally, configure the nginx vhost:
.. code-block:: nginx
# /etc/nginx/sites-available/graphite.conf
server {
listen 80;
location / {
include uwsgi_params;
uwsgi_pass localhost:8080;
}
}
Enable the vhost and restart nginx:
.. code-block:: bash
$ ln -s /etc/nginx/sites-available/graphite.conf /etc/nginx/sites-enabled
$ service nginx restart
Other deployment methods
------------------------
They currently aren't described here but there are several other ways to serve
Graphite-API:
* nginx + circus + chaussette
If you feel like contributing some documentation, feel free to open pull a
request on the `Graphite-API repository`_.
.. _Graphite-API repository: https://github.com/brutasse/graphite-api
|