Ин мақола лоиҳаро муҳокима хоҳад кард
Барои дидани таҳлилҳо дар асоси гузоришҳо, мо панели идоракуниро барои Grafana эҷод мекунем.
Ҳар касе манфиатдор, ба гурба хуш омадед.
Nginx, grafana -ро ба таври стандартӣ насб кунед.
Насб кардани кластери клик бо истифода аз ansible-playbook аз
Эҷоди пойгоҳи додаҳо ва ҷадвалҳо дар Clickhouse
Дар ин
Мо ҳар як дархостро дар ҳар сервер дар кластери Clickhouse як ба як мегузорем.
Қайдҳои муҳим. Дар ин сатр, logs_cluster бояд бо номи кластери шумо аз файли clickhouse_remote_servers.xml байни "remote_servers" ва "shard" иваз карда шавад.
ENGINE = Distributed('logs_cluster', 'nginx', 'access_log_shard', rand())
Насб ва танзим кардани nginx-log-collector-rpm
Nginx-log-collector rpm надорад. Ин ҷо
Бастаи 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
Танзимоти /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/
Насб кардани nginx
Танзимоти умумии 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;
}
Як мизбони виртуалӣ:
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;
}
}
Ба файли /etc/hosts ҳостҳои виртуалӣ илова кунед:
ip-адрес-сервера-с-nginx vhost1
Эмулятори сервери HTTP
Ҳамчун эмулятори сервери HTTP мо истифода хоҳем кард
Nodejs-stub-server rpm надорад. Ин ҷо
Бастаи nodejs-stub-server -ро дар 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
Санҷиши стресс
Мо озмоишро бо истифода аз Apache бенчмарк мегузаронем.
Онро насб кунед:
yum install -y httpd-tools
Мо озмоишро бо истифодаи бенчмарк Apache аз 5 серверҳои гуногун оғоз мекунем:
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
Насб кардани Grafana
Шумо дар вебсайти расмии Grafana панели идоракуниро нахоҳед ёфт.
Бинобар ин, мо онро дастй ичро мекунем.
Шумо метавонед панели захирашудаи маро пайдо кунед
Шумо инчунин бояд тағирёбандаи ҷадвалро бо мундариҷа эҷод кунед nginx.access_log
.
Дархостҳои умумии ягона:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter GROUP BY t
Дархостҳои нокомии Singlestat:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter AND status NOT IN (200, 201, 401) GROUP BY t
Фоизи нокомии ягона:
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
Вақти вокуниши миёнаи ягонаи ягона:
SELECT
1, avg(request_time) FROM $table
WHERE $timeFilter GROUP BY 1
Вақти максималии вокуниши ягона:
SELECT
1 as t, max(request_time) as c
FROM $table
WHERE $timeFilter GROUP BY t
Ҳолати ҳисоб:
$columns(status, count(*) as c) from $table
Барои баровардани маълумот ба монанди пирог, шумо бояд плагинро насб кунед ва графанаро аз нав оғоз кунед.
grafana-cli plugins install grafana-piechart-panel
service grafana-server restart
Ҳолати Pie TOP 5:
SELECT
1, /* fake timestamp value */
status,
sum(status) AS Reqs
FROM $table
WHERE $timeFilter
GROUP BY status
ORDER BY Reqs desc
LIMIT 5
Минбаъд ман дархостҳоро бе скриншотҳо медиҳам:
Ҳисоб кунед 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
Вақти вокуниш:
$rate(avg(request_time) as request_time) FROM $table
Вақти вокуниш ба болооб (вақти вокуниш ба болооб):
$rate(avg(arrayElement(upstream_response_time,1)) as upstream_response_time) FROM $table
Ҳолати ҳисобкунии ҷадвал барои ҳама vhost:
$columns(status, count(*) as c) from $table
Намоиши умумии панели асбобҳо
Муқоисаи avg() ва quantile()
авг()
миқдор ()
Хулоса:
Ман умедворам, ки ҷомеа дар таҳия/озмоиш ва истифодаи nginx-log-collector иштирок мекунад.
Ва вақте ки касе nginx-log-collector -ро амалӣ мекунад, онҳо ба шумо хоҳанд гуфт, ки чӣ қадар диск, RAM ва CPU захира кардаанд.
Каналҳои Telegram:
Миллисония:
Миллисонияҳо барои кӣ муҳиманд, лутфан дар ин ҷо нависед ё овоз диҳед
Манбаъ: will.com