Tuuina atu Nginx json ogalaau e faʻaaoga ai le Vector ile Clickhouse ma Elasticsearch

Tuuina atu Nginx json ogalaau e faʻaaoga ai le Vector ile Clickhouse ma Elasticsearch

Veʻa, fuafuaina e aoina, suia ma auina atu faʻamaumauga faʻamaumauga, metrics ma mea tutupu.

→ Github

O le tusia i le gagana Rust, o loʻo faʻaalia i le maualuga o le faʻatinoga ma le maualalo o le RAM faʻatusatusa i ana analog. E le gata i lea, e tele le gauai e totogi i galuega e fesoʻotaʻi ma le saʻo, aemaise lava, le mafai ona faʻasaoina mea e leʻi tuʻuina atu i se paʻu i luga o le disk ma sui faila.

Faʻataʻitaʻiga, Vector o se mea e fai ai le router e maua mai feʻau mai le tasi pe sili atu punavai, e fa'atatau ile fa'aoga i luga o nei fe'au suiga, ma auina atu i se tasi pe sili atu alavai.

Vector o se sui mo le filebeat ma logstash, e mafai ona galue i vaega uma e lua (maua ma auina atu ogalaau), nisi faʻamatalaga i latou saite.

Afai i Logstash o loʻo fausia le filifili e fai ma faʻaoga → faamama → faʻapipiʻi ona i ai lea i Vector punaoasuigasisi

E mafai ona maua faʻataʻitaʻiga i totonu o faʻamaumauga.

O lenei faatonuga o se faatonuga toe teuteu mai Vyacheslav Rakhinsky. O fa'atonuga muamua o lo'o iai le geoip processing. A'o su'e le geoip mai se feso'ota'iga i totonu, na tu'uina atu e le vector se mea sese.

Aug 05 06:25:31.889 DEBUG transform{name=nginx_parse_rename_fields type=rename_fields}: vector::transforms::rename_fields: Field did not exist field=«geoip.country_name» rate_limit_secs=30

Afai ei ai se tasi e manaʻomia le faʻaogaina o le geoip, ona vaʻai lea i faʻatonuga muamua mai Vyacheslav Rakhinsky.

O le a matou faʻapipiʻiina le tuʻufaʻatasiga o Nginx (Access logs) → Vector (Client | Filebeat) → Vector (Server | Logstash) → vavae ese i Clickhouse ma eseʻese i Elasticsearch. O le a matou faʻapipiʻi 4 servers. E ui lava e mafai ona e pasia i le 3 servers.

Tuuina atu Nginx json ogalaau e faʻaaoga ai le Vector ile Clickhouse ma Elasticsearch

O le polokalame e pei o lenei.

Fa'agata Selinux i au 'au'aunaga uma

sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
reboot

Matou te faʻapipiʻi se HTTP server emulator + utilities i luga o sapalai uma

I le avea ai o se emulator server HTTP o le a matou faʻaaogaina nodejs-stub-server от Maxim Ignatenko

Nodejs-stub-server e leai se rpm. o fai le rpm mo ia. rpm o le a fausia faʻaaoga Fedora Copr

Faʻaopoopo le faleoloa antonpatsev/nodejs-stub-server

yum -y install yum-plugin-copr epel-release
yes | yum copr enable antonpatsev/nodejs-stub-server

Fa'apipi'i le nodejs-stub-server, Apache benchmark ma screen terminal multiplexer i luga o 'au'aunaga uma

yum -y install stub_http_server screen mc httpd-tools screen

Na ou faasa'oina le taimi tali stub_http_server i le /var/lib/stub_http_server/stub_http_server.js faila ina ia tele atu ogalaau.

var max_sleep = 10;

Sei o tatou fa'alauiloa stub_http_server.

systemctl start stub_http_server
systemctl enable stub_http_server

Fa'apipi'i Clickhouse luga ole server 3

