Created
July 7, 2017 17:00
-
-
Save shudarshon/1d39af3b800959d3c6f5d5802dd5f4d3 to your computer and use it in GitHub Desktop.
This script Goaccess in Ubuntu 16.04 in automated way. Goaccess is used for web server metric monitoring from command line to webpage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fabric.api import * | |
from fabric.operations import * | |
from fabric.contrib.project import rsync_project | |
from fabric.contrib.files import exists | |
import sys, os | |
abspath = lambda filename: os.path.join( | |
os.path.abspath(os.path.dirname(__file__)), | |
filename | |
) | |
# -------------------------------------------- | |
# Goaccess cofiguration | |
# -------------------------------------------- | |
class FabricException(Exception): | |
pass | |
def dev(): | |
print "Connecting to remote machine" | |
env.setup = True | |
env.user = 'ubuntu' | |
env.ubuntu_version = '16.04' | |
env.warn_only = True | |
env.password = 'ubuntu' | |
#env.key_filename = abspath('ec2-key.pem') | |
env.hosts = [ | |
'192.168.0.118' | |
] | |
env.port_number = '7890' | |
env.output_prefix = False | |
env.graceful = False | |
env.target_website = "elk.inov.io" | |
env.nginx_config = "nginx.conf" | |
env.rsync_exclude = [ | |
"*.py", | |
"*.pyc" | |
] | |
return | |
def install(): | |
print 'Start installing Goaccess' | |
update() | |
install_goaccess_dependency() | |
install_nginx() | |
install_goaccess_from_ppa() | |
config_goaccess() | |
#config_nginx() | |
print 'Finished installing GoAccess' | |
return | |
def update(): | |
print 'Start updating the system' | |
sudo('apt-get update') | |
def install_goaccess_dependency(): | |
print 'Installing goaccess dependency' | |
sudo("apt-get install libncursesw5-dev -y") | |
sudo("apt-get install libgeoip-dev -y") | |
sudo("apt-get install libtokyocabinet-dev -y") | |
sudo("apt-get install libssl-dev -y") | |
sudo("apt-get install gcc -y") | |
sudo("apt-get install make -y") | |
sudo("apt-get install apt-transport-https -y") | |
def install_nginx(): | |
print 'Installing NGINX' | |
sudo("apt-get install -y nginx") | |
def install_goaccess_from_source(): | |
print 'Starting to install goaccess' | |
with cd('/home/%s' %(env.user)): | |
sudo("wget http://tar.goaccess.io/goaccess-1.2.tar.gz") | |
sudo("tar -xzvf goaccess-1.2.tar.gz") | |
with prefix('cd goaccess-1.2/'): | |
sudo("./configure --enable-utf8 --enable-geoip=legacy") | |
sudo("make") | |
sudo("make install") | |
sudo("rm ../goaccess-1.2.tar.gz") | |
print("Deleted goaccess tarball") | |
def install_goaccess_from_ppa(): | |
print 'Starting to install goaccess' | |
sudo('echo "deb http://deb.goaccess.io/ $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list.d/goaccess.list') | |
sudo("wget -O - https://deb.goaccess.io/gnugpg.key | sudo apt-key add -") | |
update() | |
sudo("apt-get install goaccess -y") | |
def config_goaccess(): | |
print 'Generating goaccess realtime HTML file' | |
sudo('mkdir -p /var/www/html') | |
sudo('chown -R %s:%s /var/www/' %(env.user, env.user)) | |
sudo('chmod 755 /var/www/') | |
default_config='/usr/local/etc/goaccess.conf' | |
if exists(default_config): | |
sudo('goaccess -f /var/log/nginx/access.log -a -o /var/www/html/report.html --real-time-html --ws-url=%s -p /usr/local/etc/goaccess.conf --log-format=COMBINED' %(env.target_website)) | |
else: | |
sudo('goaccess -f /var/log/nginx/access.log -o /var/www/html/report.html --real-time-html --ws-url=%s --log-format=COMBINED' %(env.target_website)) | |
def config_nginx(): | |
print 'Configuring NGINX' | |
default_config='/etc/nginx/sites-enabled/nginx.conf' | |
if exists(default_config): | |
sudo('rm /etc/nginx/sites-enabled/nginx.conf') | |
print 'Deleted NGINX default config' | |
print 'Install NGINX config' | |
put('%s' % (env.nginx_config), '/etc/nginx/sites-enabled/', use_sudo=True) | |
print 'Restarting NGINX' | |
sudo("systemctl stop nginx") | |
sudo("systemctl start nginx") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80 backlog 4096; | |
server_name elk.inov.io; | |
location / { | |
root /var/www/html/; | |
index report.html; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment