Dan l-artikolu ser jiddiskuti l-proġett
Biex tara l-analiżi bbażata fuq zkuk, se noħolqu dashboard għal Grafana.
Kull min hu interessat, merħba lill-qattus.
Installa nginx, grafana bil-mod standard.
Installazzjoni ta 'cluster clickhouse bl-użu ta' ansible-playbook minn
Ħolqien ta 'databases u tabelli fi Clickhouse
F'dan
Aħna nagħmlu kull talba waħda waħda fuq kull server fil-cluster Clickhouse.
Nota importanti. F'din il-linja, logs_cluster jeħtieġ li jiġi sostitwit bl-isem tal-cluster tiegħek mill-fajl clickhouse_remote_servers.xml bejn "remote_servers" u "shard".
ENGINE = Distributed('logs_cluster', 'nginx', 'access_log_shard', rand())
Installazzjoni u konfigurazzjoni nginx-log-collector-rpm
Nginx-log-collector m'għandux rpm. Hawn
Installa l-pakkett 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
Editja l-konfigurazzjoni /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/
Twaqqif ta 'nginx
Konfigurazzjoni ġenerali 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;
}
Host virtwali wieħed:
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;
}
}
Żid hosts virtwali mal-fajl /etc/hosts:
ip-адрес-сервера-с-nginx vhost1
Emulatur tas-server HTTP
Bħala emulatur ta 'server HTTP se nużaw
Nodejs-stub-server m'għandux rpm. Hawn
Installa pakkett nodejs-stub-server fuq nginx rpm upstream
yum -y install yum-plugin-copr
yum copr enable antonpatsev/nodejs-stub-server
yum -y install stub_http_server
systemctl start stub_http_server
Ittestjar tal-istress
Aħna nwettqu l-ittestjar bl-użu ta 'benchmark Apache.
Installaha:
yum install -y httpd-tools
Nibdew nittestjaw bl-użu tal-benchmark Apache minn 5 servers differenti:
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
Twaqqif ta’ Grafana
Mhux se ssib dashboard fuq il-websajt uffiċjali ta' Grafana.
Għalhekk, se nagħmluha bl-idejn.
Tista' ssib id-dashboard salvat tiegħi
Għandek bżonn ukoll li toħloq tabella varjabbli bil-kontenut nginx.access_log
.
Singlestat Total Talbiet:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter GROUP BY t
Talbiet Singlestat falluti:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter AND status NOT IN (200, 201, 401) GROUP BY t
Perċentwal ta' Waqfien ta' 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
Ħin medju ta' Rispons ta' Singlestat:
SELECT
1, avg(request_time) FROM $table
WHERE $timeFilter GROUP BY 1
Ħin ta' Rispons Massimu ta' Singlestat:
SELECT
1 as t, max(request_time) as c
FROM $table
WHERE $timeFilter GROUP BY t
Status tal-għadd:
$columns(status, count(*) as c) from $table
Biex toħroġ dejta bħal pie, trid tinstalla l-plugin u terġa 'tibda grafana.
grafana-cli plugins install grafana-piechart-panel
service grafana-server restart
Pie 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
Barra minn hekk se nagħti talbiet mingħajr screenshots:
Għadd 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
Żmien tar-Reazzjoni:
$rate(avg(request_time) as request_time) FROM $table
Ħin ta' rispons upstream (l-ewwel ħin ta' rispons upstream):
$rate(avg(arrayElement(upstream_response_time,1)) as upstream_response_time) FROM $table
Status tal-Għadd tat-Tabella għall-vhost kollha:
$columns(status, count(*) as c) from $table
Veduta ġenerali tad-dashboard
Tqabbil ta' avg() u quantile()
medja ()
kwantile ()
Konklużjoni:
Nispera li l-komunità tinvolvi ruħha fl-iżvilupp/l-ittestjar u l-użu ta 'nginx-log-collector.
U meta xi ħadd jimplimenta nginx-log-collector, jgħidlek kemm iffranka fuq disk, RAM u CPU.
Stazzjonijiet tat-telegramma:
Millisekondi:
Għal min jimpurtaw il-millisekondi, jekk jogħġbok ikteb jew ivvota f'dan
Sors: www.habr.com