ClickHouse faʻaaogaina le SSE 4.2 faʻatonuga seti, o lea seʻi vagana ua faʻamaonia, lagolago mo ia i totonu o le faʻaogaina o loʻo faʻaaogaina e avea ma se manaʻoga faʻaopoopo. O le poloaiga lenei e siaki pe o loʻo lagolagoina e le gaosiga o loʻo iai nei le SSE 4.2:

grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"

Muamua e tatau ona e faʻafesoʻotaʻi le fale teu oloa:

sudo yum install -y yum-utils
sudo rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
sudo yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/stable/x86_64

Ina ia faʻapipiʻi afifi e te manaʻomia le faʻatinoina o tulafono nei:

sudo yum install -y clickhouse-server clickhouse-client

Fa'ataga clickhouse-server e fa'alogo ile kata feso'ota'iga ile faila /etc/clickhouse-server/config.xml

<listen_host>0.0.0.0</listen_host>

Suia le tulaga o le logging mai le fa'asologa i le debug

tosolo

Fa'atonu fa'apipi'i:

min_compress_block_size  65536
max_compress_block_size  1048576

Ina ia faʻagaoioia le Zstd compression, sa fautuaina e aua neʻi paʻi i le config, ae faʻaaoga le DDL.

Tuuina atu Nginx json ogalaau e faʻaaoga ai le Vector ile Clickhouse ma Elasticsearch

Sa le mafai ona ou mauaina pe faʻapefea ona faʻaogaina le zstd compression e ala ile DDL ile Google. O lea na ou tuua ai e pei ona i ai.

Paʻaga o loʻo faʻaogaina le zstd compression i Clickhouse, faʻamolemole faʻasoa faʻatonuga.

Ina ia amata le server o se daemon, tamoʻe:

service clickhouse-server start

Sei o tatou agai i luma i le setiina o le Clickhouse

Alu ile Clickhouse

clickhouse-client -h 172.26.10.109 -m

172.26.10.109 - IP o le server lea e faʻapipiʻi ai Clickhouse.

Se'i tatou faia se fa'amaumauga tu'ufa'atasi

CREATE DATABASE vector;

Sei o tatou siaki pe o iai le database.

show databases;

Fausia se laulau vector.logs.

/* Это таблица где хранятся логи как есть */

CREATE TABLE vector.logs
(
    `node_name` String,
    `timestamp` DateTime,
    `server_name` String,
    `user_id` String,
    `request_full` String,
    `request_user_agent` String,
    `request_http_host` String,
    `request_uri` String,
    `request_scheme` String,
    `request_method` String,
    `request_length` UInt64,
    `request_time` Float32,
    `request_referrer` String,
    `response_status` UInt16,
    `response_body_bytes_sent` UInt64,
    `response_content_type` String,
    `remote_addr` IPv4,
    `remote_port` UInt32,
    `remote_user` String,
    `upstream_addr` IPv4,
    `upstream_port` UInt32,
    `upstream_bytes_received` UInt64,
    `upstream_bytes_sent` UInt64,
    `upstream_cache_status` String,
    `upstream_connect_time` Float32,
    `upstream_header_time` Float32,
    `upstream_response_length` UInt64,
    `upstream_response_time` Float32,
    `upstream_status` UInt16,
    `upstream_content_type` String,
    INDEX idx_http_host request_http_host TYPE set(0) GRANULARITY 1
)
ENGINE = MergeTree()
PARTITION BY toYYYYMMDD(timestamp)
ORDER BY timestamp
TTL timestamp + toIntervalMonth(1)
SETTINGS index_granularity = 8192;

Matou te siaki ua uma ona faia laulau. Tatou amata clickhouse-client ma fai se talosaga.

Sei o tatou o i le vector database.

use vector;

Ok.

0 rows in set. Elapsed: 0.001 sec.

Sei o tatou vaavaai i laulau.

show tables;

┌─name────────────────┐
│ logs                │
└─────────────────────┘

