Skip to content

Instantly share code, notes, and snippets.

@kaolian
Last active June 3, 2022 21:56
Show Gist options
  • Save kaolian/7730893 to your computer and use it in GitHub Desktop.
Save kaolian/7730893 to your computer and use it in GitHub Desktop.
from flask import Flask
from flask import request
app = Flask(__name__)
#@app.route('/<int:test_id>', methods=['GET', 'POST'])
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def index(path):
print str(request.url)
return 'hello flask'
if __name__ == '__main__':
#app.run(host='0.0.0.0', port=5000)
app.run()
# this config needs haproxy-1.1.28 or haproxy-1.2.1
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
#chroot /usr/share/haproxy
user haproxy
group haproxy
daemon
#debug
#quiet
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen appname 0.0.0.0:80
mode http
stats enable
stats uri /haproxy?stats
stats realm Strictly\ Private
#stats auth A_Username:YourPassword
#stats auth Another_User:passwd
balance roundrobin
option httpclose
option forwardfor
server node1 192.168.56.11:80 check
server node2 192.168.56.12:80 check
#!/bin/sh
echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' >> /etc/apt/sources.list
wget -O- https://download.newrelic.com/548C16BF.gpg | apt-key add -
apt-get update
apt-get -y install curl newrelic-sysmond ruby1.9.3 python-pip haproxy
cp /vagrant/files/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg
sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/haproxy
service haproxy start
nrsysmond-config --set license_key=**********************
service newrelic-sysmond start
pip install newrelic-plugin-agent
cp /vagrant/files/haproxy/newrelic_plugin_agent.cfg /etc/newrelic/newrelic_plugin_agent.cfg
newrelic_plugin_agent -c /etc/newrelic/newrelic_plugin_agent.cfg
haproxy:
name: vm-cluster-haproxy
scheme: http
host: localhost
port: 80
#verify_ssl_cert: true
path: /haproxy?stats;csv
server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /usr/share/nginx/www;
index index.html index.htm;
server_name vm-cluster-node1;
location / {
try_files $uri @uwsgi;
}
location @uwsgi {
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi.sock;
}
location /nginx_stub_status {
stub_status on;
}
}
#!/bin/sh
#add repository for newrelic
echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' >> /etc/apt/sources.list
wget -O- https://download.newrelic.com/548C16BF.gpg | apt-key add -
#install nginx newrelic uwsgi
apt-get update
apt-get -y install nginx curl newrelic-sysmond ruby1.9.3 python-pip uwsgi uwsgi-plugin-python
#start nginx
cp /vagrant/files/node1/default /etc/nginx/sites-enabled/default
service nginx start
#start uwsgi
cp /vagrant/files/node1/default.ini /etc/uwsgi/apps-available/default.ini
ln -s /etc/uwsgi/apps-available/default.ini /etc/uwsgi/apps-enabled/default.ini
mkdir -p /home/vagrant/python
cp /vagrant/files/node1/flaskproducer.py /home/vagrant/python
service uwsgi restart
#start newrelic
nrsysmond-config --set license_key=****************
service newrelic-sysmond start
#start newrelic plugin
pip install newrelic-plugin-agent
cp /vagrant/files/node1/newrelic_plugin_agent.cfg /etc/newrelic/newrelic_plugin_agent.cfg
newrelic_plugin_agent -c /etc/newrelic/newrelic_plugin_agent.cfg
[uwsgi]
chdir = /home/vagrant/python
plugin = python
socket = /tmp/uwsgi.sock
module = flaskproducer
callable = app
stats = /tmp/statsock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment