From 334012fff5ce70b03b986879f71e4d2553b511df Mon Sep 17 00:00:00 2001 From: Roman Vynar Date: Mon, 30 May 2016 12:50:20 +0300 Subject: [PATCH] Switched to Nginx --- Dockerfile | 21 ++++++++++----- add-grafana-datasource.sh | 2 +- docker-compose.yml | 5 +--- grafana.ini | 1 + install-qan.sh | 3 --- landing-page/index.html | 10 ++------ nginx.conf | 54 +++++++++++++++++++++++++++++++++++++++ prometheus.yml | 5 ++++ supervisord.conf | 26 ++++++------------- 9 files changed, 86 insertions(+), 41 deletions(-) create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile index 73fe9eba2..71bfb734a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:latest -EXPOSE 3000 9090 9001-9002 8500 80 +EXPOSE 80 9001 WORKDIR /opt @@ -13,6 +13,7 @@ RUN apt-get -y update && apt-get install -y \ curl \ git \ unzip \ + nginx \ mysql-server \ python \ supervisor @@ -21,9 +22,9 @@ RUN apt-get -y update && apt-get install -y \ # Prometheus # # ########## # -ADD https://github.com/prometheus/prometheus/releases/download/0.19.1/prometheus-0.19.1.linux-amd64.tar.gz /opt/ +ADD https://github.com/prometheus/prometheus/releases/download/0.19.2/prometheus-0.19.2.linux-amd64.tar.gz /opt/ RUN mkdir prometheus && \ - tar xfz prometheus-0.19.1.linux-amd64.tar.gz --strip-components=1 -C prometheus + tar xfz prometheus-0.19.2.linux-amd64.tar.gz --strip-components=1 -C prometheus COPY prometheus.yml /opt/prometheus/ # ####### # @@ -50,13 +51,13 @@ RUN chgrp grafana /etc/grafana/grafana.ini && \ # Percona Query Analytics # # ####################### # -ADD https://www.percona.com/downloads/TESTING/pmm/percona-qan-api-1.0.0-x86_64.tar.gz \ - https://www.percona.com/downloads/TESTING/pmm/percona-qan-app-1.0.0.tar.gz \ +ADD https://www.percona.com/downloads/TESTING/pmm/percona-qan-api.tar.gz \ + https://www.percona.com/downloads/TESTING/pmm/percona-qan-app.tar.gz \ /opt/ RUN mkdir qan-api && \ - tar zxf percona-qan-api-1.0.0-x86_64.tar.gz --strip-components=1 -C qan-api && \ + tar zxf percona-qan-api.tar.gz --strip-components=1 -C qan-api && \ mkdir qan-app && \ - tar zxf percona-qan-app-1.0.0.tar.gz --strip-components=1 -C qan-app + tar zxf percona-qan-app.tar.gz --strip-components=1 -C qan-app COPY install-qan.sh /opt RUN /opt/install-qan.sh @@ -72,6 +73,12 @@ ADD https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip /op RUN unzip consul_0.6.4_linux_amd64.zip && \ mkdir -p /opt/consul-data +# ##### # +# Nginx # +# ##### # + +COPY nginx.conf /etc/nginx + # ############ # # Landing page # # ############ # diff --git a/add-grafana-datasource.sh b/add-grafana-datasource.sh index 45261dfa9..76d9e179b 100755 --- a/add-grafana-datasource.sh +++ b/add-grafana-datasource.sh @@ -4,7 +4,7 @@ service grafana-server start for i in `seq 30`; do if curl -s http://admin:admin@localhost:3000/api/datasources; then - curl http://admin:admin@localhost:3000/api/datasources -X POST -H 'Content-Type: application/json' --data-binary '{"name":"Prometheus","type":"prometheus","url":"http://localhost:9090","access":"proxy","isDefault":true}' + curl http://admin:admin@localhost:3000/api/datasources -X POST -H 'Content-Type: application/json' --data-binary '{"name":"Prometheus","type":"prometheus","url":"http://localhost:9090/prometheus/","access":"proxy","isDefault":true}' echo "Added Prometheus data source to Grafana" break else diff --git a/docker-compose.yml b/docker-compose.yml index f8d96d6c3..67a893468 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,10 +16,7 @@ services: container_name: pmm-server image: percona/pmm-server ports: - - "9001-9002:9001-9002" - - "3000:3000" - - "9090:9090" - - "8500:8500" + - "9001:9001" - "80:80" volumes_from: - pmm-data diff --git a/grafana.ini b/grafana.ini index 8d14a34e9..ca9b9ecef 100644 --- a/grafana.ini +++ b/grafana.ini @@ -41,6 +41,7 @@ # The full public facing url ;root_url = %(protocol)s://%(domain)s:%(http_port)s/ +root_url = %(protocol)s://%(domain)s:%(http_port)s/graph # Log web requests ;router_logging = false diff --git a/install-qan.sh b/install-qan.sh index b53e082de..2863c6a8d 100755 --- a/install-qan.sh +++ b/install-qan.sh @@ -8,6 +8,3 @@ service mysql start cd /opt/qan-api START="no" SYSINT="no" ./install - -cd /opt/qan-app -START="no" SYSINT="no" LISTEN="0.0.0.0:9002" ./install diff --git a/landing-page/index.html b/landing-page/index.html index b3f23035c..25ccf5fa8 100644 --- a/landing-page/index.html +++ b/landing-page/index.html @@ -81,14 +81,8 @@