Faʻapipiʻi elasticsearch i luga o le 4th server e tuʻuina atu faʻamatalaga tutusa i Elasticsearch mo le faʻatusatusaina ma le Clickhouse

Fa'aopoopo se ki rpm lautele

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

Sei o tatou fatuina 2 repo:

/etc/yum.repos.d/elasticsearch.repo

[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md

/etc/yum.repos.d/kibana.repo

[kibana-7.x]
name=Kibana repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

Fa'apipi'i elasticsearch ma kibana

yum install -y kibana elasticsearch

Talu ai o le ai ai i le 1 kopi, e tatau ona e faʻaopoopo mea nei i le /etc/elasticsearch/elasticsearch.yml faila:

discovery.type: single-node

Ina ia mafai e le vector ona lafo faʻamatalaga i elasticsearch mai se isi server, seʻi o tatou sui network.host.

network.host: 0.0.0.0

Ina ia faʻafesoʻotaʻi i le kibana, sui le server.host parameter i le faila /etc/kibana/kibana.yml

server.host: "0.0.0.0"

Tuai ma aofia ai elasticsearch i le autostart

systemctl enable elasticsearch
systemctl start elasticsearch

ma kibana

systemctl enable kibana
systemctl start kibana

Fa'atulagaina o le Elasticsearch mo le tasi-node mode 1 shard, 0 kopi. E foliga mai o le ae maua se fuifui o se numera tele o 'auʻaunaga ma e te le manaʻomia le faia o lenei mea.

Mo fa'ailoga i le lumana'i, fa'afou le fa'ata'ita'iga fa'aletonu:

curl -X PUT http://localhost:9200/_template/default -H 'Content-Type: application/json' -d '{"index_patterns": ["*"],"order": -1,"settings": {"number_of_shards": "1","number_of_replicas": "0"}}' 

faatulagaga Veʻa e fai ma sui mo Logstash i luga o le server 2

yum install -y https://packages.timber.io/vector/0.9.X/vector-x86_64.rpm mc httpd-tools screen

Tatou setiina le Vector e suitulaga ia Logstash. Fa'asa'o le faila /etc/vector/vector.toml

# /etc/vector/vector.toml

data_dir = "/var/lib/vector"

[sources.nginx_input_vector]
  # General
  type                          = "vector"
  address                       = "0.0.0.0:9876"
  shutdown_timeout_secs         = 30

[transforms.nginx_parse_json]
  inputs                        = [ "nginx_input_vector" ]
  type                          = "json_parser"

[transforms.nginx_parse_add_defaults]
  inputs                        = [ "nginx_parse_json" ]
  type                          = "lua"
  version                       = "2"

  hooks.process = """
  function (event, emit)

    function split_first(s, delimiter)
      result = {};
      for match in (s..delimiter):gmatch("(.-)"..delimiter) do
          table.insert(result, match);
      end
      return result[1];
    end

    function split_last(s, delimiter)
      result = {};
      for match in (s..delimiter):gmatch("(.-)"..delimiter) do
          table.insert(result, match);
      end
      return result[#result];
    end

    event.log.upstream_addr             = split_first(split_last(event.log.upstream_addr, ', '), ':')
    event.log.upstream_bytes_received   = split_last(event.log.upstream_bytes_received, ', ')
    event.log.upstream_bytes_sent       = split_last(event.log.upstream_bytes_sent, ', ')
    event.log.upstream_connect_time     = split_last(event.log.upstream_connect_time, ', ')
    event.log.upstream_header_time      = split_last(event.log.upstream_header_time, ', ')
    event.log.upstream_response_length  = split_last(event.log.upstream_response_length, ', ')
    event.log.upstream_response_time    = split_last(event.log.upstream_response_time, ', ')
    event.log.upstream_status           = split_last(event.log.upstream_status, ', ')

    if event.log.upstream_addr == "" then
        event.log.upstream_addr = "127.0.0.1"
    end

    if (event.log.upstream_bytes_received == "-" or event.log.upstream_bytes_received == "") then
        event.log.upstream_bytes_received = "0"
    end

    if (event.log.upstream_bytes_sent == "-" or event.log.upstream_bytes_sent == "") then
        event.log.upstream_bytes_sent = "0"
    end

    if event.log.upstream_cache_status == "" then
        event.log.upstream_cache_status = "DISABLED"
    end

    if (event.log.upstream_connect_time == "-" or event.log.upstream_connect_time == "") then
        event.log.upstream_connect_time = "0"
    end

    if (event.log.upstream_header_time == "-" or event.log.upstream_header_time == "") then
        event.log.upstream_header_time = "0"
    end

    if (event.log.upstream_response_length == "-" or event.log.upstream_response_length == "") then
        event.log.upstream_response_length = "0"
    end

    if (event.log.upstream_response_time == "-" or event.log.upstream_response_time == "") then
        event.log.upstream_response_time = "0"
    end

    if (event.log.upstream_status == "-" or event.log.upstream_status == "") then
        event.log.upstream_status = "0"
    end

    emit(event)

  end
  """

[transforms.nginx_parse_remove_fields]
    inputs                              = [ "nginx_parse_add_defaults" ]
    type                                = "remove_fields"
    fields                              = ["data", "file", "host", "source_type"]

[transforms.nginx_parse_coercer]

    type                                = "coercer"
    inputs                              = ["nginx_parse_remove_fields"]

    types.request_length = "int"
    types.request_time = "float"

    types.response_status = "int"
    types.response_body_bytes_sent = "int"

    types.remote_port = "int"

    types.upstream_bytes_received = "int"
    types.upstream_bytes_send = "int"
    types.upstream_connect_time = "float"
    types.upstream_header_time = "float"
    types.upstream_response_length = "int"
    types.upstream_response_time = "float"
    types.upstream_status = "int"

    types.timestamp = "timestamp"

[sinks.nginx_output_clickhouse]
    inputs   = ["nginx_parse_coercer"]
    type     = "clickhouse"

    database = "vector"
    healthcheck = true
    host = "http://172.26.10.109:8123" #  Адрес Clickhouse
    table = "logs"

    encoding.timestamp_format = "unix"

    buffer.type = "disk"
    buffer.max_size = 104900000
    buffer.when_full = "block"

    request.in_flight_limit = 20

[sinks.elasticsearch]
    type = "elasticsearch"
    inputs   = ["nginx_parse_coercer"]
    compression = "none"
    healthcheck = true
    # 172.26.10.116 - сервер где установен elasticsearch
    host = "http://172.26.10.116:9200" 
    index = "vector-%Y-%m-%d"

E mafai ona e fetuunai le vaega transforms.nginx_parse_add_defaults.

talu Vyacheslav Rakhinsky faʻaaoga nei faʻaoga mo se CDN laʻititi ma e mafai ona tele ni tau i luga o le vaitafe_*

Mo se faʻataʻitaʻiga:

"upstream_addr": "128.66.0.10:443, 128.66.0.11:443, 128.66.0.12:443"
"upstream_bytes_received": "-, -, 123"
"upstream_status": "502, 502, 200"

Afai e le o lou tulaga lea, ona mafai lea ona faafaigofieina lenei vaega

Sei o tatou faia ni fa'atulagaga o auaunaga mo systemd /etc/systemd/system/vector.service

# /etc/systemd/system/vector.service

[Unit]
Description=Vector
After=network-online.target
Requires=network-online.target

[Service]
User=vector
Group=vector
ExecStart=/usr/bin/vector
ExecReload=/bin/kill -HUP $MAINPID
Restart=no
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=vector

[Install]
WantedBy=multi-user.target

A maeʻa ona fai laulau, e mafai ona e taʻavale Vector

systemctl enable vector
systemctl start vector

Vector logs e mafai ona vaʻaia e pei o lenei:

journalctl -f -u vector

E tatau ona iai ni fa'amaumauga fa'apenei i totonu o ogalaau

INFO vector::topology::builder: Healthcheck: Passed.
INFO vector::topology::builder: Healthcheck: Passed.

I luga ole kalani (Web server) - 1st server

I luga o le 'auʻaunaga ma nginx, e tatau ona e faʻamalo le ipv6, talu ai o le laulau ogalaau i le clickhouse e faʻaaogaina le fanua. upstream_addr IPv4, talu ai ou te le faʻaogaina ipv6 i totonu o le upega tafailagi. Afai e le tape le ipv6, o le ai ai mea sese:

DB::Exception: Invalid IPv4 value.: (while read the value of key upstream_addr)

Masalo le au faitau, faʻaopoopo ipv6 lagolago.

Fausia le faila /etc/sysctl.d/98-disable-ipv6.conf

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

Fa'aogaina o fa'atulagaga

sysctl --system

Tatou fa'apipi'i le nginx.

Faʻaopoopo le faila faila o le nginx /etc/yum.repos.d/nginx.repo

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

Faʻapipiʻi le pusa nginx

yum install -y nginx

Muamua, matou te manaʻomia le faʻapipiʻiina o le log format i Nginx i le faila /etc/nginx/nginx.conf

user  nginx;
# you must set worker processes based on your CPU cores, nginx does not benefit from setting more than that
worker_processes auto; #some last versions calculate it automatically

# number of file descriptors used for nginx
# the limit for the maximum FDs on the server is usually set by the OS.
# if you don't set FD's then OS settings will be used which is by default 2000
worker_rlimit_nofile 100000;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

# provides the configuration file context in which the directives that affect connection processing are specified.
events {
    # determines how much clients will be served per worker
    # max clients = worker_connections * worker_processes
    # max clients is also limited by the number of socket connections available on the system (~64k)
    worker_connections 4000;

    # optimized to serve many clients with each thread, essential for linux -- for testing environment
    use epoll;

    # accept as many connections as possible, may flood worker connections if set too low -- for testing environment
    multi_accept on;
}

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 vector escape=json
    '{'
        '"node_name":"nginx-vector",'
        '"timestamp":"$time_iso8601",'
        '"server_name":"$server_name",'
        '"request_full": "$request",'
        '"request_user_agent":"$http_user_agent",'
        '"request_http_host":"$http_host",'
        '"request_uri":"$request_uri",'
        '"request_scheme": "$scheme",'
        '"request_method":"$request_method",'
        '"request_length":"$request_length",'
        '"request_time": "$request_time",'
        '"request_referrer":"$http_referer",'
        '"response_status": "$status",'
        '"response_body_bytes_sent":"$body_bytes_sent",'
        '"response_content_type":"$sent_http_content_type",'
        '"remote_addr": "$remote_addr",'
        '"remote_port": "$remote_port",'
        '"remote_user": "$remote_user",'
        '"upstream_addr": "$upstream_addr",'
        '"upstream_bytes_received": "$upstream_bytes_received",'
        '"upstream_bytes_sent": "$upstream_bytes_sent",'
        '"upstream_cache_status":"$upstream_cache_status",'
        '"upstream_connect_time":"$upstream_connect_time",'
        '"upstream_header_time":"$upstream_header_time",'
        '"upstream_response_length":"$upstream_response_length",'
        '"upstream_response_time":"$upstream_response_time",'
        '"upstream_status": "$upstream_status",'
        '"upstream_content_type":"$upstream_http_content_type"'
    '}';

    access_log  /var/log/nginx/access.log  main;
    access_log  /var/log/nginx/access.json.log vector;      # Новый лог в формате json

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

Ina ia aua nei motusia lau faʻatulagaga o loʻo iai nei, Nginx faʻatagaina oe e maua ni faʻatonuga access_log

access_log  /var/log/nginx/access.log  main;            # Стандартный лог
access_log  /var/log/nginx/access.json.log vector;      # Новый лог в формате json

Aua nei galo e faaopoopo se tulafono e logrotate mo ogalaau fou (pe afai e le muta le faila faila i le .log)

Aveese default.conf mai /etc/nginx/conf.d/

rm -f /etc/nginx/conf.d/default.conf

Fa'aopoopo le host virtual /etc/nginx/conf.d/vhost1.conf

server {
    listen 80;
    server_name vhost1;
    location / {
        proxy_pass http://172.26.10.106:8080;
    }
}

Fa'aopoopo le host virtual /etc/nginx/conf.d/vhost2.conf

server {
    listen 80;
    server_name vhost2;
    location / {
        proxy_pass http://172.26.10.108:8080;
    }
}

Fa'aopoopo le host virtual /etc/nginx/conf.d/vhost3.conf

server {
    listen 80;
    server_name vhost3;
    location / {
        proxy_pass http://172.26.10.109:8080;
    }
}

Fa'aopoopo le host virtual /etc/nginx/conf.d/vhost4.conf

server {
    listen 80;
    server_name vhost4;
    location / {
        proxy_pass http://172.26.10.116:8080;
    }
}

Faʻaopoopo 'au faʻapitoa (172.26.10.106 ip o le 'auʻaunaga o loʻo faʻapipiʻi ai le nginx) i 'auʻaunaga uma i le /etc/hosts file:

172.26.10.106 vhost1
172.26.10.106 vhost2
172.26.10.106 vhost3
172.26.10.106 vhost4

Ma afai ua uma ona saunia mea uma

nginx -t 
systemctl restart nginx

Se'i o tatou fa'apipi'iina i tatou lava Veʻa

yum install -y https://packages.timber.io/vector/0.9.X/vector-x86_64.rpm

Sei o tatou faia se faila faila mo systemd /etc/systemd/system/vector.service

[Unit]
Description=Vector
After=network-online.target
Requires=network-online.target

[Service]
User=vector
Group=vector
ExecStart=/usr/bin/vector
ExecReload=/bin/kill -HUP $MAINPID
Restart=no
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=vector

[Install]
WantedBy=multi-user.target

Ma fetuutuunai le sui Filebeat i le /etc/vector/vector.toml config. O le tuatusi IP 172.26.10.108 o le tuatusi IP o le log server (Vector-Server)

data_dir = "/var/lib/vector"

[sources.nginx_file]
  type                          = "file"
  include                       = [ "/var/log/nginx/access.json.log" ]
  start_at_beginning            = false
  fingerprinting.strategy       = "device_and_inode"

[sinks.nginx_output_vector]
  type                          = "vector"
  inputs                        = [ "nginx_file" ]

  address                       = "172.26.10.108:9876"

