Ta članek bo obravnaval projekt
Za ogled analitike na podlagi dnevnikov bomo ustvarili nadzorno ploščo za Grafana.
Kogar zanima, dobrodošli v kat.
Namestite nginx, grafana na standardni način.
Namestitev gruče Clickhouse z uporabo ansible-playbook from
Izdelava baz podatkov in tabel v Clickhouseu
V tem
Vsako zahtevo naredimo eno za drugo na vsakem strežniku v gruči Clickhouse.
Pomembna opomba. V tej vrstici je treba logs_cluster zamenjati z imenom vaše gruče iz datoteke clickhouse_remote_servers.xml med »remote_servers« in »shard«.
ENGINE = Distributed('logs_cluster', 'nginx', 'access_log_shard', rand())
Namestitev in konfiguracija nginx-log-collector-rpm
Nginx-log-collector nima rpm. Tukaj
Namestite paket rpm nginx-log-collector-rpm
yum -y install yum-plugin-copr
yum copr enable antonpatsev/nginx-log-collector-rpm
yum -y install nginx-log-collector
systemctl start nginx-log-collector
Uredite konfiguracijo /etc/nginx-log-collector/config.yaml:
.......
upload:
table: nginx.access_log
dsn: http://ip-адрес-кластера-clickhouse:8123/
- tag: "nginx_error:"
format: error # access | error
buffer_size: 1048576
upload:
table: nginx.error_log
dsn: http://ip-адрес-кластера-clickhouse:8123/
Nastavitev nginx
Splošna konfiguracija nginx:
user nginx;
worker_processes auto;
#error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format avito_json escape=json
'{'
'"event_datetime": "$time_iso8601", '
'"server_name": "$server_name", '
'"remote_addr": "$remote_addr", '
'"remote_user": "$remote_user", '
'"http_x_real_ip": "$http_x_real_ip", '
'"status": "$status", '
'"scheme": "$scheme", '
'"request_method": "$request_method", '
'"request_uri": "$request_uri", '
'"server_protocol": "$server_protocol", '
'"body_bytes_sent": $body_bytes_sent, '
'"http_referer": "$http_referer", '
'"http_user_agent": "$http_user_agent", '
'"request_bytes": "$request_length", '
'"request_time": "$request_time", '
'"upstream_addr": "$upstream_addr", '
'"upstream_response_time": "$upstream_response_time", '
'"hostname": "$hostname", '
'"host": "$host"'
'}';
access_log syslog_server=unix:/var/run/nginx_log.sock,nohostname,tag=nginx avito_json; #ClickHouse
error_log syslog_server=unix:/var/run/nginx_log.sock,nohostname,tag=nginx_error; #ClickHouse
#access_log /var/log/nginx/access.log main;
proxy_ignore_client_abort on;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
En virtualni gostitelj:
vhost1.conf:
upstream backend {
server ip-адрес-сервера-с-stub_http_server:8080;
server ip-адрес-сервера-с-stub_http_server:8080;
server ip-адрес-сервера-с-stub_http_server:8080;
server ip-адрес-сервера-с-stub_http_server:8080;
server ip-адрес-сервера-с-stub_http_server:8080;
}
server {
listen 80;
server_name vhost1;
location / {
proxy_pass http://backend;
}
}
Dodajte navidezne gostitelje v datoteko /etc/hosts:
ip-адрес-сервера-с-nginx vhost1
Emulator strežnika HTTP
Kot emulator strežnika HTTP bomo uporabili
Nodejs-stub-server nima rpm. Tukaj
Namestite paket nodejs-stub-server na upstream nginx rpm
yum -y install yum-plugin-copr
yum copr enable antonpatsev/nodejs-stub-server
yum -y install stub_http_server
systemctl start stub_http_server
Stresno testiranje
Testiranje izvajamo z uporabo Apache benchmarka.
Namestite:
yum install -y httpd-tools
Testiranje začnemo z uporabo primerjalnega testa Apache na 5 različnih strežnikih:
while true; do ab -H "User-Agent: 1server" -c 10 -n 10 -t 10 http://vhost1/; sleep 1; done
while true; do ab -H "User-Agent: 2server" -c 10 -n 10 -t 10 http://vhost1/; sleep 1; done
while true; do ab -H "User-Agent: 3server" -c 10 -n 10 -t 10 http://vhost1/; sleep 1; done
while true; do ab -H "User-Agent: 4server" -c 10 -n 10 -t 10 http://vhost1/; sleep 1; done
while true; do ab -H "User-Agent: 5server" -c 10 -n 10 -t 10 http://vhost1/; sleep 1; done
Postavitev Grafana
Na uradni spletni strani Grafana ne boste našli nadzorne plošče.
Zato bomo to storili ročno.
Najdete mojo shranjeno nadzorno ploščo
Ustvariti morate tudi spremenljivko tabele z vsebino nginx.access_log
.
Skupno število zahtev Singlestat:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter GROUP BY t
Singlestat neuspele zahteve:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter AND status NOT IN (200, 201, 401) GROUP BY t
Odstotek neuspešnih Singlestat:
SELECT
1 as t, (sum(status = 500 or status = 499)/sum(status = 200 or status = 201 or status = 401))*100 FROM $table
WHERE $timeFilter GROUP BY t
Povprečni odzivni čas Singlestat:
SELECT
1, avg(request_time) FROM $table
WHERE $timeFilter GROUP BY 1
Največji odzivni čas Singlestat:
SELECT
1 as t, max(request_time) as c
FROM $table
WHERE $timeFilter GROUP BY t
Stanje štetja:
$columns(status, count(*) as c) from $table
Če želite izpisati podatke kot torto, morate namestiti vtičnik in znova zagnati grafano.
grafana-cli plugins install grafana-piechart-panel
service grafana-server restart
Pita TOP 5 Status:
SELECT
1, /* fake timestamp value */
status,
sum(status) AS Reqs
FROM $table
WHERE $timeFilter
GROUP BY status
ORDER BY Reqs desc
LIMIT 5
Nadalje bom podal zahteve brez posnetkov zaslona:
Štej http_user_agent:
$columns(http_user_agent, count(*) c) FROM $table
GoodRate/BadRate:
$rate(countIf(status = 200) AS good, countIf(status != 200) AS bad) FROM $table
Odzivni čas:
$rate(avg(request_time) as request_time) FROM $table
Odzivni čas navzgor (1. odzivni čas navzgor):
$rate(avg(arrayElement(upstream_response_time,1)) as upstream_response_time) FROM $table
Status štetja tabele za vse vhost:
$columns(status, count(*) as c) from $table
Splošni pogled na armaturno ploščo
Primerjava avg() in quantile()
povprečje()
kvantil()
Zaključek:
Upam, da se bo skupnost vključila v razvoj/testiranje in uporabo nginx-log-collector.
In ko nekdo implementira nginx-log-collector, vam bo povedal, koliko diska, RAM-a in CPE-ja je prihranil.
Telegram kanali:
Milisekunde:
Komur so milisekunde pomembne, prosim napišite ali glasujte v tem
Vir: www.habr.com