Tell Us What You Think

diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 000000000..c37878352 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,54 @@ +user www-data; +worker_processes 4; +pid /run/nginx.pid; + +events { + worker_connections 768; +} + +http { + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + include /etc/nginx/mime.types; + default_type application/octet-stream; + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + gzip on; + server { + listen *:80; + server_name _; + server_tokens off; + root /opt/landing-page; + + # Grafana + rewrite ^/graph$ /graph/; + location /graph { + proxy_pass http://localhost:3000; + rewrite ^/graph/(.*) /$1 break; + } + + # Prometheus + location /prometheus { + proxy_pass http://localhost:9090; + } + + # Consul UI + location /consul/ { + proxy_pass http://localhost:8500/ui/; + } + + # Consul API + location /v1/ { + proxy_pass http://localhost:8500/v1/; + } + + # QAN App + location /qan { + alias /opt/qan-app; + } + } +} + diff --git a/prometheus.yml b/prometheus.yml index 2ab05a427..cfcadb933 100644 --- a/prometheus.yml +++ b/prometheus.yml @@ -5,6 +5,7 @@ global: scrape_configs: - job_name: prometheus + metrics_path: /prometheus/metrics target_groups: - targets: ['localhost:9090'] @@ -31,6 +32,10 @@ scrape_configs: regex: '.*,cluster_(\w+),.*' target_label: 'cluster' replacement: '$1' + - source_labels: ['__meta_consul_tags'] + regex: '.*,nodetype_(\w+),.*' + target_label: 'nodetype' + replacement: '$1' - job_name: mysql-hr diff --git a/supervisord.conf b/supervisord.conf index 421e42eb6..c8b11fa89 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -30,33 +30,23 @@ stdout_logfile = /var/log/qan-api.log stderr_logfile = /var/log/qan-api.log autorestart = true -[program:qan-app] -priority = 5 -directory = /usr/local/percona/qan-app -environment = BG=no -command = /usr/local/percona/qan-app/start -stdout_logfile = /var/log/qan-app.log -stderr_logfile = /var/log/qan-app.log -autorestart = true - -[program:landing-page] -priority = 6 -directory = /opt/landing-page -command = python -c "import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer(('0.0.0.0', 80), shs.SimpleHTTPRequestHandler).serve_forever()" -stdout_logfile = /var/log/landing-page.log -stderr_logfile = /var/log/landing-page.log +[program:nginx] +priority = 5 +command = nginx +stdout_logfile = /var/log/nginx.log +stderr_logfile = /var/log/nginx.log autorestart = true [program:cron] -priority = 7 +priority = 6 command = /usr/sbin/cron -f stdout_logfile = /var/log/cron.log stderr_logfile = /var/log/cron.log autorestart = true [program:prometheus] -priority = 8 -command = bash -c "sleep 5 && /opt/prometheus/prometheus -config.file=/opt/prometheus/prometheus.yml -storage.local.path=/opt/prometheus/data -web.listen-address=:9090 -storage.local.retention=192h -storage.local.memory-chunks=262144 -web.console.libraries=/opt/prometheus/console_libraries -web.console.templates=/opt/prometheus/consoles" +priority = 7 +command = bash -c "sleep 5 && /opt/prometheus/prometheus -config.file=/opt/prometheus/prometheus.yml -storage.local.path=/opt/prometheus/data -web.listen-address=:9090 -storage.local.retention=192h -storage.local.memory-chunks=262144 -web.console.libraries=/opt/prometheus/console_libraries -web.console.templates=/opt/prometheus/consoles -web.external-url=http://localhost:9090/prometheus/" stdout_logfile = /var/log/prometheus.log stderr_logfile = /var/log/prometheus.log autorestart = true