summaryrefslogtreecommitdiff
path: root/roles/monitoring/graphite/web
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2020-12-08 20:06:25 +0100
committerChristian Pointner <equinox@spreadspace.org>2020-12-08 20:06:25 +0100
commit785cae7ccf8c69366438a446ff121ecbb7ad5465 (patch)
treef9971024e7befb12bb2bf26277d7b8c2006c36e1 /roles/monitoring/graphite/web
parentadd role for graphite carbon-cache (diff)
add grahpite web and grafana roles
Diffstat (limited to 'roles/monitoring/graphite/web')
-rw-r--r--roles/monitoring/graphite/web/defaults/main.yml5
-rw-r--r--roles/monitoring/graphite/web/handlers/main.yml1
-rw-r--r--roles/monitoring/graphite/web/tasks/main.yml50
-rw-r--r--roles/monitoring/graphite/web/templates/nginx-vhost.conf.j220
-rw-r--r--roles/monitoring/graphite/web/templates/uwsgi-app.ini.j28
5 files changed, 84 insertions, 0 deletions
diff --git a/roles/monitoring/graphite/web/defaults/main.yml b/roles/monitoring/graphite/web/defaults/main.yml
new file mode 100644
index 00000000..167c39a1
--- /dev/null
+++ b/roles/monitoring/graphite/web/defaults/main.yml
@@ -0,0 +1,5 @@
+---
+# graphite_web_secret_key: <--- pwgen -s 64 -1
+
+graphite_web_nginx_listen: 127.0.0.1:81 default_server
+graphite_web_uwsgi_port: 3031
diff --git a/roles/monitoring/graphite/web/handlers/main.yml b/roles/monitoring/graphite/web/handlers/main.yml
new file mode 100644
index 00000000..ed97d539
--- /dev/null
+++ b/roles/monitoring/graphite/web/handlers/main.yml
@@ -0,0 +1 @@
+---
diff --git a/roles/monitoring/graphite/web/tasks/main.yml b/roles/monitoring/graphite/web/tasks/main.yml
new file mode 100644
index 00000000..7c796722
--- /dev/null
+++ b/roles/monitoring/graphite/web/tasks/main.yml
@@ -0,0 +1,50 @@
+---
+- name: instsall apt packages
+ apt:
+ name: graphite-web
+ state: present
+
+- name: configure secret key
+ lineinfile:
+ path: /etc/graphite/local_settings.py
+ regexp: '#?SECRET_KEY\s*='
+ line: "SECRET_KEY = '{{ graphite_web_secret_key }}'"
+
+- name: initialize database
+ become: yes
+ become_method: su
+ become_user: "_graphite"
+ become_flags: "-s /bin/bash"
+ command: graphite-manage migrate --run-syncdb
+ args:
+ creates: /var/lib/graphite/graphite.db
+
+- name: fix sqlite database permissions
+ file:
+ path: /var/lib/graphite/graphite.db
+ owner: "_graphite"
+ group: "_graphite"
+ mode: "0600"
+
+- name: check if uwsgi plugin python3 is installed
+ assert:
+ msg: "This role needs uwsgi with python3 plugin installed"
+ that:
+ - uwsgi_plugins is defined
+ - "'python3' in uwsgi_plugins"
+
+- name: install uwsgi app
+ vars:
+ uwsgi_app:
+ name: graphite
+ content: "{{ lookup('template', 'uwsgi-app.ini.j2') }}"
+ include_role:
+ name: uwsgi/app
+
+- name: install nginx vhost
+ vars:
+ nginx_vhost:
+ name: graphite
+ content: "{{ lookup('template', 'nginx-vhost.conf.j2') }}"
+ include_role:
+ name: nginx/vhost
diff --git a/roles/monitoring/graphite/web/templates/nginx-vhost.conf.j2 b/roles/monitoring/graphite/web/templates/nginx-vhost.conf.j2
new file mode 100644
index 00000000..48b6ef73
--- /dev/null
+++ b/roles/monitoring/graphite/web/templates/nginx-vhost.conf.j2
@@ -0,0 +1,20 @@
+server {
+ listen {{ graphite_web_nginx_listen }};
+
+ server_name _;
+
+ location / {
+ include uwsgi_params;
+ uwsgi_pass 127.0.0.1:{{ graphite_web_uwsgi_port }};
+ }
+ rewrite ^/admin(.*)admin/([^/]+)/([^/]+)$ /media/$2/$3 redirect;
+ location /media {
+ alias /usr/share/python-django-common/django/contrib/admin/static/admin/;
+ }
+ location /static/ {
+ alias /usr/share/graphite-web/static/;
+ }
+
+ access_log /var/log/nginx/access-graphite.log;
+ error_log /var/log/nginx/error-graphite.log;
+}
diff --git a/roles/monitoring/graphite/web/templates/uwsgi-app.ini.j2 b/roles/monitoring/graphite/web/templates/uwsgi-app.ini.j2
new file mode 100644
index 00000000..e5b01a04
--- /dev/null
+++ b/roles/monitoring/graphite/web/templates/uwsgi-app.ini.j2
@@ -0,0 +1,8 @@
+[uwsgi]
+plugin = python3
+processes = 2
+socket = 127.0.0.1:{{ graphite_web_uwsgi_port }}
+gid = _graphite
+uid = _graphite
+chdir = /usr/share/graphite-web
+wsgi-file = /usr/share/graphite-web/graphite.wsgi