Commit 06690621 authored by Etersoft's avatar Etersoft Committed by Vitaly Lipatov

add azbyka_stat

parent 4289855f
#!/bin/sh
# azbyka_deti IP
set_mysql_host()
{
subst "s|.* mysql.$1|$2 mysql.$1|g" /etc/hosts
}
MYSQL01=$(resolve -s a01.azbyka.ru)
AD=/azbyka
for i in $AD/azbyka_* ; do
BN="$(basename $i)"
if test -f $i/A01-HOSTED ; then
set_mysql_host $BN $MYSQL01
fi
done
#!/bin/sh
NS=/var/local/nginx-stat/apache-errors.txt
echo "All apache errors logs " > $NS
date >>$NS
TODAY=$(date "+%a %b %d")
filter_today()
{
grep "\[$TODAY"
}
for i in /azbyka/*/log/*_error.log ; do
[ -s "$i" ] || continue
tail "$i" -n100 | filter_today >$0.tmp
[ -s "$0.tmp" ] || continue
echo
echo "$i"
cat $0.tmp
done >>$NS
rm -f $0.tmp
#!/bin/sh
NS=/var/local/nginx-stat/apache-errors-full.txt
echo "All apache errors logs " > $NS
date >>$NS
for i in /azbyka/*/log/*_error.log ; do
[ -s "$i" ] || continue
echo
echo "$i"
tail "$i" -n100
done >>$NS
#!/bin/sh
NS=/var/local/nginx-stat/nginx-errors-full.txt
echo "All nginx errors logs " > $NS
date >>$NS
for i in /var/log/nginx/*error*.log ; do
[ -s "$i" ] || continue
echo
echo "$i"
tail "$i" -n100
done >>$NS
#!/bin/sh
NS=/var/local/nginx-stat/nginx-errors.txt
echo "All nginx errors logs " > $NS
date >>$NS
TODAY=$(date "+%Y/%m/%d")
filter_today()
{
grep "^$TODAY"
}
TODAYA=$(date "+%d/%b/%Y")
filter_todaya()
{
grep "\[$TODAYA"
}
for i in /var/log/nginx/*error*.log ; do
[ -s "$i" ] || continue
tail "$i" -n100 | filter_today >$0.tmp
tail "$i" -n100 | filter_todaya >>$0.tmp
[ -s "$0.tmp" ] || continue
echo
echo "$i"
cat $0.tmp
done >>$NS
rm -f $0.tmp
#!/bin/sh
head -n2 url_a.sh.access.log.stat >$0.out
for i in *.stat ; do
head -n 5 $i | tail -n 3
done | grep -v "^===" | grep -v "^percent" | sort -k2 -n -r >>$0.out
ST='style="text-align:right;"'
while read per overall count mid url ; do
overall=$(echo $overall | sed -e "s|\..*||g")
mid=$(echo $mid | sed -e "s|\..*||g")
echo "|-"
echo "| $ST | $per || $ST | $overall || $ST | $count || $ST | $mid || $url"
done <$0.out >$0.outwiki
NS=/var/local/nginx-stat/stat.html
cat << EOF >$NS
<!DOCTYPE html>
<html lang="ru" dir="ltr" class="client-nojs">
<head>
<meta charset="UTF-8" />
<title>Азбука/nginx</title>
</head>
<body>
$(date)
<table border="0">
<tr>
<td style="text-align:center;">&#160;% от
<p>проекта
</p>
</td>
<td style="text-align:center;">Общее время,
<p>сек
</p>
</td>
<td style="text-align:center;">Кол-во запросов
</td>
<td style="text-align:center;">Среднее время
<p>запроса, мс</p>
</td>
<td style="text-align:center;">URL
</td></tr>
EOF
cat $0.out | head -n 102 | tail -n 100 | while read per overall count mid url ; do
overall=$(echo $overall | sed -e "s|\..*||g")
mid=$(echo $mid | sed -e "s|\..*||g")
echo "<tr>"
echo "<td style=\"text-align:right;\">$per</td>"
echo "<td style=\"text-align:right;\">$overall</td>"
echo "<td style=\"text-align:right;\">$count</td>"
echo "<td style=\"text-align:right;\">$mid</td>"
echo "<td>$url</td></tr>"
done >>$NS
cat << EOF >>$NS
</table>
</body>
EOF
#!/bin/sh
P=$(pwd)
cd ..
for i in /var/log/nginx/*access.log ; do
[ "$i" = /var/log/nginx/azbyka.ru-access.log ] && continue
./url_stats.sh $i
cp -f url_report.txt $P/$0.$(basename $i).stat
done
#!/bin/sh
ST='style="text-align:right;"'
while read per overall count mid url ; do
overall=$(echo $overall | sed -e "s|\..*||g")
mid=$(echo $mid | sed -e "s|\..*||g")
echo "|-"
echo "| $ST | $per || $ST | $overall || $ST | $count || $ST | $mid || $url"
done < url_a_p.sh.azbyka.stat >$0.outwiki
NS=/var/local/nginx-stat/stat-projects.html
cat << EOF >$NS
<!DOCTYPE html>
<html lang="ru" dir="ltr" class="client-nojs">
<head>
<meta charset="UTF-8" />
<title>Азбука/nginx</title>
</head>
<body>
<h2>По проектам крупно</h2>
$(date)
<table border="0">
<tr>
<td style="text-align:center;">&#160;% от
<p>проекта
</p>
</td>
<td style="text-align:center;">Общее время,
<p>сек
</p>
</td>
<td style="text-align:center;">Кол-во запросов
</td>
<td style="text-align:center;">Среднее время
<p>запроса, мс</p>
</td>
<td style="text-align:center;">URL
</td></tr>
EOF
cat url_a_p.sh.azbyka.stat | while read per overall count mid url ; do
overall=$(echo $overall | sed -e "s|\..*||g")
mid=$(echo $mid | sed -e "s|\..*||g")
echo "<tr>"
echo "<td style=\"text-align:right;\">$per</td>"
echo "<td style=\"text-align:right;\">$overall</td>"
echo "<td style=\"text-align:right;\">$count</td>"
echo "<td style=\"text-align:right;\">$mid</td>"
echo "<td>$url</td></tr>"
done >>$NS
cat << EOF >>$NS
</table>
</body>
EOF
#!/bin/sh
P=$(pwd)
cd ..
for i in /var/log/nginx/azbyka_*access.log ; do
[ "$i" = /var/log/nginx/azbyka.ru-access.log ] && continue
#./url_stats_project.sh $i
#cp -f url_report.txt $P/$0.$(basename $i).stat
./url_stats_project.py <$i
done >$P/$0.azbyka.stat
#!/usr/bin/env python
import sys
urls = {}
try:
while 1:
line = raw_input()
line_arr = line.split(" ")
try:
host = line_arr[-1]
host = host[1:]
host = host[:-1]
# CHANGE HERE
url = line_arr[6]
url = "/"+url.split("/")[1]
#url = ""
t = float(line_arr[-2])
# print host, url, t
try:
urls[host + url] = (urls[host + url][0] + t, urls[host + url][1] + 1)
except KeyError, e:
urls[host + url] = (t, 1)
except ValueError, e:
pass
except EOFError, e:
pass
def sort_by_value(d):
""" Returns the keys of dictionary d sorted by their values """
items=d.items()
backitems=[ [v[1],v[0]] for v in items]
backitems.sort(reverse=True)
return [backitems[i][1] for i in range(0,len(backitems))]
if (len(sys.argv) > 1):
f = open(sys.argv[1], 'r')
for k in f.readlines():
k = k.strip()
try:
print urls[k][0], urls[k][1], urls[k][0] / urls[k][1], k
except:
print 0, 0, k
else:
i = 0
alltime = 0
# FIXME
# reduce(lambda v1, v2 : v1[0] + v2[0], a)
for k in sort_by_value(urls):
alltime = alltime + urls[k][0]
i += 1
if i > 100: break
i = 0
for k in sort_by_value(urls):
print round(urls[k][0]*100/alltime,0), urls[k][0], urls[k][1], round (urls[k][0] * 1000 / urls[k][1], 0), k
i += 1
if i > 100: break
#!/bin/sh
FILE=/var/log/nginx/*-access.log
test -z "$1" || FILE="$1"
echo "=== Requests which took most of the time (from $FILE) ===" > url_report.txt
echo "percent - overall time - number of requests - average time - url" >> url_report.txt
cat "$FILE" | ./url_stats_project.py >> url_report.txt
#grep "\[25/Dec/2010:" "$FILE" | ./url_stats.py >> url_report.txt
#cat /tmp/report.txt | mail -s "url performance report" root
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment