Isiokwu a ga-atụle ọrụ ahụ
Ka ilele nyocha dabere na ndekọ, anyị ga-emepụta dashboard maka Grafana.
Onye ọ bụla nwere mmasị, nabata nwamba.
Wụnye nginx, grafana n'ụzọ ọkọlọtọ.
Ịwụnye ụyọkọ clickhouse site na iji akwụkwọ egwu egwu nwere ike
Ịmepụta ọdụ data na tebụl na Clickhouse
Na nke a
Anyị na-arịọ arịrịọ nke ọ bụla n'otu n'otu na sava ọ bụla na ụyọkọ Clickhouse.
Ihe ndetu dị mkpa. N'ahịrị a, ekwesịrị iji aha ụyọkọ gị dochie logs_cluster site na faịlụ clickhouse_remote_servers.xml n'etiti "remote_servers" na "shard".
ENGINE = Distributed('logs_cluster', 'nginx', 'access_log_shard', rand())
Ịwụnye na ịhazi nginx-log-collector-rpm
Nginx-log-collector enweghị rpm. Ebe a
Wụnye ngwugwu 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
Dezie nhazi /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/
Ịtọlite nginx
Nhazi nginx izugbe:
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;
}
Otu onye nnabata mebere:
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;
}
}
Tinye ndị ọbịa mebere na faịlụ /etc/hosts:
ip-адрес-сервера-с-nginx vhost1
Ihe nkesa HTTP emulator
Dịka emulator nkesa HTTP anyị ga-eji
Ihe nkesa Nodejs-stub enweghị rpm. Ebe a
Wụnye ngwungwu ihe nkesa nodejs-stub na nginx rpm elu
yum -y install yum-plugin-copr
yum copr enable antonpatsev/nodejs-stub-server
yum -y install stub_http_server
systemctl start stub_http_server
Nnwale nrụgide
Anyị na-eme nnwale site na iji benchmark Apache.
Wụnye ya:
yum install -y httpd-tools
Anyị na-amalite ịnwale iji Apache benchmark sitere na sava 5 dị iche iche:
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
Ịtọlite Grafana
Ị gaghị ahụ dashboard na webụsaịtị Grafana gọọmentị.
Ya mere, anyị ga-eji aka mee ya.
Ị nwere ike ịchọta dashboard m echekwara
Ịkwesịrị ịmepụta mgbanwe tebụl na ọdịnaya nginx.access_log
.
Arịrịọ Singlestat:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter GROUP BY t
Arịrịọ Singlestat dara:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter AND status NOT IN (200, 201, 401) GROUP BY t
Pasent na-adaghị 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
Oge nzaghachi Singlestat:
SELECT
1, avg(request_time) FROM $table
WHERE $timeFilter GROUP BY 1
Oge nzaghachi Singlestat Max:
SELECT
1 as t, max(request_time) as c
FROM $table
WHERE $timeFilter GROUP BY t
Ọnụọgụgụ:
$columns(status, count(*) as c) from $table
Iji wepụta data dị ka achịcha, ịkwesịrị ịwụnye ngwa mgbakwunye wee malitegharịa grafana.
grafana-cli plugins install grafana-piechart-panel
service grafana-server restart
Pie TOP 5 Ọnọdụ:
SELECT
1, /* fake timestamp value */
status,
sum(status) AS Reqs
FROM $table
WHERE $timeFilter
GROUP BY status
ORDER BY Reqs desc
LIMIT 5
Ọzọkwa m ga-enye arịrịọ na-enweghị nseta ihuenyo:
Gụọ http_user_agent:
$columns(http_user_agent, count(*) c) FROM $table
Ọnụego Dị Mma/Ọdịmma:
$rate(countIf(status = 200) AS good, countIf(status != 200) AS bad) FROM $table
Oge nzaghachi:
$rate(avg(request_time) as request_time) FROM $table
Oge nzaghachi elu (oge nzaghachi elu nke mbụ):
$rate(avg(arrayElement(upstream_response_time,1)) as upstream_response_time) FROM $table
Ọnọdụ agụta tebụl maka vhost niile:
$columns(status, count(*) as c) from $table
Echiche izugbe nke dashboard
Ntụle nke avg() na quantile()
aro()
quantile()
Mmechi:
Enwere m olile anya na obodo ga-etinye aka na mmepe/nnwale na iji nginx-log-collector.
Ma mgbe mmadụ mebere nginx-log-collector, ha ga-agwa gị ego ole ha chekwara na diski, RAM, na CPU.
Ọwa telegram:
Ọtụtụ narị sekọnd:
Onye milliseconds dị mkpa nye, biko dee ma ọ bụ votu na nke a
isi: www.habr.com