Skip to content
Snippets Groups Projects
Commit 8050be13 authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Cleaned history.

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 815 additions and 0 deletions
#!/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 Antnio P. P. Almeida
# Copyright (C) 2010 Antnio P. P. Almeida <appa@perusio.net>
# Copyright (C) 2010 Minato Miray <minatomiray@gmail.com>
# Author: Antnio 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";
#!/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";
}
#!/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 $?
#!/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";
}
#!/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)
#!/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
}'
#!/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
#!/bin/bash
source /root/envsetup/envsetup.conf
DEBIAN_FRONTEND=noninteractive aptitude install -y ferm
cp ferm.conf /etc/ferm/ferm.conf
service ferm restart
# -*- shell-script -*-
#
# Configuration file for ferm(1).
#
table filter {
chain INPUT {
policy DROP;
# connection tracking
mod state state INVALID DROP;
mod state state (ESTABLISHED RELATED) ACCEPT;
# allow local packet
interface lo ACCEPT;
# respond to ping
proto icmp ACCEPT;
# allow SSH connections
proto tcp dport ssh ACCEPT;
# http https
proto tcp dport (http https) ACCEPT;
# snmp
proto udp dport snmp ACCEPT;
}
chain OUTPUT {
policy ACCEPT;
# connection tracking
#mod state state INVALID DROP;
mod state state (ESTABLISHED RELATED) ACCEPT;
}
chain FORWARD {
policy DROP;
# connection tracking
mod state state INVALID DROP;
mod state state (ESTABLISHED RELATED) ACCEPT;
}
}
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import utils
def setup(interactive=True):
dir_path = utils.get_dir(__file__)
# This script should be installed only if the home partition is a mount point
cmds = [
dict(line='write', template='%s/check_services.py' % dir_path, target='/usr/local/bin/check_services.py'),
'chmod 755 /usr/local/bin/check_services.py',
'cat /etc/rc.local | grep "/usr/local/bin/check_services.py" || sed -i "s/^exit 0/\(sleep 200 \&\& \/usr\/local\/bin\/check_services\.py \&\)\\n\\nexit 0/g" /etc/rc.local',
]
utils.run_commands(cmds)
This diff is collapsed.
This diff is collapsed.
# EnvSetup
Script to setup and configure softwares used in our servers.
## Dependencies
* python3
## How to add a software setup
* Add a folder next to "envsetup.py" named using the following pattern: "<number>.<name>".
The number should not be used by any other setup.
* Add a file named "0_setup.py" in this folder.
* Add a the actions that have to be done in a function named "setup" in the "0_setup.py" file.
## Notes
* All the adjustable configurations must be in the "conf.py" file.
* The "setup" function should be non interactive.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment