From 7c64e963d3ba08233d80eb19d454ef11ae62d7eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu> Date: Tue, 18 Oct 2016 16:48:16 +0200 Subject: [PATCH] Use ubicast config to configure Munin. --- 31.Install_munin/0_setup.sh | 41 +---- 31.Install_munin/http_response_time_ | 91 ---------- 31.Install_munin/nginx-cache-hit-rate | 97 ----------- 31.Install_munin/nginx-cache-multi_ | 163 ------------------ 31.Install_munin/nginx-combined | 161 ----------------- 31.Install_munin/nginx_connection_request | 154 ----------------- 31.Install_munin/nginx_error | 135 --------------- 31.Install_munin/nginx_memory | 86 --------- 31.Install_munin/nginx_upstream | 56 ------ 31.Install_munin/nginx_vhost_traffic | 103 ----------- 31.Install_munin/nginx_working_set | 38 ---- 31.Install_munin/uwsgi_ | 61 ------- 72.Deploy_munin_configuration/0_setup.sh | 18 +- .../nginx-cache-hit-rate | 97 ----------- .../nginx-cache-multi_ | 163 ------------------ 72.Deploy_munin_configuration/nginx-combined | 161 ----------------- .../nginx_connection_request | 154 ----------------- 72.Deploy_munin_configuration/nginx_error | 135 --------------- 72.Deploy_munin_configuration/nginx_memory | 86 --------- 72.Deploy_munin_configuration/nginx_upstream | 56 ------ .../nginx_vhost_traffic | 103 ----------- .../nginx_working_set | 38 ---- 22 files changed, 6 insertions(+), 2191 deletions(-) delete mode 100755 31.Install_munin/http_response_time_ delete mode 100755 31.Install_munin/nginx-cache-hit-rate delete mode 100755 31.Install_munin/nginx-cache-multi_ delete mode 100755 31.Install_munin/nginx-combined delete mode 100755 31.Install_munin/nginx_connection_request delete mode 100755 31.Install_munin/nginx_error delete mode 100755 31.Install_munin/nginx_memory delete mode 100755 31.Install_munin/nginx_upstream delete mode 100755 31.Install_munin/nginx_vhost_traffic delete mode 100755 31.Install_munin/nginx_working_set delete mode 100644 31.Install_munin/uwsgi_ delete mode 100755 72.Deploy_munin_configuration/nginx-cache-hit-rate delete mode 100755 72.Deploy_munin_configuration/nginx-cache-multi_ delete mode 100755 72.Deploy_munin_configuration/nginx-combined delete mode 100755 72.Deploy_munin_configuration/nginx_connection_request delete mode 100755 72.Deploy_munin_configuration/nginx_error delete mode 100755 72.Deploy_munin_configuration/nginx_memory delete mode 100755 72.Deploy_munin_configuration/nginx_upstream delete mode 100755 72.Deploy_munin_configuration/nginx_vhost_traffic delete mode 100755 72.Deploy_munin_configuration/nginx_working_set diff --git a/31.Install_munin/0_setup.sh b/31.Install_munin/0_setup.sh index f3d98fb2..a4aa4f82 100755 --- a/31.Install_munin/0_setup.sh +++ b/31.Install_munin/0_setup.sh @@ -1,43 +1,11 @@ #!/bin/bash source /root/envsetup/envsetup.conf -# nginx -python3 /root/envsetup/envsetup.py 7 -sed -i "s@server_name .*@server_name ${MONITOR};@" /etc/nginx/sites-available/msmonitor.conf -sed -i "s@server_name .*@server_name ${MS};@" /etc/nginx/sites-available/mediaserver-msuser.conf +# This script should be run after Nginx and Wowza setup (if they should be installed) + # munin -# uwsgi -cp uwsgi_ /usr/share/munin/plugins/uwsgi_ -chmod +x /usr/share/munin/plugins/uwsgi_ -ln -s /usr/share/munin/plugins/uwsgi_ /etc/munin/plugins/uwsgi_average -ln -s /usr/share/munin/plugins/uwsgi_ /etc/munin/plugins/uwsgi_memory -ln -s /usr/share/munin/plugins/uwsgi_ /etc/munin/plugins/uwsgi_processes -# nginx -aptitude install -y libwww-perl -echo '' >> /etc/munin/plugin-conf.d/munin-node -echo '[nginx*]' >> /etc/munin/plugin-conf.d/munin-node -echo 'env.url http://127.0.0.1/nginx_status' >> /etc/munin/plugin-conf.d/munin-node -echo 'env.ua nginx-status-verifier/0.1' >> /etc/munin/plugin-conf.d/munin-node -cp nginx* /usr/share/munin/plugins/ -ln -s /usr/share/munin/plugins/nginx-combined /etc/munin/plugins/ -ln -s /usr/share/munin/plugins/nginx_connection_request /etc/munin/plugins/ -ln -s /usr/share/munin/plugins/nginx_error /etc/munin/plugins/ -ln -s /usr/share/munin/plugins/nginx_memory /etc/munin/plugins/ -ln -s /usr/share/munin/plugins/nginx_vhost_traffic /etc/munin/plugins/ -ln -s /usr/share/munin/plugins/nginx_working_set /etc/munin/plugins/ -ln -s /usr/share/munin/plugins/nginx_request /etc/munin/plugins/nginx_request -ln -s /usr/share/munin/plugins/nginx_status /etc/munin/plugins/nginx_status -# http_response_time -cp http_response_time_ /usr/share/munin/plugins/ -chmod +x /usr/share/munin/plugins/http_response_time_ -ln -s /usr/share/munin/plugins/http_response_time_ /etc/munin/plugins/http_response_time_ms -cat << EOF >> /etc/munin/plugin-conf.d/munin-node +DEBIAN_FRONTEND=noninteractive apt-get install -y ubicast-config -[http_response_time_ms] -env.url1_url https://${FTP}/crossdomain.xml -env.url1_name videos -env.url1_label ${FTP}/crossdomain.xml -EOF # configure alerts # detect where to insert LIG=$(grep -n contact.nagios.command /etc/munin/munin.conf | awk -F ":" '{print$1}') @@ -60,7 +28,7 @@ mv /etc/munin/munin.conf.tmp /etc/munin/munin.conf # modify df function https://redmine.ubicast.net/issues/17912 sed -i "s@-P -l @-P@" /usr/share/munin/plugins/df -# new template +# new skin templates cd /etc/munin git clone https://git.ubicast.net/mediaserver/munin-monitoring-theme.git mv /etc/munin/static /etc/munin/static.orig @@ -68,6 +36,5 @@ mv /etc/munin/templates /etc/munin/templates.orig cp -pr munin-monitoring-theme/templates/munstrap/static /etc/munin/ cp -pr munin-monitoring-theme/templates/munstrap/templates /etc/munin/ # service restart -munin-node-configure --suggest service munin restart service munin-node restart diff --git a/31.Install_munin/http_response_time_ b/31.Install_munin/http_response_time_ deleted file mode 100755 index e1c4b223..00000000 --- a/31.Install_munin/http_response_time_ +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2009, devdoodles -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials provided -# with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import httplib -import os -import socket -import sys -import time -import urlparse - -request_timeout = os.getenv('request_timeout') or 10 -socket.setdefaulttimeout(float(request_timeout)) - -def load_urls(): - urls = [] - n = 1 - while 1: - url = os.getenv("url%s_url" % n) - if not url: break - data = { 'url': url } - for v in ('name', 'label', 'timeout', 'warning', 'critical'): - data[v] = os.getenv("url%s_%s" % (n, v)) - urls.append(data) - n += 1 - return urls - -def do_request(dest, host, path): - conn = httplib.HTTPConnection(dest) - conn.request('GET', path, headers={ 'Host': host }) - resp = conn.getresponse() - data = resp.read() - conn.close() - return resp.status - -urls = load_urls() - -if len(sys.argv) > 1 and sys.argv[1] == 'config': - title = os.getenv("graph_title") or "Response time" - category = os.getenv("graph_category") - draw = os.getenv("draw") - if category: print "graph_category %s" % (category,) - print "graph_title %s" % (title,) - print "graph_vlabel Time (seconds)" - print "graph_args --lower-limit 0" - print "graph_category availability" - for url in urls: - if draw: print "%s.draw %s" % (url['name'], draw) - for v in ('label', 'warning', 'critical'): - if url[v]: print "%s.%s %s" % (url['name'], v, url[v]) - sys.exit(0) - -for url in urls: - o = urlparse.urlparse(url['url']) - try: - t1 = time.time() - status = do_request(o.netloc, o.hostname, o.path) - t2 = time.time() - if status == 200: - print "%s.value %.2f" % (url['name'], t2 - t1) - else: - print "%s.value U" % (url['name'],) - except socket.timeout: - print "%s.value %s" % (url['name'], request_timeout) - except: - print "%s.value U" % (url['name'],) diff --git a/31.Install_munin/nginx-cache-hit-rate b/31.Install_munin/nginx-cache-hit-rate deleted file mode 100755 index a241a8c4..00000000 --- a/31.Install_munin/nginx-cache-hit-rate +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/perl -w - -=head1 NAME - -nginx_hitmiss - Munin plugin to show hit rate of nginx proxy cache - -=head1 APPLICABLE SYSTEMS - -nginx caching proxy - -=head1 CONFIGURATION - -File::ReadBackwards is used and must be installed. - -You can override the log file location. - - [nginx*] - env.logfile /var/log/nginx/cache-access.log - -Nginx must be configured to include "cs=$upstream_cache_status" in the -log file. Example format: - -log_format cache '$remote_addr - $host [$time_local] "$request" $status ' - '$body_bytes_sent "$http_referer" ' - 'rt=$request_time ut="$upstream_response_time" ' - 'cs=$upstream_cache_status'; - -By default the last 1000 log lines are read, you may want to change this. - -=head1 MAGIC MARKERS - - #%# family=auto - #%# capabilities=autoconf - -=head1 LICENSE - -BSD - -=cut - -use File::ReadBackwards; -my $line_counter=1000; - -my $LOG = exists $ENV{'logfile'} ? $ENV{'logfile'} - : "/var/log/nginx/cache-access.log"; - -if ( exists $ARGV[0] and $ARGV[0] eq "autoconf" ) { - unless (-r $LOG) { - print "$LOG not readable\n"; - exit 0; - } else { - print "yes\n"; - exit 0; - } -} - -if ( exists $ARGV[0] and $ARGV[0] eq "config" ) { - print "graph_title NGINX hit rates\n"; - print "graph_args -l 0 -u 100 --rigid\n"; - print "graph_category nginx\n"; - print "graph_vlabel %\n"; - print "hit.label Hits\n"; - print "hit.draw AREA\n"; - print "hit.min 0\n"; - print "hit.cdef hit,$line_counter,/,100,*\n"; - print "miss.label Misses\n"; - print "miss.draw STACK\n"; - print "miss.min 0\n"; - print "miss.cdef miss,$line_counter,/,100,*\n"; - print "expired.label Expired Objects\n"; - print "expired.draw STACK\n"; - print "expired.min 0\n"; - print "expired.cdef expired,$line_counter,/,100,*\n"; - exit 0; -} - -my ($e,$h,$m) = (0,0,0); -my $file_counter=0; - -FILE: while ($line_counter > 0) { - my $file_extension = $file_counter==0? "" : ".$file_counter"; - my $lh= File::ReadBackwards->new( "$LOG$file_extension" ) - or ( warn "$line_counter lines to read, but $LOG$file_extension: $!" - and last FILE); - $file_counter++; - while (defined ($_= $lh->readline)) { - $line_counter--; - /cs=HIT/ and $h++; - /cs=MISS/ and $m++; - /cs=EXPIRED/ and $e++; - last FILE if $line_counter==0; - } - $lh->close(); -} -print "hit.value $h\n"; -print "miss.value $m\n"; -print "expired.value $e\n"; diff --git a/31.Install_munin/nginx-cache-multi_ b/31.Install_munin/nginx-cache-multi_ deleted file mode 100755 index 3ab8046b..00000000 --- a/31.Install_munin/nginx-cache-multi_ +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# vim: set fileencoding=utf-8 -# -# Munin plugin to monitor nginx cache statuses. -# -# Copyright Igor Borodikhin -# -# License : GPLv3 -# -# This plugin generates two graphs - with number of requests and with percents. -# Create these symlinks: -# ln -s /usr/share/munin/plugins/nginx-cache-multi_ /etc/munin/plugins/nginx-cache-multi_number -# ls -s /usr/share/munin/plugins/nginx-cache-multi_ /etc/munin/plugins/nginx-cache-multi_percent -# -# You can override the log file location. -# -# [nginx-cache-multi] -# env.logfile /var/log/nginx/cache-access.log -# -# Nginx must be configured to include "cs=$upstream_cache_status" in the -# log file. Example format: -# -# log_format cache '$remote_addr - $host [$time_local] "$request" $status ' -# '$body_bytes_sent "$http_referer" ' -# 'rt=$request_time ut="$upstream_response_time" ' -# 'cs=$upstream_cache_status'; -#%# capabilities=autoconf -#%# family=contrib - -import os, sys, re - -# How we've been called -prog_name = sys.argv[0] -prog_name = prog_name[prog_name.rfind("/")+1:] - -# What is graph type? -graph_type = prog_name[prog_name.rfind("_")+1:] - -# Where to store plugin state -if "MUNIN_PLUGSTATE" in os.environ: - state_dir = os.environ["MUNIN_PLUGSTATE"] -else: - state_dir = None - -# Log path -if "logfile" in os.environ: - log_file = os.environ["logfile"] -else: - log_file = "/var/log/nginx/access.log" - -cache_status_list = { "MISS" : 0, "EXPIRED" : 0, "UPDATING" : 0, "STALE" : 0, "HIT" : 0, "NONE" : 0, "TOTAL" : 0 } - -if len(sys.argv) == 2 and sys.argv[1] == "autoconf": - print "yes" -elif len(sys.argv) == 2 and sys.argv[1] == "config": - graph_args = "" - if graph_type == "number": - vlabel = "requests" - else: - vlabel = "%" - graph_args = "graph_args -l 0" - - # Parent graph declaration - print "multigraph nginx_cache_multi_%s" % graph_type - print "graph_title Nginx cache status (%s)" % graph_type - print "graph_category nginx" - print "graph_vlabel %s" % vlabel - if graph_args: - print(graph_args) - for key in cache_status_list.keys(): - if key != "TOTAL": - print "%s.label %s" % (key.lower(), key.capitalize()) - print "%s.draw AREASTACK" % key.lower() - print "%s.min 0" % key.lower() - print "" - - for key in cache_status_list.keys(): - # Other graphs declaration - if key != "TOTAL": - print "multigraph nginx_cache_multi_%s.%s" % (graph_type, key.lower()) - print "graph_title Nginx cache status (%s) - %s" % (graph_type, key.capitalize()) - print "graph_category nginx" - print "graph_vlabel %s" % vlabel - print "%s.label %s" % (key.lower(), key.capitalize()) - print "%s.draw LINE1" % key.lower() - print "%s.min 0" % key.lower() - print "" -else: - last_byte_file = "%s/%s_state" % (state_dir, prog_name) - last_byte_handle = None - - # Load last position in log file - try: - last_byte_handle = open(last_byte_file, "r") - last_byte = int(last_byte_handle.read()) - except Exception: - last_byte = 0 - - if last_byte_handle != None: - last_byte_handle.close() - - # Open log file for reading - try: - log_handle = open(log_file, "r") - except Exception: - print "Log file %s not readable" % log_file - sys.exit(1) - - # Find out log size and set proper position depending on log size - try: - log_size = int(os.path.getsize(log_file)) - except ValueError: - log_size = 0 - - if log_size < last_byte: - last_byte = 0 - - # Set position on file - log_handle.seek(last_byte) - - reg_exp = re.compile(r"cs=([^\s]+)") - - for line in log_handle: - match = reg_exp.search(line) - cache_status = match.group(1) - if cache_status == "-": - cache_status = "NONE" - cache_status_list[cache_status] += 1 - cache_status_list["TOTAL"] += 1 - - try: - last_byte_handle = open(last_byte_file, "w") - last_byte_handle.write(str(log_handle.tell())) - last_byte_handle.close() - except Exception: - sys.exit(1) - - log_handle.close() - - # Handle graph type (_num for absolute numbers and anything else for percents) - if graph_type != "number": - for key in cache_status_list.keys(): - if key != "TOTAL": - cache_status_list[key] = cache_status_list[key] * 100 / cache_status_list["TOTAL"] - cache_status_list["TOTAL"] = 100 - - - # Parent graph declaration - print "multigraph nginx_cache_multi_%s" % graph_type - #print "total.value %s" % cache_status_list["TOTAL"] - for key in cache_status_list.keys(): - if key != "TOTAL": - print "%s.value %s" % (key.lower(), cache_status_list[key]) - print "" - - for key in cache_status_list.keys(): - # Other graphs declaration - if key != "TOTAL": - print "multigraph nginx_cache_multi_%s.%s" % (graph_type, key.lower()) - print "total.value %s" % cache_status_list["TOTAL"] - print "%s.value %s" % (key.lower(), cache_status_list[key]) - print "" diff --git a/31.Install_munin/nginx-combined b/31.Install_munin/nginx-combined deleted file mode 100755 index a8052a3c..00000000 --- a/31.Install_munin/nginx-combined +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/perl -w -# -*- cperl -*- -# Magic markers: -#%# family=auto -#%# capabilities=autoconf -# nginx_combine_ --- Determine the current status of Nginx -# using the http_stub_status module. -# extend of nginx_status_ plugin of António P. P. Almeida - -# Copyright (C) 2010 António P. P. Almeida <appa@perusio.net> -# Copyright (C) 2010 Minato Miray <minatomiray@gmail.com> - -# Author: António P. P. Almeida <appa@perusio.net>, -# Author: Minato Miray <minatomiray@gmail.com> - -####################################### -# Nginx combined plugin to measure in one graph: -# - Request /sec -# - Connection / sec -# - Request / connection -# - Active connections -# - Reading -# - Writing -# - Waiting -######################################## - -# Usage: -# Copy to /usr/share/munin/plugins -# ln -s /usr/share/munin/plugins/nginx_combined_ /etc/munin/plugins/nginx_combined_[hostname OR IP address] - -#examples based on nginx configuration: -#example1: ./nginx_combined_mysite.net -#example2: ./nginx_combined_10.0.0.1 - -######################################## - -my $ret = undef; - -if (! eval "require LWP::UserAgent;"){ - $ret = "LWP::UserAgent not found"; -} - -chomp(my $fqdn = `basename $0 | sed 's/^nginx_combined_//g'`); - -my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://$fqdn/nginx_status"; - -if ( exists $ARGV[0] and $ARGV[0] eq "autoconf" ) -{ - if ($ret){ - print "no ($ret)\n"; - exit 1; - } - - my $ua = LWP::UserAgent->new(timeout => 30); - my $response = $ua->request(HTTP::Request->new('GET',$URL)); - - unless ($response->is_success and $response->content =~ /server/im) - { - print "no (no nginx status on $URL)\n"; - exit 1; - } - else - { - print "yes\n"; - exit 0; - } -} - -if ( exists $ARGV[0] and $ARGV[0] eq "config" ) -{ - print "graph_title NGINX status: $URL\n"; - print "graph_args --base 1000\n"; - print "graph_category nginx\n"; - print "graph_vlabel Connections\n"; - - print "reqpsec.label Request/sec.\n"; - print "reqpsec.info Request/sec.\n"; - print "reqpsec.draw LINE2\n"; - - print "conpersec.label Connection/sec.\n"; - print "conpersec.info Connection/sec.\n"; - print "conpersec.draw LINE2\n"; - - print "reqpcon.label Request/conn.\n"; - print "reqpcon.info Request/conn.\n"; - print "reqpcon.draw LINE2\n"; - - print "total.label Active connections\n"; - print "total.info Active connections\n"; - print "total.draw LINE2\n"; - - print "reading.label Reading\n"; - print "reading.info Reading\n"; - print "reading.draw LINE2\n"; - - print "writing.label Writing\n"; - print "writing.info Writing\n"; - print "writing.draw LINE2\n"; - - print "waiting.label Waiting\n"; - print "waiting.info Waiting\n"; - print "waiting.draw LINE2\n"; - - exit 0; -} - -#do requests -my $ua = LWP::UserAgent->new(timeout => 10); -my $response = $ua->request(HTTP::Request->new('GET',$URL)); -sleep(1); -my $response2 = $ua->request(HTTP::Request->new('GET',$URL)); - - -#calculate responses -$response->content =~ /Active connections:\s+(\d+).*Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/s; -my $a1 = $1; -my $r1 = $2; -my $w1 = $3; -my $wa1 = $4; - -my $out1 = $response->content; -$out1 =~ s/\n/ /g; -my @vals = split(/ /, $out1); - -my $tmp1_reqpsec=$vals[11]; -my $tmp1_conpsec=$vals[10]; - -$response2->content =~ /Active connections:\s+(\d+).*Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/s; - -my $a2 = $1; -my $r2 = $2; -my $w2 = $3; -my $wa2 = $4; - -my $out2 = $response2->content; -$out2 =~ s/\n/ /g; -my @vals2 = split(/ /, $out2); -my $tmp2_reqpsec=$vals2[11]; -my $tmp2_conpsec=$vals2[10]; - -my $conpersec=0; -my $reqpcon=0; -my $reqpsec=0; -if (defined $tmp2_conpsec && $tmp2_conpsec =~ /^[+-]?\d+$/ && $tmp2_conpsec > 0){ - $conpersec=$tmp2_conpsec-$tmp1_conpsec; -} -if (defined $tmp2_reqpsec && $tmp2_reqpsec =~ /^[+-]?\d+$/ && $tmp2_reqpsec > 0){ - $reqpsec=$tmp2_reqpsec-$tmp1_reqpsec; -} -if ($conpersec > 0){ - $reqpcon=$reqpsec/$conpersec; -} - -print "reqpsec.value $reqpsec\n"; -print "conpersec.value $conpersec\n"; -printf("reqpcon.value %.2f\n", $reqpcon); -print "total.value $a2\n"; -print "reading.value $r2\n"; -print "writing.value $w2\n"; -print "waiting.value $wa2\n"; - diff --git a/31.Install_munin/nginx_connection_request b/31.Install_munin/nginx_connection_request deleted file mode 100755 index 47c0faf5..00000000 --- a/31.Install_munin/nginx_connection_request +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/perl -w -# -*- mode: cperl; mode: autopair -*- -# Magic markers: -#%# family=auto -#%# capabilities=autoconf -# nginx_connection request --- Determine the requests/connection -# served by nginx. - -# Copyright (C) 2010 António P. P. Almeida <appa@perusio.net> - -# Author: António P. P. Almeida <appa@perusio.net> - -# Permission is hereby granted, free of charge, to any person obtaining a -# copy of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, including without limitation -# the rights to use, copy, modify, merge, publish, distribute, sublicense, -# and/or sell copies of the Software, and to permit persons to whom the -# Software is furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. - -# Except as contained in this notice, the name(s) of the above copyright -# holders shall not be used in advertising or otherwise to promote the sale, -# use or other dealings in this Software without prior written authorization. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -# DEALINGS IN THE SOFTWARE. - -=head1 NAME - -nginx_connection_request - Munin plugin to show number of -requests/connection served by nginx. - -=encoding utf8 - -=head1 APPLICABLE SYSTEMS - -Any nginx host - -=head1 CONFIGURATION - -This shows the default configuration of this plugin. You can override -the status URL and User Agent. - - [nginx*] - env.url http://localhost/nginx_status - env.ua nginx-status-verifier/0.1 - -Nginx must also be configured. Firstly the stub-status module must be -compiled, and secondly it must be configured like this: - - server { - listen 127.0.0.1; - server_name localhost; - location /nginx_status { - stub_status on; - access_log off; - allow 127.0.0.1; - deny all; - } - } - -=head1 MAGIC MARKERS - - #%# family=auto - #%# capabilities=autoconf - -=head1 VERSION - -1.1 - -=head1 BUGS - -None known - -=head1 AUTHOR - -António Almeida <appa@perusio.net> - -=head1 REPOSITORY - -Source code at http://github.com/perusio/nginx-munin - -=head1 LICENSE - -MIT - -=cut - -my $ret = undef; - -if (! eval "require LWP::UserAgent;") { - $ret = "LWP::UserAgent not found"; -} - -chomp(my $fqdn=`hostname -f`); - -## Environment defined variables. -## The default URL is nginx_status if different set it in the environment. -my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://$fqdn/nginx_status"; -## The default user agent is ngnix-status-verifier/0.1 if different -## set it in the environment. -my $UA = exists $ENV{'ua'} ? $ENV{'ua'} : 'nginx-status-verifier/0.1'; - -## Munin autoconf method. -if (exists $ARGV[0] and $ARGV[0] eq "autoconf" ) { - if ($ret) { - print "no ($ret)\n"; - exit 1; - } - my $ua = LWP::UserAgent->new(timeout => 30); - # Set the UA to something different from the libwww-perl. - # That UA is blocked. - $ua->agent($UA); - my $response = $ua->request(HTTP::Request->new('GET',$URL)); - - unless ($response->is_success and $response->content =~ /server/im) { - print "no (no nginx status on $URL)\n"; - exit 1; - } else { - print "yes\n"; - exit 0; - } -} - -## Munin config method. -if (exists $ARGV[0] and $ARGV[0] eq "config") { - print "graph_title nginx requests/connection handled\n"; - print "graph_category nginx\n"; - print "graph_vlabel Request/Connection\n"; - print "connection_request.label requests/connection\n"; - print "connection_request.min 0\n"; - print "connection_request.draw LINE2\n"; - - exit 0; -} - -my $ua = LWP::UserAgent->new(timeout => 30); -# Set the UA to something different from the libwww-perl. -# That UA is blocked. -$ua->agent($UA); -my $response = $ua->request(HTTP::Request->new('GET',$URL)); - -if ($response->content =~ /^\s+(\d+)\s+(\d+)\s+(\d+)/m) { - printf("connection_request.value %.2f\n", $3/$2); -} else { - print "connection_request.value U\n"; -} diff --git a/31.Install_munin/nginx_error b/31.Install_munin/nginx_error deleted file mode 100755 index 7a12262e..00000000 --- a/31.Install_munin/nginx_error +++ /dev/null @@ -1,135 +0,0 @@ -#!/bin/bash -# -*- bash -*- - -: <<=cut - -=head1 NAME - -nginx error - Munin plugin to monitor nginx error rates (http status codes per minute). - -=head1 APPLICABLE SYSTEMS - -Any Linux host, running nginx, with bash version > 4.0 - -=head1 CONFIGURATION - -This shows the default configuration of this plugin. You can override -the log file path and the logpattern. - - [nginx_error] - env.logpath /var/log/nginx - env.logpattern a.*.log - - Nginx must also be configured to log accesses in "combined" log format (default) - -=head1 USAGE - -Link this plugin to /etc/munin/plugins/ and restart the munin-node. - -This plugin also can be used like wildcard-plugin for monitoring particular virtual host log. -E.g. - ln -s /usr/share/munin/plugins/nginx_error /etc/munin/plugins/nginx_error_mydomaincom -will parse the log file /var/log/nginx/a.mydomaincom.log - -You can change 'env.logpattern' using asterisk ('*') to match your logs filenames. - -=head1 INTERPRETATION - -The plugin shows nginx http "error" status rates by parsing access log. - -=head1 MAGIC MARKERS - - #%# family=auto - #%# capabilities=autoconf - -=head1 BUGS - -None known. - -=head1 VERSION - -$Id:$ - -=head1 AUTHOR - -vovansystems@gmail.com, 2013 - -=head1 LICENSE - -GPLv3 - -=cut - -if [ -z $logpath ]; then - logpath='/var/log/nginx' -fi - -name=`basename $0` - -domain=${name/nginx_error/} -if [[ $domain != '_' && ${#domain} -ne 0 ]]; then - domain=${domain:1} - if [ -z $logpattern ]; then - logpattern='a.*.log' - fi - logpattern=${logpattern/\*/$domain} -else - logpattern='access.log' -fi - -log="$logpath/$logpattern" - -# declaring an array with http status codes, we are interested in -declare -A http_codes -http_codes[400]='Bad Request' -http_codes[401]='Unauthorized' -http_codes[403]='Forbidden' -http_codes[404]='Not Found' -http_codes[405]='Method Not Allowed' -http_codes[406]='Not Acceptable' -http_codes[408]='Request Timeout' -http_codes[429]='Too Many Requests' -http_codes[499]='Client Connection Terminated' -http_codes[500]='Internal Server Error' -http_codes[502]='Bad Gateway' -http_codes[503]='Service Unavailable' - -do_ () { # Fetch - declare -A line_counts - values=`awk '{print $9}' $log | sort | uniq -c` - while read -r line; do - read -a tmp <<< "$line"; - line_counts[${tmp[1]}]=${tmp[0]}; - done <<< "$values" - - for k in ${!http_codes[@]}; do - echo "error$k.value ${line_counts[$k]:-0}" - done - exit 0 -} - -do_config () { - echo "graph_title $logpattern - Nginx errors per minute" - echo 'graph_vlabel pages with http error codes / ${graph_period}' - echo "graph_category nginx" - echo "graph_period minute" - echo "graph_info This graph shows nginx error amount per minute" - for k in ${!http_codes[@]}; do - echo "error$k.type DERIVE" - echo "error$k.min 0" - echo "error$k.label $k ${http_codes[$k]}" - done - exit 0 -} - -do_autoconf () { - echo yes - exit 0 -} - -case $1 in - config|autoconf|'') - eval do_$1 -esac - -exit $? diff --git a/31.Install_munin/nginx_memory b/31.Install_munin/nginx_memory deleted file mode 100755 index 207af3bf..00000000 --- a/31.Install_munin/nginx_memory +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/perl -w -# -*- mode: cperl; mode: autopair -*- -# Magic markers: -#%# family=auto -#%# capabilities=autoconf -# nginx_memory --- Munin plugin for monitoring Nginx memory -# usage. Based on the nginx_memory.pl plugin -# by AkyRhO <akyrho@gmail.com>. - -# Copyright (C) 2010 António P. P. Almeida <appa@perusio.net> - -# Author: António P. P. Almeida <appa@perusio.net> - -# Permission is hereby granted, free of charge, to any person obtaining a -# copy of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, including without limitation -# the rights to use, copy, modify, merge, publish, distribute, sublicense, -# and/or sell copies of the Software, and to permit persons to whom the -# Software is furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. - -# Except as contained in this notice, the name(s) of the above copyright -# holders shall not be used in advertising or otherwise to promote the sale, -# use or other dealings in this Software without prior written authorization. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -# DEALINGS IN THE SOFTWARE. - -=head1 NAME - -nginx_memory - Munin plugin to show the RAM used by nginx. - -=encoding utf8 - -=head1 APPLICABLE SYSTEMS - -Any nginx host - -=head1 MAGIC MARKERS - - #%# family=auto - #%# capabilities=autoconf - -=head1 VERSION - -1.0 - -=head1 BUGS - -None known - -=head1 AUTHOR - -Based on a script by AkyRhO <akyrho@gmail.com>. Modified by António -Almeida <appa@perusio.net> - -=head1 REPOSITORY - -Source code at http://github.com/perusio/nginx-munin - -=head1 LICENSE - -MIT - -=cut - -## Munin config method. -if (exists $ARGV[0] and $ARGV[0] eq "config") { - print "graph_title nginx RAM usage\n"; - print "graph_vlabel RAM\n"; - print "graph_category nginx\n"; - print "ram.label RAM\n"; - print "graph_args --base 1024\n"; - - exit 0; -} else { - my $m = `ps u -p \$(pidof nginx) | awk 'NR > 1 {nm += \$5} END {print nm*1024}'`; - print "ram.value $m"; -} diff --git a/31.Install_munin/nginx_upstream b/31.Install_munin/nginx_upstream deleted file mode 100755 index ee3ab974..00000000 --- a/31.Install_munin/nginx_upstream +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/python -#requires log format as below -#log_format cache '$remote_addr - $host [$time_local] "$request" $status ' -# '$body_bytes_sent "$http_referer" ' -# 'rt=$request_time ut="$upstream_response_time" ' -# 'cs=$upstream_cache_status'; - -#License BSD -#Created by Simon Whittaker simon+github@swbh.net -#based on nginx_cache_hit_rate - -from __future__ import with_statement -import re -import sys -fname = "/var/log/nginx/access.log" # File to check - -if len(sys.argv) > 1: - if sys.argv[1]=="config": - print "graph_args --base 1000 -l 0" - print "graph_title NGINX Upstream times" - print "graph_category nginx" - print "graph_vlabel milliseconds" - print "upstream.label upstream" - print "upstream.warning 5000" - print "upstream.critical 10000" - print "graph_info Shows the average time of connections to upstream servers for the primary site" - sys.exit(0) - -with open(fname, "r") as f: - f.seek (0, 2) # Seek @ EOF - fsize = f.tell() # Get Size - f.seek (max (fsize-20480, 0), 0) # Set pos @ last n chars - lines = f.readlines() # Read to end - -lines = lines[-1000:] #last 1000 lines you might want to change this - -re1='.*?' # Non-greedy match on filler -re2='(ut)' # Word 1 -re3='(=)' # Any Single Character 1 -re4='([+-]?\\d*\\.\\d+)(?![-+0-9\\.])' # Float 1 - -rg = re.compile(re1+re2+re3+re4,re.IGNORECASE|re.DOTALL) -totaltimeforrequests=0 -numberofrequests=0 -for line in lines: - m = rg.search(line) - if m: - word1=m.group(1) - c1=m.group(2) - float1=m.group(3) - numberofrequests=numberofrequests+1 - totaltimeforrequests=totaltimeforrequests+float(float1) - -upstream=(totaltimeforrequests/numberofrequests)*1000 -upstream=int(upstream) -print "upstream.value "+str(upstream) diff --git a/31.Install_munin/nginx_vhost_traffic b/31.Install_munin/nginx_vhost_traffic deleted file mode 100755 index 826059ea..00000000 --- a/31.Install_munin/nginx_vhost_traffic +++ /dev/null @@ -1,103 +0,0 @@ -#!/bin/sh -# -# Script for monitoring nginx Virtual host output traffic -# -# Requierements: logtail awk -# one unique access log file with $bytes_sent value for more accuracy -# check http://wiki.nginx.org/NginxHttpLogModule -# -# Configuration Options (all options have defaults) -# [nginx_vhost_traffic] -# -# Virtual host list -# env.vhosts "example.com example.net example.org" -# -# Log path -# env.logdir = /var/log/nginx -# env.flogfile = access.log -# -# Position of the $bytes_sent in the access.log file -# env.bparam 11 -# -# Aggregate subdomains -# ex: example.com will match www.example.com, webmail.example.com and *example.com -# BUG: will also match also www.bad-example.com -# env.aggregate true #change to false to disable aggregation -# -# To report bugs, improvements or get updates -# see http://github.com/joanpc/nginix_vhost_traffic -# -# inspired in postfix_filtered_awk -# Copyright (c) 2010, Joan Perez i Cauhe - -LOGDIR=${logdir:-/var/log/nginx} -ACCESS_LOG=$LOGDIR/${logfile:-access.log} -LOGTAIL=${logtail:-`which logtail`} -STATEFILE=/var/lib/munin/plugin-state/nginx_vhost_traffic.state -VHOSTS=${vhosts:-`hostname`} -AGGREGATE=${aggregate:true} - -BPARAM=${bparam:-11} - -case $1 in - config) - DRAW=AREA - echo 'graph_title Nginx Virtual host traffic' - echo 'graph_vlabel bits out / ${graph_period}' - echo 'graph_args --base 1000 -l 0' - echo 'graph_category Nginx' - - i=0 - for vhost in $VHOSTS - do - i=$(($i + 1)) - echo vhost$i.label $vhost - echo vhost$i.type ABSOLUTE - echo vhost$i.cdef vhost$i,8,* - echo vhost$i.draw $DRAW - DRAW=STACK - done - - echo rest.label Rest - echo rest.type ABSOLUTE - echo rest.cdef rest,8,* - echo rest.draw STACK - exit 0;; -esac - -export BPARAM -export VHOSTS -export AGGREGATE - -# Awk Script -$LOGTAIL ${ACCESS_LOG} -o $STATEFILE | awk ' - -BEGIN { -split(ENVIRON["VHOSTS"], hosts) -for (host in hosts) { track[hosts[host]] = host} -} -{ - cn[$2]+=$ENVIRON["BPARAM"] -} -END { - for (host in cn) { - if (match(ENVIRON["AGGREGATE"], "true")) { - found = 0 - for (vhost in track) { - if (index(host, vhost)) { - res[vhost] += cn[host] - found = 1 - break - } - } - if (! found) rest+=cn[host] - } else { - if (host in track) { - res[host] += cn[host] - } else rest+=cn[host] - } - } - print "aggregate: " ENVIRON["AGGREGATE"] - for (vhost in track) print "vhost" track[vhost] ".value " res[vhost]+0 - print "rest.value " rest + 0 -}' diff --git a/31.Install_munin/nginx_working_set b/31.Install_munin/nginx_working_set deleted file mode 100755 index 04e8b809..00000000 --- a/31.Install_munin/nginx_working_set +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -# -# Munin plugin for monitoring Nginx working set -# -# by Mike Koss, Feb 12, 2012 - MIT License -# -#%# family=auto -#%# capabilities=autoconf - -case $1 in -config) - cat <<'EOF' -graph_title NGINX Working Set -graph_vlabel WS Bytes -graph_category nginx -graph_args --base 1024 -ws.label Working Set -EOF - exit 0 - ;; - -autoconf) - if [ "$(pidof nginx)" == "" ]; then - echo no - else - echo yes - fi - exit 0 - ;; -esac - -KBS=$(ps -o rss --no-heading -p $(pidof nginx)) -total=0 -for size in $KBS -do - total=$(($total + $size * 1024)) -done -echo ws.value $total diff --git a/31.Install_munin/uwsgi_ b/31.Install_munin/uwsgi_ deleted file mode 100644 index 4c4c228e..00000000 --- a/31.Install_munin/uwsgi_ +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash -# Copyright (c) 2013 Gareth Davies (shaolintiger@gmail.com www.shaolintiger.com) -# License GPLv2 -# This plugin monitors number of workers, total memory used and average memory per process for uWSGI. -# Here are the symlinks to enable it -# -# ln -s /usr/share/munin/plugins/uwsgi_ /etc/munin/plugins/uwsgi_average -# ln -s /usr/share/munin/plugins/uwsgi_ /etc/munin/plugins/uwsgi_memory -# ln -s /usr/share/munin/plugins/uwsgi_ /etc/munin/plugins/uwsgi_processes -mode=`echo $0 | cut -d _ -f 2` -if [ "$1" = "suggest" ]; then - echo "memory" - echo "processes" - echo "average" - exit 0 -fi -if [ "$mode" = "memory" ]; then - if [ "$1" = "config" ]; then - echo "graph_title Total uWSGI Memory" - echo "graph_vlabel Total RAM" - echo "graph_category uWSGI" - echo "graph_args --base 1024" - echo "ram.label Total RAM" - exit 0 - else - memory_array=(`ps auwx | grep "uwsgi.sock" | grep -v grep | awk '{print $6 }'`) - for i in "${memory_array[@]}" - do - sum=$(( $sum + ( $i * 1024) )) - done - echo -n "ram.value " - echo $sum - fi -elif [ "$mode" = "processes" ]; then - if [ "$1" = "config" ]; then - echo "graph_title uWSGI Processes" - echo "graph_vlabel Processes" - echo "graph_category uWSGI" - echo "processes.label active processes" - else - echo -n "processes.value " - ps awwwux | grep 'uwsgi.sock' | grep -v grep | wc -l - exit 0 - fi -elif [ "$mode" = "average" ]; then - if [ "$1" = "config" ]; then - echo 'graph_title uWSGI Average Process Size' - echo 'graph_args --base 1024 -l 0 ' - echo 'graph_vlabel Average Process Size' - echo 'graph_category uWSGI' - echo 'uwsgi_average.label Average Process Size' - echo 'uwsgi_average.draw LINE2' - echo 'uwsgi_average.info The average process size for uWSGI' - else - echo -n "uwsgi_average.value " - ps awwwux | grep 'uwsgi.sock' | grep -v grep | awk '{total_mem = $6 * 1024 + total_mem; total_proc++} END{printf("%d\n", total_mem / total_proc)}' - exit 0 - fi - -fi -exit 0 diff --git a/72.Deploy_munin_configuration/0_setup.sh b/72.Deploy_munin_configuration/0_setup.sh index 79a4b9c7..d5030834 100755 --- a/72.Deploy_munin_configuration/0_setup.sh +++ b/72.Deploy_munin_configuration/0_setup.sh @@ -1,19 +1,5 @@ #!/bin/bash source /root/envsetup/envsetup.conf -# service -aptitude install -y libwww-perl -echo '' >> /etc/munin/plugin-conf.d/munin-node -echo '[nginx*]' >> /etc/munin/plugin-conf.d/munin-node -echo "env.url http://localhost/nginx_status" >> /etc/munin/plugin-conf.d/munin-node -# -cp nginx* /usr/share/munin/plugins/ -ln -s /usr/share/munin/plugins/nginx-combined /etc/munin/plugins/ -ln -s /usr/share/munin/plugins/nginx_connection_request /etc/munin/plugins/ -ln -s /usr/share/munin/plugins/nginx_error /etc/munin/plugins/ -ln -s /usr/share/munin/plugins/nginx_memory /etc/munin/plugins/ -ln -s /usr/share/munin/plugins/nginx_vhost_traffic /etc/munin/plugins/ -ln -s /usr/share/munin/plugins/nginx_working_set /etc/munin/plugins/ -## -munin-node-configure --suggest -service munin-node restart +# for munin +DEBIAN_FRONTEND=noninteractive apt-get install -y ubicast-config diff --git a/72.Deploy_munin_configuration/nginx-cache-hit-rate b/72.Deploy_munin_configuration/nginx-cache-hit-rate deleted file mode 100755 index a241a8c4..00000000 --- a/72.Deploy_munin_configuration/nginx-cache-hit-rate +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/perl -w - -=head1 NAME - -nginx_hitmiss - Munin plugin to show hit rate of nginx proxy cache - -=head1 APPLICABLE SYSTEMS - -nginx caching proxy - -=head1 CONFIGURATION - -File::ReadBackwards is used and must be installed. - -You can override the log file location. - - [nginx*] - env.logfile /var/log/nginx/cache-access.log - -Nginx must be configured to include "cs=$upstream_cache_status" in the -log file. Example format: - -log_format cache '$remote_addr - $host [$time_local] "$request" $status ' - '$body_bytes_sent "$http_referer" ' - 'rt=$request_time ut="$upstream_response_time" ' - 'cs=$upstream_cache_status'; - -By default the last 1000 log lines are read, you may want to change this. - -=head1 MAGIC MARKERS - - #%# family=auto - #%# capabilities=autoconf - -=head1 LICENSE - -BSD - -=cut - -use File::ReadBackwards; -my $line_counter=1000; - -my $LOG = exists $ENV{'logfile'} ? $ENV{'logfile'} - : "/var/log/nginx/cache-access.log"; - -if ( exists $ARGV[0] and $ARGV[0] eq "autoconf" ) { - unless (-r $LOG) { - print "$LOG not readable\n"; - exit 0; - } else { - print "yes\n"; - exit 0; - } -} - -if ( exists $ARGV[0] and $ARGV[0] eq "config" ) { - print "graph_title NGINX hit rates\n"; - print "graph_args -l 0 -u 100 --rigid\n"; - print "graph_category nginx\n"; - print "graph_vlabel %\n"; - print "hit.label Hits\n"; - print "hit.draw AREA\n"; - print "hit.min 0\n"; - print "hit.cdef hit,$line_counter,/,100,*\n"; - print "miss.label Misses\n"; - print "miss.draw STACK\n"; - print "miss.min 0\n"; - print "miss.cdef miss,$line_counter,/,100,*\n"; - print "expired.label Expired Objects\n"; - print "expired.draw STACK\n"; - print "expired.min 0\n"; - print "expired.cdef expired,$line_counter,/,100,*\n"; - exit 0; -} - -my ($e,$h,$m) = (0,0,0); -my $file_counter=0; - -FILE: while ($line_counter > 0) { - my $file_extension = $file_counter==0? "" : ".$file_counter"; - my $lh= File::ReadBackwards->new( "$LOG$file_extension" ) - or ( warn "$line_counter lines to read, but $LOG$file_extension: $!" - and last FILE); - $file_counter++; - while (defined ($_= $lh->readline)) { - $line_counter--; - /cs=HIT/ and $h++; - /cs=MISS/ and $m++; - /cs=EXPIRED/ and $e++; - last FILE if $line_counter==0; - } - $lh->close(); -} -print "hit.value $h\n"; -print "miss.value $m\n"; -print "expired.value $e\n"; diff --git a/72.Deploy_munin_configuration/nginx-cache-multi_ b/72.Deploy_munin_configuration/nginx-cache-multi_ deleted file mode 100755 index 3ab8046b..00000000 --- a/72.Deploy_munin_configuration/nginx-cache-multi_ +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# vim: set fileencoding=utf-8 -# -# Munin plugin to monitor nginx cache statuses. -# -# Copyright Igor Borodikhin -# -# License : GPLv3 -# -# This plugin generates two graphs - with number of requests and with percents. -# Create these symlinks: -# ln -s /usr/share/munin/plugins/nginx-cache-multi_ /etc/munin/plugins/nginx-cache-multi_number -# ls -s /usr/share/munin/plugins/nginx-cache-multi_ /etc/munin/plugins/nginx-cache-multi_percent -# -# You can override the log file location. -# -# [nginx-cache-multi] -# env.logfile /var/log/nginx/cache-access.log -# -# Nginx must be configured to include "cs=$upstream_cache_status" in the -# log file. Example format: -# -# log_format cache '$remote_addr - $host [$time_local] "$request" $status ' -# '$body_bytes_sent "$http_referer" ' -# 'rt=$request_time ut="$upstream_response_time" ' -# 'cs=$upstream_cache_status'; -#%# capabilities=autoconf -#%# family=contrib - -import os, sys, re - -# How we've been called -prog_name = sys.argv[0] -prog_name = prog_name[prog_name.rfind("/")+1:] - -# What is graph type? -graph_type = prog_name[prog_name.rfind("_")+1:] - -# Where to store plugin state -if "MUNIN_PLUGSTATE" in os.environ: - state_dir = os.environ["MUNIN_PLUGSTATE"] -else: - state_dir = None - -# Log path -if "logfile" in os.environ: - log_file = os.environ["logfile"] -else: - log_file = "/var/log/nginx/access.log" - -cache_status_list = { "MISS" : 0, "EXPIRED" : 0, "UPDATING" : 0, "STALE" : 0, "HIT" : 0, "NONE" : 0, "TOTAL" : 0 } - -if len(sys.argv) == 2 and sys.argv[1] == "autoconf": - print "yes" -elif len(sys.argv) == 2 and sys.argv[1] == "config": - graph_args = "" - if graph_type == "number": - vlabel = "requests" - else: - vlabel = "%" - graph_args = "graph_args -l 0" - - # Parent graph declaration - print "multigraph nginx_cache_multi_%s" % graph_type - print "graph_title Nginx cache status (%s)" % graph_type - print "graph_category nginx" - print "graph_vlabel %s" % vlabel - if graph_args: - print(graph_args) - for key in cache_status_list.keys(): - if key != "TOTAL": - print "%s.label %s" % (key.lower(), key.capitalize()) - print "%s.draw AREASTACK" % key.lower() - print "%s.min 0" % key.lower() - print "" - - for key in cache_status_list.keys(): - # Other graphs declaration - if key != "TOTAL": - print "multigraph nginx_cache_multi_%s.%s" % (graph_type, key.lower()) - print "graph_title Nginx cache status (%s) - %s" % (graph_type, key.capitalize()) - print "graph_category nginx" - print "graph_vlabel %s" % vlabel - print "%s.label %s" % (key.lower(), key.capitalize()) - print "%s.draw LINE1" % key.lower() - print "%s.min 0" % key.lower() - print "" -else: - last_byte_file = "%s/%s_state" % (state_dir, prog_name) - last_byte_handle = None - - # Load last position in log file - try: - last_byte_handle = open(last_byte_file, "r") - last_byte = int(last_byte_handle.read()) - except Exception: - last_byte = 0 - - if last_byte_handle != None: - last_byte_handle.close() - - # Open log file for reading - try: - log_handle = open(log_file, "r") - except Exception: - print "Log file %s not readable" % log_file - sys.exit(1) - - # Find out log size and set proper position depending on log size - try: - log_size = int(os.path.getsize(log_file)) - except ValueError: - log_size = 0 - - if log_size < last_byte: - last_byte = 0 - - # Set position on file - log_handle.seek(last_byte) - - reg_exp = re.compile(r"cs=([^\s]+)") - - for line in log_handle: - match = reg_exp.search(line) - cache_status = match.group(1) - if cache_status == "-": - cache_status = "NONE" - cache_status_list[cache_status] += 1 - cache_status_list["TOTAL"] += 1 - - try: - last_byte_handle = open(last_byte_file, "w") - last_byte_handle.write(str(log_handle.tell())) - last_byte_handle.close() - except Exception: - sys.exit(1) - - log_handle.close() - - # Handle graph type (_num for absolute numbers and anything else for percents) - if graph_type != "number": - for key in cache_status_list.keys(): - if key != "TOTAL": - cache_status_list[key] = cache_status_list[key] * 100 / cache_status_list["TOTAL"] - cache_status_list["TOTAL"] = 100 - - - # Parent graph declaration - print "multigraph nginx_cache_multi_%s" % graph_type - #print "total.value %s" % cache_status_list["TOTAL"] - for key in cache_status_list.keys(): - if key != "TOTAL": - print "%s.value %s" % (key.lower(), cache_status_list[key]) - print "" - - for key in cache_status_list.keys(): - # Other graphs declaration - if key != "TOTAL": - print "multigraph nginx_cache_multi_%s.%s" % (graph_type, key.lower()) - print "total.value %s" % cache_status_list["TOTAL"] - print "%s.value %s" % (key.lower(), cache_status_list[key]) - print "" diff --git a/72.Deploy_munin_configuration/nginx-combined b/72.Deploy_munin_configuration/nginx-combined deleted file mode 100755 index a8052a3c..00000000 --- a/72.Deploy_munin_configuration/nginx-combined +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/perl -w -# -*- cperl -*- -# Magic markers: -#%# family=auto -#%# capabilities=autoconf -# nginx_combine_ --- Determine the current status of Nginx -# using the http_stub_status module. -# extend of nginx_status_ plugin of António P. P. Almeida - -# Copyright (C) 2010 António P. P. Almeida <appa@perusio.net> -# Copyright (C) 2010 Minato Miray <minatomiray@gmail.com> - -# Author: António P. P. Almeida <appa@perusio.net>, -# Author: Minato Miray <minatomiray@gmail.com> - -####################################### -# Nginx combined plugin to measure in one graph: -# - Request /sec -# - Connection / sec -# - Request / connection -# - Active connections -# - Reading -# - Writing -# - Waiting -######################################## - -# Usage: -# Copy to /usr/share/munin/plugins -# ln -s /usr/share/munin/plugins/nginx_combined_ /etc/munin/plugins/nginx_combined_[hostname OR IP address] - -#examples based on nginx configuration: -#example1: ./nginx_combined_mysite.net -#example2: ./nginx_combined_10.0.0.1 - -######################################## - -my $ret = undef; - -if (! eval "require LWP::UserAgent;"){ - $ret = "LWP::UserAgent not found"; -} - -chomp(my $fqdn = `basename $0 | sed 's/^nginx_combined_//g'`); - -my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://$fqdn/nginx_status"; - -if ( exists $ARGV[0] and $ARGV[0] eq "autoconf" ) -{ - if ($ret){ - print "no ($ret)\n"; - exit 1; - } - - my $ua = LWP::UserAgent->new(timeout => 30); - my $response = $ua->request(HTTP::Request->new('GET',$URL)); - - unless ($response->is_success and $response->content =~ /server/im) - { - print "no (no nginx status on $URL)\n"; - exit 1; - } - else - { - print "yes\n"; - exit 0; - } -} - -if ( exists $ARGV[0] and $ARGV[0] eq "config" ) -{ - print "graph_title NGINX status: $URL\n"; - print "graph_args --base 1000\n"; - print "graph_category nginx\n"; - print "graph_vlabel Connections\n"; - - print "reqpsec.label Request/sec.\n"; - print "reqpsec.info Request/sec.\n"; - print "reqpsec.draw LINE2\n"; - - print "conpersec.label Connection/sec.\n"; - print "conpersec.info Connection/sec.\n"; - print "conpersec.draw LINE2\n"; - - print "reqpcon.label Request/conn.\n"; - print "reqpcon.info Request/conn.\n"; - print "reqpcon.draw LINE2\n"; - - print "total.label Active connections\n"; - print "total.info Active connections\n"; - print "total.draw LINE2\n"; - - print "reading.label Reading\n"; - print "reading.info Reading\n"; - print "reading.draw LINE2\n"; - - print "writing.label Writing\n"; - print "writing.info Writing\n"; - print "writing.draw LINE2\n"; - - print "waiting.label Waiting\n"; - print "waiting.info Waiting\n"; - print "waiting.draw LINE2\n"; - - exit 0; -} - -#do requests -my $ua = LWP::UserAgent->new(timeout => 10); -my $response = $ua->request(HTTP::Request->new('GET',$URL)); -sleep(1); -my $response2 = $ua->request(HTTP::Request->new('GET',$URL)); - - -#calculate responses -$response->content =~ /Active connections:\s+(\d+).*Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/s; -my $a1 = $1; -my $r1 = $2; -my $w1 = $3; -my $wa1 = $4; - -my $out1 = $response->content; -$out1 =~ s/\n/ /g; -my @vals = split(/ /, $out1); - -my $tmp1_reqpsec=$vals[11]; -my $tmp1_conpsec=$vals[10]; - -$response2->content =~ /Active connections:\s+(\d+).*Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/s; - -my $a2 = $1; -my $r2 = $2; -my $w2 = $3; -my $wa2 = $4; - -my $out2 = $response2->content; -$out2 =~ s/\n/ /g; -my @vals2 = split(/ /, $out2); -my $tmp2_reqpsec=$vals2[11]; -my $tmp2_conpsec=$vals2[10]; - -my $conpersec=0; -my $reqpcon=0; -my $reqpsec=0; -if (defined $tmp2_conpsec && $tmp2_conpsec =~ /^[+-]?\d+$/ && $tmp2_conpsec > 0){ - $conpersec=$tmp2_conpsec-$tmp1_conpsec; -} -if (defined $tmp2_reqpsec && $tmp2_reqpsec =~ /^[+-]?\d+$/ && $tmp2_reqpsec > 0){ - $reqpsec=$tmp2_reqpsec-$tmp1_reqpsec; -} -if ($conpersec > 0){ - $reqpcon=$reqpsec/$conpersec; -} - -print "reqpsec.value $reqpsec\n"; -print "conpersec.value $conpersec\n"; -printf("reqpcon.value %.2f\n", $reqpcon); -print "total.value $a2\n"; -print "reading.value $r2\n"; -print "writing.value $w2\n"; -print "waiting.value $wa2\n"; - diff --git a/72.Deploy_munin_configuration/nginx_connection_request b/72.Deploy_munin_configuration/nginx_connection_request deleted file mode 100755 index 47c0faf5..00000000 --- a/72.Deploy_munin_configuration/nginx_connection_request +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/perl -w -# -*- mode: cperl; mode: autopair -*- -# Magic markers: -#%# family=auto -#%# capabilities=autoconf -# nginx_connection request --- Determine the requests/connection -# served by nginx. - -# Copyright (C) 2010 António P. P. Almeida <appa@perusio.net> - -# Author: António P. P. Almeida <appa@perusio.net> - -# Permission is hereby granted, free of charge, to any person obtaining a -# copy of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, including without limitation -# the rights to use, copy, modify, merge, publish, distribute, sublicense, -# and/or sell copies of the Software, and to permit persons to whom the -# Software is furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. - -# Except as contained in this notice, the name(s) of the above copyright -# holders shall not be used in advertising or otherwise to promote the sale, -# use or other dealings in this Software without prior written authorization. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -# DEALINGS IN THE SOFTWARE. - -=head1 NAME - -nginx_connection_request - Munin plugin to show number of -requests/connection served by nginx. - -=encoding utf8 - -=head1 APPLICABLE SYSTEMS - -Any nginx host - -=head1 CONFIGURATION - -This shows the default configuration of this plugin. You can override -the status URL and User Agent. - - [nginx*] - env.url http://localhost/nginx_status - env.ua nginx-status-verifier/0.1 - -Nginx must also be configured. Firstly the stub-status module must be -compiled, and secondly it must be configured like this: - - server { - listen 127.0.0.1; - server_name localhost; - location /nginx_status { - stub_status on; - access_log off; - allow 127.0.0.1; - deny all; - } - } - -=head1 MAGIC MARKERS - - #%# family=auto - #%# capabilities=autoconf - -=head1 VERSION - -1.1 - -=head1 BUGS - -None known - -=head1 AUTHOR - -António Almeida <appa@perusio.net> - -=head1 REPOSITORY - -Source code at http://github.com/perusio/nginx-munin - -=head1 LICENSE - -MIT - -=cut - -my $ret = undef; - -if (! eval "require LWP::UserAgent;") { - $ret = "LWP::UserAgent not found"; -} - -chomp(my $fqdn=`hostname -f`); - -## Environment defined variables. -## The default URL is nginx_status if different set it in the environment. -my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://$fqdn/nginx_status"; -## The default user agent is ngnix-status-verifier/0.1 if different -## set it in the environment. -my $UA = exists $ENV{'ua'} ? $ENV{'ua'} : 'nginx-status-verifier/0.1'; - -## Munin autoconf method. -if (exists $ARGV[0] and $ARGV[0] eq "autoconf" ) { - if ($ret) { - print "no ($ret)\n"; - exit 1; - } - my $ua = LWP::UserAgent->new(timeout => 30); - # Set the UA to something different from the libwww-perl. - # That UA is blocked. - $ua->agent($UA); - my $response = $ua->request(HTTP::Request->new('GET',$URL)); - - unless ($response->is_success and $response->content =~ /server/im) { - print "no (no nginx status on $URL)\n"; - exit 1; - } else { - print "yes\n"; - exit 0; - } -} - -## Munin config method. -if (exists $ARGV[0] and $ARGV[0] eq "config") { - print "graph_title nginx requests/connection handled\n"; - print "graph_category nginx\n"; - print "graph_vlabel Request/Connection\n"; - print "connection_request.label requests/connection\n"; - print "connection_request.min 0\n"; - print "connection_request.draw LINE2\n"; - - exit 0; -} - -my $ua = LWP::UserAgent->new(timeout => 30); -# Set the UA to something different from the libwww-perl. -# That UA is blocked. -$ua->agent($UA); -my $response = $ua->request(HTTP::Request->new('GET',$URL)); - -if ($response->content =~ /^\s+(\d+)\s+(\d+)\s+(\d+)/m) { - printf("connection_request.value %.2f\n", $3/$2); -} else { - print "connection_request.value U\n"; -} diff --git a/72.Deploy_munin_configuration/nginx_error b/72.Deploy_munin_configuration/nginx_error deleted file mode 100755 index 7a12262e..00000000 --- a/72.Deploy_munin_configuration/nginx_error +++ /dev/null @@ -1,135 +0,0 @@ -#!/bin/bash -# -*- bash -*- - -: <<=cut - -=head1 NAME - -nginx error - Munin plugin to monitor nginx error rates (http status codes per minute). - -=head1 APPLICABLE SYSTEMS - -Any Linux host, running nginx, with bash version > 4.0 - -=head1 CONFIGURATION - -This shows the default configuration of this plugin. You can override -the log file path and the logpattern. - - [nginx_error] - env.logpath /var/log/nginx - env.logpattern a.*.log - - Nginx must also be configured to log accesses in "combined" log format (default) - -=head1 USAGE - -Link this plugin to /etc/munin/plugins/ and restart the munin-node. - -This plugin also can be used like wildcard-plugin for monitoring particular virtual host log. -E.g. - ln -s /usr/share/munin/plugins/nginx_error /etc/munin/plugins/nginx_error_mydomaincom -will parse the log file /var/log/nginx/a.mydomaincom.log - -You can change 'env.logpattern' using asterisk ('*') to match your logs filenames. - -=head1 INTERPRETATION - -The plugin shows nginx http "error" status rates by parsing access log. - -=head1 MAGIC MARKERS - - #%# family=auto - #%# capabilities=autoconf - -=head1 BUGS - -None known. - -=head1 VERSION - -$Id:$ - -=head1 AUTHOR - -vovansystems@gmail.com, 2013 - -=head1 LICENSE - -GPLv3 - -=cut - -if [ -z $logpath ]; then - logpath='/var/log/nginx' -fi - -name=`basename $0` - -domain=${name/nginx_error/} -if [[ $domain != '_' && ${#domain} -ne 0 ]]; then - domain=${domain:1} - if [ -z $logpattern ]; then - logpattern='a.*.log' - fi - logpattern=${logpattern/\*/$domain} -else - logpattern='access.log' -fi - -log="$logpath/$logpattern" - -# declaring an array with http status codes, we are interested in -declare -A http_codes -http_codes[400]='Bad Request' -http_codes[401]='Unauthorized' -http_codes[403]='Forbidden' -http_codes[404]='Not Found' -http_codes[405]='Method Not Allowed' -http_codes[406]='Not Acceptable' -http_codes[408]='Request Timeout' -http_codes[429]='Too Many Requests' -http_codes[499]='Client Connection Terminated' -http_codes[500]='Internal Server Error' -http_codes[502]='Bad Gateway' -http_codes[503]='Service Unavailable' - -do_ () { # Fetch - declare -A line_counts - values=`awk '{print $9}' $log | sort | uniq -c` - while read -r line; do - read -a tmp <<< "$line"; - line_counts[${tmp[1]}]=${tmp[0]}; - done <<< "$values" - - for k in ${!http_codes[@]}; do - echo "error$k.value ${line_counts[$k]:-0}" - done - exit 0 -} - -do_config () { - echo "graph_title $logpattern - Nginx errors per minute" - echo 'graph_vlabel pages with http error codes / ${graph_period}' - echo "graph_category nginx" - echo "graph_period minute" - echo "graph_info This graph shows nginx error amount per minute" - for k in ${!http_codes[@]}; do - echo "error$k.type DERIVE" - echo "error$k.min 0" - echo "error$k.label $k ${http_codes[$k]}" - done - exit 0 -} - -do_autoconf () { - echo yes - exit 0 -} - -case $1 in - config|autoconf|'') - eval do_$1 -esac - -exit $? diff --git a/72.Deploy_munin_configuration/nginx_memory b/72.Deploy_munin_configuration/nginx_memory deleted file mode 100755 index 207af3bf..00000000 --- a/72.Deploy_munin_configuration/nginx_memory +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/perl -w -# -*- mode: cperl; mode: autopair -*- -# Magic markers: -#%# family=auto -#%# capabilities=autoconf -# nginx_memory --- Munin plugin for monitoring Nginx memory -# usage. Based on the nginx_memory.pl plugin -# by AkyRhO <akyrho@gmail.com>. - -# Copyright (C) 2010 António P. P. Almeida <appa@perusio.net> - -# Author: António P. P. Almeida <appa@perusio.net> - -# Permission is hereby granted, free of charge, to any person obtaining a -# copy of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, including without limitation -# the rights to use, copy, modify, merge, publish, distribute, sublicense, -# and/or sell copies of the Software, and to permit persons to whom the -# Software is furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. - -# Except as contained in this notice, the name(s) of the above copyright -# holders shall not be used in advertising or otherwise to promote the sale, -# use or other dealings in this Software without prior written authorization. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -# DEALINGS IN THE SOFTWARE. - -=head1 NAME - -nginx_memory - Munin plugin to show the RAM used by nginx. - -=encoding utf8 - -=head1 APPLICABLE SYSTEMS - -Any nginx host - -=head1 MAGIC MARKERS - - #%# family=auto - #%# capabilities=autoconf - -=head1 VERSION - -1.0 - -=head1 BUGS - -None known - -=head1 AUTHOR - -Based on a script by AkyRhO <akyrho@gmail.com>. Modified by António -Almeida <appa@perusio.net> - -=head1 REPOSITORY - -Source code at http://github.com/perusio/nginx-munin - -=head1 LICENSE - -MIT - -=cut - -## Munin config method. -if (exists $ARGV[0] and $ARGV[0] eq "config") { - print "graph_title nginx RAM usage\n"; - print "graph_vlabel RAM\n"; - print "graph_category nginx\n"; - print "ram.label RAM\n"; - print "graph_args --base 1024\n"; - - exit 0; -} else { - my $m = `ps u -p \$(pidof nginx) | awk 'NR > 1 {nm += \$5} END {print nm*1024}'`; - print "ram.value $m"; -} diff --git a/72.Deploy_munin_configuration/nginx_upstream b/72.Deploy_munin_configuration/nginx_upstream deleted file mode 100755 index ee3ab974..00000000 --- a/72.Deploy_munin_configuration/nginx_upstream +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/python -#requires log format as below -#log_format cache '$remote_addr - $host [$time_local] "$request" $status ' -# '$body_bytes_sent "$http_referer" ' -# 'rt=$request_time ut="$upstream_response_time" ' -# 'cs=$upstream_cache_status'; - -#License BSD -#Created by Simon Whittaker simon+github@swbh.net -#based on nginx_cache_hit_rate - -from __future__ import with_statement -import re -import sys -fname = "/var/log/nginx/access.log" # File to check - -if len(sys.argv) > 1: - if sys.argv[1]=="config": - print "graph_args --base 1000 -l 0" - print "graph_title NGINX Upstream times" - print "graph_category nginx" - print "graph_vlabel milliseconds" - print "upstream.label upstream" - print "upstream.warning 5000" - print "upstream.critical 10000" - print "graph_info Shows the average time of connections to upstream servers for the primary site" - sys.exit(0) - -with open(fname, "r") as f: - f.seek (0, 2) # Seek @ EOF - fsize = f.tell() # Get Size - f.seek (max (fsize-20480, 0), 0) # Set pos @ last n chars - lines = f.readlines() # Read to end - -lines = lines[-1000:] #last 1000 lines you might want to change this - -re1='.*?' # Non-greedy match on filler -re2='(ut)' # Word 1 -re3='(=)' # Any Single Character 1 -re4='([+-]?\\d*\\.\\d+)(?![-+0-9\\.])' # Float 1 - -rg = re.compile(re1+re2+re3+re4,re.IGNORECASE|re.DOTALL) -totaltimeforrequests=0 -numberofrequests=0 -for line in lines: - m = rg.search(line) - if m: - word1=m.group(1) - c1=m.group(2) - float1=m.group(3) - numberofrequests=numberofrequests+1 - totaltimeforrequests=totaltimeforrequests+float(float1) - -upstream=(totaltimeforrequests/numberofrequests)*1000 -upstream=int(upstream) -print "upstream.value "+str(upstream) diff --git a/72.Deploy_munin_configuration/nginx_vhost_traffic b/72.Deploy_munin_configuration/nginx_vhost_traffic deleted file mode 100755 index 826059ea..00000000 --- a/72.Deploy_munin_configuration/nginx_vhost_traffic +++ /dev/null @@ -1,103 +0,0 @@ -#!/bin/sh -# -# Script for monitoring nginx Virtual host output traffic -# -# Requierements: logtail awk -# one unique access log file with $bytes_sent value for more accuracy -# check http://wiki.nginx.org/NginxHttpLogModule -# -# Configuration Options (all options have defaults) -# [nginx_vhost_traffic] -# -# Virtual host list -# env.vhosts "example.com example.net example.org" -# -# Log path -# env.logdir = /var/log/nginx -# env.flogfile = access.log -# -# Position of the $bytes_sent in the access.log file -# env.bparam 11 -# -# Aggregate subdomains -# ex: example.com will match www.example.com, webmail.example.com and *example.com -# BUG: will also match also www.bad-example.com -# env.aggregate true #change to false to disable aggregation -# -# To report bugs, improvements or get updates -# see http://github.com/joanpc/nginix_vhost_traffic -# -# inspired in postfix_filtered_awk -# Copyright (c) 2010, Joan Perez i Cauhe - -LOGDIR=${logdir:-/var/log/nginx} -ACCESS_LOG=$LOGDIR/${logfile:-access.log} -LOGTAIL=${logtail:-`which logtail`} -STATEFILE=/var/lib/munin/plugin-state/nginx_vhost_traffic.state -VHOSTS=${vhosts:-`hostname`} -AGGREGATE=${aggregate:true} - -BPARAM=${bparam:-11} - -case $1 in - config) - DRAW=AREA - echo 'graph_title Nginx Virtual host traffic' - echo 'graph_vlabel bits out / ${graph_period}' - echo 'graph_args --base 1000 -l 0' - echo 'graph_category Nginx' - - i=0 - for vhost in $VHOSTS - do - i=$(($i + 1)) - echo vhost$i.label $vhost - echo vhost$i.type ABSOLUTE - echo vhost$i.cdef vhost$i,8,* - echo vhost$i.draw $DRAW - DRAW=STACK - done - - echo rest.label Rest - echo rest.type ABSOLUTE - echo rest.cdef rest,8,* - echo rest.draw STACK - exit 0;; -esac - -export BPARAM -export VHOSTS -export AGGREGATE - -# Awk Script -$LOGTAIL ${ACCESS_LOG} -o $STATEFILE | awk ' - -BEGIN { -split(ENVIRON["VHOSTS"], hosts) -for (host in hosts) { track[hosts[host]] = host} -} -{ - cn[$2]+=$ENVIRON["BPARAM"] -} -END { - for (host in cn) { - if (match(ENVIRON["AGGREGATE"], "true")) { - found = 0 - for (vhost in track) { - if (index(host, vhost)) { - res[vhost] += cn[host] - found = 1 - break - } - } - if (! found) rest+=cn[host] - } else { - if (host in track) { - res[host] += cn[host] - } else rest+=cn[host] - } - } - print "aggregate: " ENVIRON["AGGREGATE"] - for (vhost in track) print "vhost" track[vhost] ".value " res[vhost]+0 - print "rest.value " rest + 0 -}' diff --git a/72.Deploy_munin_configuration/nginx_working_set b/72.Deploy_munin_configuration/nginx_working_set deleted file mode 100755 index 04e8b809..00000000 --- a/72.Deploy_munin_configuration/nginx_working_set +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -# -# Munin plugin for monitoring Nginx working set -# -# by Mike Koss, Feb 12, 2012 - MIT License -# -#%# family=auto -#%# capabilities=autoconf - -case $1 in -config) - cat <<'EOF' -graph_title NGINX Working Set -graph_vlabel WS Bytes -graph_category nginx -graph_args --base 1024 -ws.label Working Set -EOF - exit 0 - ;; - -autoconf) - if [ "$(pidof nginx)" == "" ]; then - echo no - else - echo yes - fi - exit 0 - ;; -esac - -KBS=$(ps -o rss --no-heading -p $(pidof nginx)) -total=0 -for size in $KBS -do - total=$(($total + $size * 1024)) -done -echo ws.value $total -- GitLab