Aua ne'i galo e fa'aopoopo le tagata fa'aoga vector i le vaega mana'omia ina ia mafai ona ia faitau faila ogalaau. Mo se faʻataʻitaʻiga, o le nginx i centos e fatuina ogalaau ma aia tatau a vaega.

usermod -a -G adm vector

Sei o tatou amata le tautua vector

systemctl enable vector
systemctl start vector

Vector logs e mafai ona vaʻaia e pei o lenei:

journalctl -f -u vector

E tatau ona i ai se faʻamatalaga faʻapea i totonu o ogalaau

INFO vector::topology::builder: Healthcheck: Passed.

Su'ega Fa'atiga

O suʻega e faia e faʻaaoga ai le faʻailoga a Apache.

O le httpd-tools package na faʻapipiʻiina i luga o sapalai uma

Matou te amata faʻataʻitaʻiga e faʻaaoga ai le Apache benchmark mai 4 'auʻaunaga eseese i le mata. Muamua, matou te faʻalauiloaina le telexer mata, ona matou amata suʻe lea e faʻaaoga ai le Apache benchmark. E fa'afefea ona galue ma lau mata e mafai ona e mauaina i totonu tusiga.

Mai le 1st server

while true; do ab -H "User-Agent: 1server" -c 100 -n 10 -t 10 http://vhost1/; sleep 1; done

