Artikel iki bakal ngrembug proyek kasebut
Kanggo ndeleng analytics adhedhasar log, kita bakal nggawe dashboard kanggo Grafana.
Sapa wae sing minat, welcome to cat.
Instal nginx, grafana kanthi cara standar.
Nginstal kluster clickhouse nggunakake ansible-playbook saka
Nggawe database lan tabel ing Clickhouse
Ing iki
Kita nggawe saben panjalukan siji-siji ing saben server ing kluster Clickhouse.
Cathetan penting. Ing baris iki, logs_cluster kudu diganti karo jeneng cluster saka file clickhouse_remote_servers.xml antarane "remote_servers" lan "shard".
ENGINE = Distributed('logs_cluster', 'nginx', 'access_log_shard', rand())
Nginstal lan konfigurasi nginx-log-collector-rpm
Nginx-log-collector ora duwe rpm. kene
Instal paket 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
Owahi konfigurasi /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/
Nyetel nginx
Konfigurasi nginx umum:
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;
}
Siji host 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;
}
}
Tambah host virtual menyang file /etc/hosts:
ip-адрес-сервера-с-nginx vhost1
emulator server HTTP
Minangka emulator server HTTP sing bakal digunakake
Nodejs-stub-server ora duwe rpm. kene
Instal paket nodejs-stub-server ing hulu 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
Stress Testing
Kita nindakake tes nggunakake benchmark Apache.
Instal:
yum install -y httpd-tools
Kita miwiti nguji nggunakake pathokan Apache saka 5 server sing beda:
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
Nyetel Grafana
Sampeyan ora bakal nemokake dashboard ing situs web resmi Grafana.
Mulane, kita bakal nindakake kanthi tangan.
Sampeyan bisa nemokake dashboard sing wis disimpen
Sampeyan uga kudu nggawe variabel tabel kanthi isi nginx.access_log
.
Singlestat Total Panjaluk:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter GROUP BY t
Panjaluk Singlestat Gagal:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter AND status NOT IN (200, 201, 401) GROUP BY t
Persentase Gagal 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
Wektu Tanggapan Rata-rata Singlestat:
SELECT
1, avg(request_time) FROM $table
WHERE $timeFilter GROUP BY 1
Wektu Tanggapan Maks Singlestat:
SELECT
1 as t, max(request_time) as c
FROM $table
WHERE $timeFilter GROUP BY t
Status count:
$columns(status, count(*) as c) from $table
Kanggo ngasilake data kaya kue, sampeyan kudu nginstal plugin lan miwiti maneh grafana.
grafana-cli plugins install grafana-piechart-panel
service grafana-server restart
Status TOP 5 Pie:
SELECT
1, /* fake timestamp value */
status,
sum(status) AS Reqs
FROM $table
WHERE $timeFilter
GROUP BY status
ORDER BY Reqs desc
LIMIT 5
Salajengipun, aku bakal menehi panjalukan tanpa gambar:
Cacah 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
Wektu Respon:
$rate(avg(request_time) as request_time) FROM $table
Wektu respon hulu (waktu respon hulu pertama):
$rate(avg(arrayElement(upstream_response_time,1)) as upstream_response_time) FROM $table
Status Jumlah Tabel kanggo kabeh vhost:
$columns(status, count(*) as c) from $table
Tampilan umum saka dashboard
Perbandingan rata-rata () lan kuantil ()
rata-rata ()
jumlah ()
Kesimpulan:
Muga-muga masyarakat bakal melu ngembangake / nguji lan nggunakake nginx-log-collector.
Lan nalika ana wong sing ngetrapake nginx-log-collector, dheweke bakal menehi pitutur marang kowe pira sing disimpen ing disk, RAM, lan CPU.
Saluran Telegram:
Milidetik:
Sing penting milidetik, tulis utawa pilih iki
Source: www.habr.com