ਇਹ ਲੇਖ ਪ੍ਰੋਜੈਕਟ ਬਾਰੇ ਚਰਚਾ ਕਰੇਗਾ
ਲੌਗਸ ਦੇ ਆਧਾਰ 'ਤੇ ਵਿਸ਼ਲੇਸ਼ਣ ਦੇਖਣ ਲਈ, ਅਸੀਂ Grafana ਲਈ ਇੱਕ ਡੈਸ਼ਬੋਰਡ ਬਣਾਵਾਂਗੇ।
ਕੋਈ ਵੀ ਦਿਲਚਸਪੀ ਰੱਖਦਾ ਹੈ, ਬਿੱਲੀ ਵਿੱਚ ਤੁਹਾਡਾ ਸੁਆਗਤ ਹੈ।
nginx, ਗ੍ਰਾਫਾਨਾ ਨੂੰ ਮਿਆਰੀ ਤਰੀਕੇ ਨਾਲ ਸਥਾਪਿਤ ਕਰੋ।
ਤੋਂ ਜਵਾਬਦੇਹ-ਪਲੇਬੁੱਕ ਦੀ ਵਰਤੋਂ ਕਰਦੇ ਹੋਏ ਇੱਕ ਕਲਿੱਕਹਾਊਸ ਕਲੱਸਟਰ ਨੂੰ ਸਥਾਪਿਤ ਕਰਨਾ
ਕਲਿਕਹਾਊਸ ਵਿੱਚ ਡੇਟਾਬੇਸ ਅਤੇ ਟੇਬਲ ਬਣਾਉਣਾ
ਇਸ ਵਿੱਚ
ਅਸੀਂ ਕਲਿਕਹਾਊਸ ਕਲੱਸਟਰ ਵਿੱਚ ਹਰੇਕ ਸਰਵਰ 'ਤੇ ਇੱਕ-ਇੱਕ ਕਰਕੇ ਹਰੇਕ ਬੇਨਤੀ ਕਰਦੇ ਹਾਂ।
ਮਹੱਤਵਪੂਰਨ ਨੋਟ. ਇਸ ਲਾਈਨ ਵਿੱਚ, "remote_servers" ਅਤੇ "shard" ਵਿਚਕਾਰ clickhouse_remote_servers.xml ਫ਼ਾਈਲ ਤੋਂ logs_cluster ਨੂੰ ਤੁਹਾਡੇ ਕਲੱਸਟਰ ਨਾਮ ਨਾਲ ਬਦਲਣ ਦੀ ਲੋੜ ਹੈ।
ENGINE = Distributed('logs_cluster', 'nginx', 'access_log_shard', rand())
nginx-log-collector-rpm ਨੂੰ ਸਥਾਪਿਤ ਅਤੇ ਸੰਰਚਿਤ ਕਰਨਾ
Nginx-log-colector ਕੋਲ 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 ਨਹੀਂ ਹੈ। ਇਥੇ
ਅੱਪਸਟਰੀਮ nginx rpm 'ਤੇ nodejs-stub-server ਪੈਕੇਜ ਇੰਸਟਾਲ ਕਰੋ
yum -y install yum-plugin-copr
yum copr enable antonpatsev/nodejs-stub-server
yum -y install stub_http_server
systemctl start stub_http_server
ਤਣਾਅ ਟੈਸਟਿੰਗ
ਅਸੀਂ ਅਪਾਚੇ ਬੈਂਚਮਾਰਕ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਟੈਸਟਿੰਗ ਕਰਦੇ ਹਾਂ।
ਇਸਨੂੰ ਸਥਾਪਿਤ ਕਰੋ:
yum install -y httpd-tools
ਅਸੀਂ 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 ਵੈੱਬਸਾਈਟ 'ਤੇ ਡੈਸ਼ਬੋਰਡ ਨਹੀਂ ਮਿਲੇਗਾ।
ਇਸ ਲਈ, ਅਸੀਂ ਇਸਨੂੰ ਹੱਥ ਨਾਲ ਕਰਾਂਗੇ.
ਤੁਸੀਂ ਮੇਰਾ ਸੁਰੱਖਿਅਤ ਕੀਤਾ ਡੈਸ਼ਬੋਰਡ ਲੱਭ ਸਕਦੇ ਹੋ
ਤੁਹਾਨੂੰ ਸਮੱਗਰੀ ਦੇ ਨਾਲ ਇੱਕ ਸਾਰਣੀ ਵੇਰੀਏਬਲ ਬਣਾਉਣ ਦੀ ਵੀ ਲੋੜ ਹੈ nginx.access_log
.
ਸਿੰਗਲਸਟੈਟ ਕੁੱਲ ਬੇਨਤੀਆਂ:
SELECT
1 as t,
count(*) as c
FROM $table
WHERE $timeFilter GROUP BY t
ਸਿੰਗਲਸਟੈਟ ਅਸਫਲ ਬੇਨਤੀਆਂ:
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
ਪਾਈ ਟਾਪ 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
ਚੰਗਾ ਦਰ/ਬੁਰਾ ਦਰ:
$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
ਡੈਸ਼ਬੋਰਡ ਦਾ ਆਮ ਦ੍ਰਿਸ਼
ਔਸਤ() ਅਤੇ ਕੁਆਂਟਾਇਲ() ਦੀ ਤੁਲਨਾ
ਔਸਤ()
ਮਾਤਰਾ()
ਸਿੱਟਾ:
ਮੈਂ ਉਮੀਦ ਕਰਦਾ ਹਾਂ ਕਿ ਕਮਿਊਨਿਟੀ nginx-log-colector ਦੇ ਵਿਕਾਸ/ਟੈਸਟਿੰਗ ਅਤੇ ਵਰਤੋਂ ਵਿੱਚ ਸ਼ਾਮਲ ਹੋ ਜਾਂਦੀ ਹੈ।
ਅਤੇ ਜਦੋਂ ਕੋਈ nginx-log-colector ਨੂੰ ਲਾਗੂ ਕਰਦਾ ਹੈ, ਤਾਂ ਉਹ ਤੁਹਾਨੂੰ ਦੱਸੇਗਾ ਕਿ ਉਹਨਾਂ ਨੇ ਕਿੰਨੀ ਡਿਸਕ, RAM ਅਤੇ CPU ਨੂੰ ਸੁਰੱਖਿਅਤ ਕੀਤਾ ਹੈ।
ਟੈਲੀਗ੍ਰਾਮ ਚੈਨਲ:
ਮਿਲੀਸਕਿੰਟ:
ਜਿਸ ਲਈ ਮਿਲੀਸਕਿੰਟ ਮਹੱਤਵਪੂਰਨ ਹਨ, ਕਿਰਪਾ ਕਰਕੇ ਇਸ ਵਿੱਚ ਲਿਖੋ ਜਾਂ ਵੋਟ ਕਰੋ
ਸਰੋਤ: www.habr.com