Mai le 2st server

while true; do ab -H "User-Agent: 2server" -c 100 -n 10 -t 10 http://vhost2/; sleep 1; done

Mai le 3st server

while true; do ab -H "User-Agent: 3server" -c 100 -n 10 -t 10 http://vhost3/; sleep 1; done

Mai le 4st server

while true; do ab -H "User-Agent: 4server" -c 100 -n 10 -t 10 http://vhost4/; sleep 1; done

Sei o tatou siaki faʻamatalaga ile Clickhouse

Alu ile Clickhouse

clickhouse-client -h 172.26.10.109 -m

Faia se fesili SQL

SELECT * FROM vector.logs;

┌─node_name────┬───────────timestamp─┬─server_name─┬─user_id─┬─request_full───┬─request_user_agent─┬─request_http_host─┬─request_uri─┬─request_scheme─┬─request_method─┬─request_length─┬─request_time─┬─request_referrer─┬─response_status─┬─response_body_bytes_sent─┬─response_content_type─┬───remote_addr─┬─remote_port─┬─remote_user─┬─upstream_addr─┬─upstream_port─┬─upstream_bytes_received─┬─upstream_bytes_sent─┬─upstream_cache_status─┬─upstream_connect_time─┬─upstream_header_time─┬─upstream_response_length─┬─upstream_response_time─┬─upstream_status─┬─upstream_content_type─┐
│ nginx-vector │ 2020-08-07 04:32:42 │ vhost1      │         │ GET / HTTP/1.0 │ 1server            │ vhost1            │ /           │ http           │ GET            │             66 │        0.028 │                  │             404 │                       27 │                       │ 172.26.10.106 │       45886 │             │ 172.26.10.106 │             0 │                     109 │                  97 │ DISABLED              │                     0 │                0.025 │                       27 │                  0.029 │             404 │                       │
└──────────────┴─────────────────────┴─────────────┴─────────┴────────────────┴────────────────────┴───────────────────┴─────────────┴────────────────┴────────────────┴────────────────┴──────────────┴──────────────────┴─────────────────┴──────────────────────────┴───────────────────────┴───────────────┴─────────────┴─────────────┴───────────────┴───────────────┴─────────────────────────┴─────────────────────┴───────────────────────┴───────────────────────┴──────────────────────┴──────────────────────────┴────────────────────────┴─────────────────┴───────────────────────

