O lenei tusiga o le a talanoaina le poloketi
Ina ia va'ai au'ili'iliga e ala i ogalaau, se'i o tatou faia se dashboard mo Grafana.
O ai e popole, fa'afeiloa'i i lalo o pusi.
Faʻapipiʻi nginx, grafana i le auala masani.
Fa'apipi'i le kulupu clickhouse ma le ansible-playbook mai
Fausia se faʻamaumauga ma laulau ile Clickhouse
I lena
Matou te faia talosaga taʻitasi i luga o sapalai taʻitasi o le Clickhouse cluster.
Fa'amatalaga taua. I lenei laina, e tatau ona sui le logs_cluster i lou igoa fuifui mai le faila clickhouse_remote_servers.xml i le va o le "remote_servers" ma le "shard".
ENGINE = Distributed('logs_cluster', 'nginx', 'access_log_shard', rand())
Faʻapipiʻi ma faʻatulagaina nginx-log-collector-rpm
Nginx-log-collector e leai se rpm. O iinei
Faʻapipiʻi le pusa 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
Fa'atonu config /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/
Faʻatulagaina nginx
General nginx config:
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;
}
Ta'ita'i fa'apitoa tasi:
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;
}
}
Faʻaopoopo 'au faʻapitoa i le /etc/hosts faila:
ip-адрес-сервера-с-nginx vhost1
HTTP server emulator
I le avea ai o se emulator server HTTP o le a matou faʻaaogaina
nodejs-stub-server e leai se rpm. O iinei
Fa'apipi'i le afifi nodejs-stub-server ile 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
Su'ega Fa'atiga
O suʻega e faia e faʻaaoga ai le faʻailoga a Apache.
Fa'apipi'i:
yum install -y httpd-tools
Matou te amata suʻega e faʻaaoga ai le faʻailoga Apache mai 5 'auʻaunaga eseese:
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
Faʻatulagaina le Grafana
E te le mauaina se dashboard i luga o le upega tafaʻilagi aloaia a Grafana.
O le mea lea, o le a tatou faia i le lima.
E mafai ona e mauaina la'u dashboard fa'asaoina
E te manaʻomia foʻi le fatuina o se laulau fesuiaʻi ma le anotusi nginx.access_log
.
Singlestat Aofa'iga Talosaga:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter GROUP BY t
Talosaga ua le manuia le Singlestat:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter AND status NOT IN (200, 201, 401) GROUP BY t
Singlestat Fa'aletonu pasene:
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
Singlestat Avg Tali Taimi:
SELECT
1, avg(request_time) FROM $table
WHERE $timeFilter GROUP BY 1
Singlestat Max Taimi Tali:
SELECT
1 as t, max(request_time) as c
FROM $table
WHERE $timeFilter GROUP BY t
Tulaga Faitau:
$columns(status, count(*) as c) from $table
Ina ia maua faʻamatalaga e pei o se pai, e manaʻomia ona e faʻapipiʻi le plugin ma toe faʻapipiʻi le grafana.
grafana-cli plugins install grafana-piechart-panel
service grafana-server restart
Pie TOP 5 Tulaga:
SELECT
1, /* fake timestamp value */
status,
sum(status) AS Reqs
FROM $table
WHERE $timeFilter
GROUP BY status
ORDER BY Reqs desc
LIMIT 5
E le gata i lea, o le a ou tuuina atu talosaga e aunoa ma ni screenshots:
Faitau http_user_agent:
$columns(http_user_agent, count(*) c) FROM $table
Su'ega Lelei/Leaga:
$rate(countIf(status = 200) AS good, countIf(status != 200) AS bad) FROM $table
taimi tali:
$rate(avg(request_time) as request_time) FROM $table
Taimi tali i luga (taimi tali o le 1st upstream):
$rate(avg(arrayElement(upstream_response_time,1)) as upstream_response_time) FROM $table
Tulaga Faitau Laulau mo vhosts uma:
$columns(status, count(*) as c) from $table
Vaaiga lautele o le dashboard
Fa'atusatusaina avg() ma quantile()
fua()
tele()
Faaiuga:
Faʻamoemoe o le a aʻafia le alalafaga i le atinaʻeina / suʻega ma le faʻaaogaina o le nginx-log-collector.
Ma pe a faʻaaogaina e se tasi le nginx-log-collector, o le a ia taʻu atu ia te oe le tele na ia faʻasaoina le disk, RAM, PPU.
Telegram auala:
Miliseconds:
O ai e popole i milliseconds, tusi pe palota, faamolemole, i lenei
puna: www.habr.com