Skip to content

Commit

Permalink
Switched to Nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-vynar committed May 30, 2016
1 parent 193955f commit 334012f
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 41 deletions.
21 changes: 14 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:latest

EXPOSE 3000 9090 9001-9002 8500 80
EXPOSE 80 9001

WORKDIR /opt

Expand All @@ -13,6 +13,7 @@ RUN apt-get -y update && apt-get install -y \
curl \
git \
unzip \
nginx \
mysql-server \
python \
supervisor
Expand All @@ -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/

# ####### #
Expand All @@ -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

Expand All @@ -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 #
# ############ #
Expand Down
2 changes: 1 addition & 1 deletion add-grafana-datasource.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions grafana.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions install-qan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 2 additions & 8 deletions landing-page/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,8 @@ <h2 class="margin-top-0 wow fadeIn">Tell Us What You Think</h2>
<script src="js/jquery-2.2.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var hostname = window.location.hostname;
if (hostname) {
$("#qanURL").attr("href", "http://"+hostname+":9002");
$("#grafURL").attr("href", "http://"+hostname+":3000");
} else {
$("#qanURL").attr("href", "http://localhost:9002");
$("#grafURL").attr("href", "http://localhost:3000");
}
$("#qanURL").attr("href", "/qan/");
$("#grafURL").attr("href", "/graph");
});
</script>

Expand Down
54 changes: 54 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

5 changes: 5 additions & 0 deletions prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ global:

scrape_configs:
- job_name: prometheus
metrics_path: /prometheus/metrics
target_groups:
- targets: ['localhost:9090']

Expand All @@ -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
Expand Down
26 changes: 8 additions & 18 deletions supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 334012f

Please sign in to comment.