Su'e le tele o laulau ile Clickhouse

select concat(database, '.', table)                         as table,
       formatReadableSize(sum(bytes))                       as size,
       sum(rows)                                            as rows,
       max(modification_time)                               as latest_modification,
       sum(bytes)                                           as bytes_size,
       any(engine)                                          as engine,
       formatReadableSize(sum(primary_key_bytes_in_memory)) as primary_keys_size
from system.parts
where active
group by database, table
order by bytes_size desc;

Se'i o tatou su'esu'e pe fia le tele o ogalaau na maua ile Clickhouse.

Tuuina atu Nginx json ogalaau e faʻaaoga ai le Vector ile Clickhouse ma Elasticsearch

Ole lapopoa ole laulau ole 857.19 MB.

Tuuina atu Nginx json ogalaau e faʻaaoga ai le Vector ile Clickhouse ma Elasticsearch

Ole tele ole fa'amatalaga tutusa ile faasinoupu ile Elasticsearch ole 4,5GB.

Afai e te le faʻamaonia faʻamatalaga i le vector i totonu o faʻamaufaʻailoga, Clickhouse e 4500/857.19 = 5.24 taimi itiiti ifo nai lo le Elasticsearch.

I le vector, e fa'aaogaina le fanua fa'amalosi.

Telegram talatalanoaga e fale kiliki
Telegram talatalanoaga e Elasticsearch
Telegram talatalanoaga e "Aoina ma auiliiliga o faiga feau"

puna: www.habr.com

Faaopoopo i ai se faamatalaga