E kūkākūkā kēia ʻatikala i ka papahana
No ka ʻike ʻana i nā ʻikepili e pili ana i nā lāʻau, e hana mākou i kahi dashboard no Grafana.
ʻO ka poʻe hoihoi, hoʻokipa i ka pōpoki.
E hoʻouka i ka nginx, grafana ma ke ala maʻamau.
Ke hoʻouka ʻana i kahi pūʻulu clickhouse me ka hoʻohana ʻana i ka ansible-playbook mai
Ke hana ʻana i nā ʻikepili a me nā papa ma Clickhouse
I keia
Hana mākou i kēlā me kēia noi i kēlā me kēia kikowaena ma ka hui Clickhouse.
Palapala nui. Ma kēia laina, pono e hoʻololi i ka logs_cluster me kou inoa cluster mai ka waihona clickhouse_remote_servers.xml ma waena o "remote_servers" a me "shard".
ENGINE = Distributed('logs_cluster', 'nginx', 'access_log_shard', rand())
Ke hoʻouka a hoʻonohonoho ʻana i ka nginx-log-collector-rpm
ʻAʻohe rpm ʻo Nginx-log-collector. Eia
E hoʻouka i ka pahu 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
Hoʻoponopono i ka 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/
Hoʻonohonoho i ka nginx
ʻO ka hoʻonohonoho nginx maʻamau:
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;
}
Hoʻokahi hoʻokipa virtual:
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;
}
}
Hoʻohui i nā pūʻali virtual i ka faila /etc/hosts:
ip-адрес-сервера-с-nginx vhost1
Emulator kikowaena HTTP
Ma ke ʻano he emulator server HTTP e hoʻohana mākou
ʻAʻohe rpm nodejs-stub-server. Eia
E hoʻouka i ka pūʻolo nodejs-stub-server ma ka 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
ʻO ka hoʻāʻo ʻana
Hana mākou i ka hoʻāʻo me ka hoʻohana ʻana i ka benchmark Apache.
E hoʻokomo iā ia:
yum install -y httpd-tools
Hoʻomaka mākou i ka hoʻāʻo ʻana me ka hoʻohana ʻana i ka benchmark Apache mai 5 mau kikowaena ʻokoʻa:
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
Hoʻonohonoho iā Grafana
ʻAʻole ʻoe e ʻike i kahi dashboard ma ka pūnaewele mana o Grafana.
No laila, e hana mākou me ka lima.
Hiki iā ʻoe ke ʻike i kaʻu dashboard i mālama ʻia
Pono ʻoe e hana i kahi ʻano pākaukau me nā mea i loko nginx.access_log
.
Singlestat huina noi:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter GROUP BY t
Nā noi i hāʻule ʻole ʻo Singlestat:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter AND status NOT IN (200, 201, 401) GROUP BY t
Singlestat hāʻule pākēneka:
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 Manawa pane:
SELECT
1, avg(request_time) FROM $table
WHERE $timeFilter GROUP BY 1
Singlestat Max Manawa pane:
SELECT
1 as t, max(request_time) as c
FROM $table
WHERE $timeFilter GROUP BY t
Helu kūlana:
$columns(status, count(*) as c) from $table
No ka hoʻopuka ʻana i ka ʻikepili e like me kahi pai, pono ʻoe e hoʻokomo i ka plugin a hoʻomaka hou i ka grafana.
grafana-cli plugins install grafana-piechart-panel
service grafana-server restart
Kūlana 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
E hāʻawi hou wau i nā noi me ka ʻole o nā screenshots:
E helu http_user_agent:
$columns(http_user_agent, count(*) c) FROM $table
Maikaʻi/ʻino:
$rate(countIf(status = 200) AS good, countIf(status != 200) AS bad) FROM $table
Ka manawa pane:
$rate(avg(request_time) as request_time) FROM $table
Ka manawa pane upstream (1st upstream response time):
$rate(avg(arrayElement(upstream_response_time,1)) as upstream_response_time) FROM $table
Ke kūlana helu papa no nā vhost a pau:
$columns(status, count(*) as c) from $table
Nānā nui o ka dashboard
Hoʻohālikelike o avg() a me quantile()
avg()
quantile()
Panina:
Manaʻo wau e komo ke kaiāulu i ka hoʻomohala ʻana a me ka hoʻohana ʻana i ka nginx-log-collector.
A ke hoʻokō kekahi i ka nginx-log-collector, e haʻi lākou iā ʻoe i ka nui o ka disk, RAM, a me ka CPU a lākou i mālama ai.
Nā ala Telegram:
Milikikona:
No wai ka milliseconds, e ʻoluʻolu e kākau a koho paha i kēia
Source: www.habr.com