Logstash cheat sheet: Difference between revisions

 
(219 intermediate revisions by the same user not shown)
= Elastic stack / ELK (Elasticsearch + Logstash + Kibana) =
 
'''諸般の事情により更新休止します'''
 
== 久しぶりの追記 ==
久しぶりに logstash.conf を修正したら、割と重要な仕様変更がたくさんあり、過去の記述は現在の仕様に合ってないです。ちなみに ruby code を追記したのですが、event.get event.set とかになっている。
<syntaxhighlight lang="javascript" enclose="div">
ruby {
code => "event.set('foo',event.get('foo')+ 5.1)"
}
</syntaxhighlight>
こんな感じ。
 
その他、認証系強化による仕様の混乱はとりあえずなんとかするしかないw
 
== splunk のデモをみて、自分の環境に logstash を入れてみた。 :) ==
:(ELKBの更新が速いので、随時記事をアップデートします。[https://www.elastic.co/downloads/elasticsearch Elasticsearch 57.06.2], [https://www.elastic.co/downloads/logstash Logstash 57.06.12], [https://www.elastic.co/downloads/beats/filebeat Filebeat 57.06.12], [https://www.elastic.co/downloads/kibana Kibana 57.06.2])
 
:[http://ja.splunk.com/ splunk] のデモを見て、構造化ロギング・高速検索・可視化の素晴らしさが解ったので、それをオープンソースの Elastic stack (ELK stack) で実現する。
:ELK でログ管理をしはじめて、いままで気付かなかった事がいろいろ見えて、かなり改善しました(実感!)
 
最近の Elastic Stack は logstash いらずで簡易にという方向を狙ってきている。それはそれで嬉しいが、いろいろ細かく触りたい場合には、まだまだ logstash をホゲらないと逝けない。
 
::完全に通常の運用につかっているので、アグレッシブな変更はできなくなってるので突っ込んだ記事がかけない^^;;;
 
 
7.6.0 は kibana の index の変換するのだが、elasticseach のサーキットブレーカーが作動して完了しない。
:一時的に elasticsearch の heap 増やした。(最終的には、今回の件がギリギリ回避できるメモリー量に増やした)
 
7.6.0 から X-Pack の概念が変わった(なくなった?)
:logstash.yml から xpack の設定をコメントアウト
 
timelion の位置付けが変わった。
 
kibana.ymlに
<syntaxhighlight lang="yaml" enclose="div">
timelion.ui.enabled: true
</syntaxhighlight>
で元に戻る。設定を確認して、新しいビジュアライズに移行する。
 
 
7.4.1 の logstash がダメっぽい。ヘビー io-wait
:以前よりメモリー食いになってるようで、ES も含めて頑張って使用メモリー削減してかろうじて稼働中
:: dns filter がぁ failed_cache_size ちゃんと設定しないとまずい。
 
'''ようやく 7.x にあげた'''
 
あら...意外と簡単に入った 7.4.0...でもないぞ。
 
よく見たら index 名が変わって Index Lifecycle Management がよしなにしてしまうようで、昔に戻すには elasticsearch output pulgin で
<syntaxhighlight lang="javascript" enclose="div">
ilm_enabled => false
</syntaxhighlight>
 
kibana の index pattern を削除したあとトラブル。新しい index pattern 作っているのに index pattern が無いので作れといわれる
 
解決策は、新しい index pattern を作るときに、advanced options を表示して、Custom index pattern ID に index pattern と同じ文字をいれる。たとえば index pattern が "logstash-*" なら Custom index pattern ID も "logstash-*" とする。
 
私は '*' という文字が嫌なので(あとで問題起きそう)、全部 id を書き換えた。
 
filebeat.yml で filebeat.registry_file 行削除すること
 
logstash の elasticsearch-template を変更
<syntaxhighlight lang="javascript" enclose="div">
"_default_" : {
****
}
</syntaxhighlight>
を削除
 
python beaver から送られる 'host' を remove
<syntaxhighlight lang="javascript" enclose="div">
mutate {
rename => { "host" => "my_host" }
}
mutate {
add_field => { "[host][name]" => "%{my_host}" }
}
</syntaxhighlight>
 
beats が送っていた "host" は host.name に
[host][name]
 
agent.* が増えた
 
7.0.0 出た! テストは気力があるときwにします。。。
 
6.6.1 で geoip.postal_code の型がコンフリクト
 
[https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/788/files#diff-c1b7e63b1e6f2c2cfe8656fa847ecba5 "postal_code" : { "type" : "keyword" }]
 
6.5.0 で kibana の index が変更されて .kibana_1 .kibana_2 というのができた。これですこしハマった。
 
6.2.0 で /etc/elasticsearch/jvm.options
-Djava.io.tmpdir=${ES_TMPDIR}
:: ES_TMPDIR の定義がないのでエラーになる。
 
'''filebeat 6.3.0 は問題ありそう。6.2.4 のままで様子を見る。'''
"error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse [host]"
:::[https://github.com/elastic/beats/issues/7050 Metricbeat `host` namespace causes mapping conflict when used with Logstash]
:::[https://discuss.elastic.co/t/logstash-errors-after-upgrading-to-filebeat-6-3-0/135984/5 Logstash errors after upgrading to filebeat-6.3.0]
 
 
[https://github.com/elastic/beats/blob/master/libbeat/docs/breaking.asciidoc#breaking-changes-in-63 Breaking changes in 6.3]
:ここに着地
 
<syntaxhighlight lang="javascript" enclose="div">
"mappings" : {
"properties" : {
"host" : {
"dynamic": true,
"properties" : {
"name": { "type": "keyword" },
"id" : { "type" : "keyword" },
"architecture" : { "type" : "keyword" },
"os" : {
"dynamic" : true,
"properties" : {
"platform": { "type": "keyword" },
"version": { "type": "keyword" },
"family": { "type": "keyword" }
}
"ip" : { "type" : "ip" },
"mac" : { "type" : "keyword" }
}
}
}
}
}
</syntaxhighlight>
:こんな感じの template でいいのかねぇ
::[https://github.com/elastic/ecs Elastic Common Schema] こんなこと計画してるらしい
 
それか無視するか
<syntaxhighlight lang="javascript" enclose="div">
# For Beat and LSF compatibility
if [beat][name] {
# Remove host metadata
mutate {
remove_field => [ "[host]" ]
}
mutate {
add_field => {
"host" => "%{[beat][name]}"
}
}
</syntaxhighlight>
:beat.hostname ではなく beat.name つかえと...
 
===logstash の書籍===
logstash-shipper(redisに送る)--------------↗︎
beaver(redisに送る)-------------------↗︎
Filebeat(redisに送る)-----------------↗︎
</pre>
:最近は Kafka を broker にするのが良さげか?
Filebeat:
端末(filebeat) ----> 解析サーバ(logstash-shipper)
[端末(filebeat) ----> 解析・蓄積(Elasticsearch Ingest Node)]
 
logstash-shipper:
Filebeat の待ち受け(input beats)、ブローカーへそのまま吐き出す(output redis)
 
==== Filebeat 設定 ====
'''filebeat.yml 例 (1.x -> 56.0 仮)'''
: 6.0 は type が使えないので log_type という名前のカスタムフィールドに変更する。
::logstash 使うので filebeat modules は使わない。
:::modules 勉強しないといけない。
::::もともと logstash から入ったので modules は私には不要かも...
<syntaxhighlight lang="yaml" enclose="div">
############################# Filebeat ##########Configuration ############################
filebeat:
# List of prospectors to fetch data.
prospectors:
# Each - is a prospector. Below are the prospector specific configurations
-
paths:
- /var/log/syslog
- /var/log/mail.log
- /var/log/auth.log
input_type: log
document_type: syslog
fields_under_root: true
 
#=========================== Filebeat prospectors =============================
-
paths:
- /var/log/apache2/access.log
input_type: log
document_type: apache
fields_under_root: true
 
filebeat.inputs:
-
#filebeat.prospectors:
paths:
- /var/log/apache2/other_vhosts_access.log
input_type: log
document_type: apache-other-vhost
fields_under_root: true
 
- type: log
-
paths:
- /var/log/apache2/error.logsyslog
- input_type: /var/log/mail.log
- /var/log/auth.log
document_type: apache-error
fields:
fields_under_root: true
log_type: syslog
fields_under_root: true
 
- type: log
-
paths:
- /var/log/dpkgapache2/access.log
fields:
input_type: log
document_typelog_type: dpkgapache
fields_under_root: true
 
- type: log
# General filebeat configuration options
#paths:
/var/log/apache2/other_vhosts_access.log
# Event count spool threshold - forces network flush if exceeded
fields:
#spool_size: 2048
log_type: apache-other-vhost
fields_under_root: true
 
- type: log
# Defines how often the spooler is flushed. After idle_timeout the spooler is
paths:
# Flush even though spool_size is not reached.
/var/log/apache2/error.log
#idle_timeout: 5s
fields:
log_type: apache-error
fields_under_root: true
 
- type: log
# Name of the registry file. Per default it is put in the current working
paths:
# directory. In case the working directory is changed after when running
/var/log/varnish/varnishncsa.log
# filebeat again, indexing starts from the beginning again.
fields:
registry_file: /var/lib/filebeat/registry
log_type: varnish
fields_under_root: true
 
- type: log
# Full Path to directory with additional prospector configuration files. Each file must end with .yml
paths:
# These config files must have the full filebeat config part inside, but only
/var/log/dpkg.log
# the prospector part is processed. All global options like spool_size are ignored.
fields:
# The config_dir MUST point to a different directory then where the main filebeat config file is in.
log_type: dpkg
#config_dir:
fields_under_root: true
 
- type: log
paths:
/var/log/fail2ban.log
fields:
log_type: fail2ban
fields_under_root: true
 
#========================= Filebeat global options ============================
###############################################################################
############################# Libbeat Config ##################################
# Base config file used by all other beats for using libbeat features
 
filebeat.registry_file: /var/lib/filebeat/registry
############################# Output ##########################################
 
#================================ Outputs ======================================
# Configure what outputs to use when sending the data collected by the beat.
# Multiple outputs may be used.
output:
### Logstash as output
logstash:
# The Logstash hosts
hosts: ["localhost:5044"]
 
#----------------------------- Logstash output ---------------------------------
# Number of workers per Logstash host.
output.logstash:
#worker: 1
# The Logstash hosts
hosts: ["localhost:5044"]
 
# Optional SSL. By default is off.
# Set gzip compression level.
# List of root certificates for HTTPS server verifications
#compression_level: 3
ssl.certificate_authorities: ["/etc/logstash/logstash-forwarder.crt"]
 
# Certificate for TLS client authentication
# Optional load balance the events between the Logstash hosts
#ssl.certificate: "/etc/logstash/logstash-forwarder.crt"
#loadbalance: true
 
# Client Certificate Key
# Optional index name. The default index name depends on the each beat.
#ssl.key: "/etc/logstash/logstash-forwarder.key"
# For Packetbeat, the default is set to packetbeat, for Topbeat
# top topbeat and for Filebeat to filebeat.
#index: filebeat
 
# Configure SSL verification mode. If `none` is configured, all server hosts
# Optional TLS. By default is off.
# and certificates will be accepted. In this mode, SSL based connections are
ssl:
# susceptible to man-in-the-middle attacks. Use only for testing. Default is
# List of root certificates for HTTPS server verifications
# `full`.
certificate_authorities: ["/etc/logstash/logstash-forwarder.crt"]
#ssl.verification_mode: full
ssl.verification_mode: none
 
#================================ Logging ======================================
# Certificate for TLS client authentication
# There are three options for the log output: syslog, file, stderr.
#certificate: "/etc/logstash/logstash-forwarder.crt"
# Under Windows systems, the log files are per default sent to the file output,
# under all other system per default to syslog.
 
# Sets log level. The default log level is info.
# Client Certificate Key
# Available log levels are: critical, error, warning, info, debug
#key: "/etc/logstash/logstash-forwarder.key"
#logging.level: info
logging.level: info
 
# Enable debug output for selected components. To enable all selectors use ["*"]
#verification_mode: none
# Other available selectors are "beat", "publish", "service"
verification_mode: none
# Multiple selectors can be chained.
#logging.selectors: [ ]
 
# Send all logging output to syslog. The default is false.
# Configure cipher suites to be used for TLS connections
#logging.to_syslog: true
#cipher_suites: []
logging.to_syslog: false
 
# Configure curve types for ECDHE based cipher suites
#curve_types: []
 
############################# Logging #########################################
 
# There are three options for the log ouput: syslog, file, stderr.
# Under Windos systems, the log files are per default sent to the file output,
# under all other system per default to syslog.
logging:
 
# If enabled, filebeat periodically logs its internal metrics that have changed
# Send all logging output to syslog. On Windows default is false, otherwise
# in the last period. For each metric that changed, the delta from the value at
# default is true.
# the beginning of the period is logged. Also, the total values for
#to_syslog: true
# all non-zero internal metrics are logged on shutdown. The default is true.
to_syslog: false
#logging.metrics.enabled: true
 
# The period after which to log the internal metrics. The default is 30s.
# Write all logging output to files. Beats automatically rotate files if rotateeverybytes
#logging.metrics.period: 30s
# limit is reached.
#to_files: false
to_files: true
 
# ToLogging enableto loggingrotating tofiles files,. Set logging.to_files optionto hasfalse to bedisable setlogging to true
# files:.
logging.to_files: true
# The directory where the log files will written to.
logging.files:
#path: /var/log/mybeat
# Configure the path where the logs are written. The default is the logs directory
path: /var/log/filebeat
# under the home path (the binary location).
#path: /var/log/filebeat
path: /var/log/filebeat
 
# The name of the files where the logs are written to.
#name: mybeatfilebeat
name: filebeat.log
 
# Configure log file size limit. If limit is reached, log file will be
# automatically rotated
#rotateeverybytes: 10485760 # = 10MB
rotateeverybytes: 10485760 # = 10MB
 
# Number of rotated log files to keep. Oldest files will be deleted first.
#keepfiles: 7
keepfiles: 7
 
# The permissions mask to apply when rotating log files. The default value is 0600.
# Enable debug output for selected components. To enable all selectors use ["*"]
# Must be a valid Unix-style file permissions mask expressed in octal notation.
# Other available selectors are beat, publish, service
#permissions: 0600
# Multiple selectors can be chained.
#selectors: [ ]
 
# Set to true to log messages in json format.
# Sets log level. The default log level is error.
#logging.json: false
# Available log levels are: critical, error, warning, info, debug
#level: error
level: info
</syntaxhighlight>
 
 
*apache
[https://github.com/logstash-plugins/logstash-patterns-core/blob/master/patterns/httpd 公式 pattern の COMBINEDAPACHELOG]
[https://github.com/nxhack/logstash/blob/master/patterns/apache apache grok pattern]
 
 
== geoip, user-agent ==
http://dev.maxmind.com/geoip/geoip2/geolite2/
http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz
http://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz
 
http://dev.maxmind.com/geoip/legacy/geolite/
https://github.com/ua-parser/uap-core/blob/master/regexes.yaml
https://raw.githubusercontent.com/ua-parser/uap-core/master/regexes.yaml
 
geoip 更新処理
<syntaxhighlight lang="bash" enclose="div">
wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz
rm *.old
mv GeoLite2-City.mmdb GeoLite2-City.mmdb.old
mv GeoLite2-Country.mmdb GeoLite2-Country.mmdb.old
mv GeoLite2-ASN.mmdb GeoLite2-ASN.mmdb.old
gunzip GeoLite2-City.mmdb.gz
gunzip GeoLite2-Country.mmdb.gz
tar xfz GeoLite2-ASN.tar.gz --strip=1 --wildcards */GeoLite2-ASN.mmdb
rm GeoLite2-ASN.tar.gz
</syntaxhighlight>
 
== enable high precision timestamps ==
===rsyslog の timestamp を milliseconds まで取る===
:/etc/rsyslog.conf の
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
:の指示通り、"ActionFileDefaultTemplate" 行をコメントアウトする。
 
== X-Pack ==
Basic ライセンスというのが Free で、ライセンスを1年ごとに更新していけば、ずっと無料でつかえそうだ。
無償の範囲で使うには、ユーザ権限機能(旧 Shield)を無効にする。
:6.3.0 から Basic ライセンスは有効期限が無制限になった。また面倒だったアップテート時の x-pack のインストース作業も不要になった。
/etc/elasticsearch/elasticsearch.yml と /etc/kibana/kibana.yml に、
 
<syntaxhighlight lang="text" enclose="div">
自分のテスト環境はシングルノードなので status が YELLOW にならないように、
xpack.security.enabled: false
/usr/share/elasticsearch/plugins/x-pack/x-pack-core/x-pack-core-6.2.4.jar
:テンプレート json の index.number_of_replicas を変更する。
 
curl -XDELETE 'http://127.0.0.1:9200/_template/.monitoring-logstash'
curl -XDELETE 'http://127.0.0.1:9200/_template/.monitoring-alerts'
curl -XDELETE 'http://127.0.0.1:9200/_template/.monitoring-es-2'
curl -XDELETE 'http://127.0.0.1:9200/_template/.monitoring-es'
curl -XDELETE 'http://127.0.0.1:9200/_template/.monitoring-data-2'
curl -XDELETE 'http://127.0.0.1:9200/_template/.monitoring-kibana-2'
curl -XDELETE 'http://127.0.0.1:9200/_template/.monitoring-kibana'
 
作ってしまった index の index.number_of_replicas を変更する。
<syntaxhighlight lang="bash" enclose="div">
curl -XPUT 'http://localhost:9200/.monitoring-es-6-2017.12.05/_settings' -H 'Content-Type: application/json' -d'
{
"index" : {
"number_of_replicas" : "0"
}
}
'
 
curl -XPUT 'http://localhost:9200/.monitoring-logstash-6-2017.12.05/_settings' -H 'Content-Type: application/json' -d'
{
"index" : {
"number_of_replicas" : "0"
}
}
'
 
curl -XPUT 'http://localhost:9200/.monitoring-kibana-6-2017.12.05/_settings' -H 'Content-Type: application/json' -d'
{
"index" : {
"number_of_replicas" : "0"
}
}
'
</syntaxhighlight>
を追加する。
 
Elastic Stack がアップデートされたら、いちいち明示的に X-Pack をアップデートしなければいけないのは萎える。
Logstash の Monitoring はまだかな?
:6.3.0 から標準パッケージにはいったっぽい。
<syntaxhighlight lang="bash" enclose="div">
systemctl stop logstash
systemctl stop kibana
systemctl stop elasticsearch
cd /usr/share/logstash
./bin/logstash-plugin install logstash-output-statsd
./bin/logstash-plugin install logstash-filter-throttle
./bin/logstash-plugin install logstash-filter-sleep
systemctl start elasticsearch
systemctl start kibana
systemctl start logstash
</syntaxhighlight>
 
 
いろいろ触りどころがありそうなので一旦凍結する。
また、elasticsearch を(再)起動する時点で、kibana や logstash が稼働している場合に、monitor を突きにくるので、認証エラーが多発する。
これは無視してよいが気持ち悪い。
 
Authentication of [kibana] was terminated by realm [reserved] - failed to authenticate user [kibana]
Authentication of [logstash_system] was terminated by realm [reserved] - failed to authenticate user [logstash_system]
 
== LS 2.3.1 geoip issue ==
これは Lua EVAL 機能を使い始めたかららしい(ストアドプロシージャみないなものかな)。ppa の redis 3.0 に上げた。
-->
 
== geoip support for GeoIPLite2-ASN database ==
4.2.1 でうごくか...
 
<syntaxhighlight lang="bash" enclose="div">
/usr/share/logstash/bin/logstash-plugin update logstash-filter-geoip
Updating logstash-filter-geoip
Updated logstash-filter-geoip 4.1.1 to 4.2.1
</syntaxhighlight>
 
<syntaxhighlight lang="json" enclose="div">
geoip {
database => "/etc/logstash/geoip/GeoLite2-ASN.mmdb"
source => "postfix_client_ip"
target => "postfix_bgp"
}
</syntaxhighlight>
 
いけた!
<syntaxhighlight lang="json" enclose="div">
"postfix_bgp": {
"as_org": "Towerstream I, Inc.",
"ip": "64.17.249.242",
"asn": 33224
},
</syntaxhighlight>
 
== Raspberry Pi ==
[https://beats-nightlies.s3.amazonaws.com/index.html?prefix=jenkins/filebeat/ https://beats-nightlies.s3.amazonaws.com/index.html?prefix=jenkins/filebeat/]
にある純正スタティックリンク版がさっくり動いた。
 
filebeat-god はコンパイルした
<syntaxhighlight lang="bash" enclose="div">
git clone https://github.com/tsg/go-daemon.git
cd go-daemon
make
mv god filebeat-god
</syntaxhighlight>
 
config ファイル等は deb から流用
<syntaxhighlight lang="bash" enclose="div">
curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.5.1-amd64.deb
dpkg-deb -x filebeat-5.5.1-amd64.deb ./
</syntaxhighlight>
 
== RLIMIT_MEMLOCK ==
systemd 配下の場合は /usr/lib/systemd/system/elasticsearch.service
<syntaxhighlight lang="text" enclose="div">
[service]
LimitMEMLOCK=infinity
</syntaxhighlight>
 
こっちで対処するのが良いそうだ。
<syntaxhighlight lang="bash" enclose="div">
systemctl edit elasticsearch
</syntaxhighlight>
このコマンドで、
/etc/systemd/system/elasticsearch.service.d/override.conf
ここに、
<syntaxhighlight lang="text" enclose="div">
[service]
LimitMEMLOCK=infinity
</syntaxhighlight>
 
== sigle node / standalone ==
<syntaxhighlight lang="text" enclose="div">
discovery.type: single-node
</syntaxhighlight>
 
== Elastic Stack 6.0.0 upgrade memo ==
"type" がつかえない
 
https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html
 
statsd が標準プラグインから消えた。
 
./bin/logstash-plugin install logstash-output-statsd
 
kibana の '.kibana' のフォーマット変換が必要
https://www.elastic.co/guide/en/kibana/6.0/migrating-6.0-index.html
 
 
"type" が使えなくなったので "log_type" というカスタムフィールドにかえた。その変更をコツコツした。
 
変換後いろいろ確認して、無駄なものを削除した
curl -XGET 'http://127.0.0.1:9200/.kibana/_search/?size=1000&pretty'
curl -XDELETE 'http://127.0.0.1:9200/.kibana/doc/#{_id}
 
 
python beaver も 6.0 には対応できてない。
とりあえず type を送らないようにした。
 
<syntaxhighlight lang="diff" enclose="div">
--- ./beaver/transports/base_transport.py.orig 2017-11-30 10:57:01.546311555 +0900
+++ ./beaver/transports/base_transport.py 2017-11-24 11:40:34.962587490 +0900
@@ -36,21 +36,19 @@
self._logstash_version = beaver_config.get('logstash_version')
if self._logstash_version == 0:
self._fields = {
- 'type': '@type',
'tags': '@tags',
'message': '@message',
'file': '@source_path',
'host': '@source_host',
- 'raw_json_fields': ['@message', '@source', '@source_host', '@source_path', '@tags', '@timestamp', '@type'],
+ 'raw_json_fields': ['@message', '@source', '@source_host', '@source_path', '@tags', '@timestamp'],
}
elif self._logstash_version == 1:
self._fields = {
- 'type': 'type',
'tags': 'tags',
'message': 'message',
'file': 'file',
'host': 'host',
- 'raw_json_fields': ['message', 'host', 'file', 'tags', '@timestamp', 'type'],
+ 'raw_json_fields': ['message', 'host', 'file', 'tags', '@timestamp'],
}
def raw_formatter(data):
@@ -122,7 +120,6 @@
formatter = self._default_formatter
data = {
- self._fields.get('type'): kwargs.get('type'),
self._fields.get('tags'): kwargs.get('tags'),
'@timestamp': timestamp,
self._fields.get('host'): self._current_host,
</syntaxhighlight>
 
== Elastic Stack 5.0.0 upgrade memo ==
/var/log/kibana/kibana.stdout が肥大化していたので logrotate 設定した。
-->
=== IPv6 address の抽出 ===
単純な方法があった。
<syntaxhighlight lang="text" enclose="div">
client_ip: *\:*
</syntaxhighlight>
:これだとマッチしないのがあるっぽいな。要調査
<syntaxhighlight lang="text" enclose="div">
client_ip: ["::" TO "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]
</syntaxhighlight>
:これでも抜けるな
::これかな? [https://github.com/elastic/elasticsearch/issues/29288 unable to CIDR match IPv4-mapped IPv6]
:::あちゃ。type ipになってなかった。もうすこしホゲる。
:::: type ip にしてみたが、うまくマッチする方法がみつからない。
どうやら type ip ではこれで良い。このアドレスはインターネットに広報してよいブロックのみ。これ以外は変えないといけない。
<syntaxhighlight lang="text" enclose="div">
client_ip: "2000::/3"
</syntaxhighlight>
 
ちなみに logstash だとこんなコードでマッチする。実運用では logstash 側のロジックで新しいフィールドつくった。
 
結局 type ip ならこれでよさそうだ。
<syntaxhighlight lang="text" enclose="div">
if [client_ip] =~ /:/ {
# is IPv6, do something
mutate {
add_field => { "client_ipv6" => "%{client_ip}" }
}
}
</syntaxhighlight>
 
== dashboard URL ==
= Elasticsearch =
== 構造 ==
curl -XGET 'http://127.0.0.1:9200/{INDEX}/{TYPE:mapping}/{ID:Document}'
curl -XGET 'http://127.0.0.1:9200/{INDEX}/{TYPE:mapping}/{ID:Document}/_source'
curl -XGET 'http://127.0.0.1:9200/{INDEX}/{TYPE:mapping}/_mapping'
curl -XGET 'http://127.0.0.1:9200/{INDEX}/{TYPE:mapping}/_mapping?pretty'
 
curl -XGET 'http://127.0.0.1:9200/_search?q=tags:_grokparsefailure'
 
curl -XGET 'http://127.0.0.1:9200/_cluster/health?pretty'
curl -XGET 'http://127.0.0.1:9200/_template?pretty'
 
curl -XGET 'http://127.0.0.1:9200/kibana-int/_search?q=*:*&pretty'
curl -XGET 'http://127.0.0.1:9200/kibana-int/_search?q=*:*&size=100&pretty'
curl -XGET 'http://127.0.0.1:9200/kibana-int/_search/?size=100&pretty'
 
== 設定 ==
</syntaxhighlight>
:curator4 で大幅に書式変わった。
 
Disk full で index がロックされた場合
<syntaxhighlight lang="bash" enclose="div">
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
</syntaxhighlight>
 
[https://github.com/lmenezes/elasticsearch-kopf kopf web admin interface for elasticsearch]
curl -XDELETE 'http://127.0.0.1:9200/logstash-YYYY.MM.DD/sysdig'
</syntaxhighlight>
 
X-Pack 削除したら...
curl -XGET 'http://127.0.0.1:9200/_cluster/health?level=shards&pretty'
curl -XDELETE 'http://127.0.0.1:9200/.security'
curl -XDELETE 'http://127.0.0.1:9200/.triggered_watches'
curl -XDELETE 'http://127.0.0.1:9200/.watches'
curl -XDELETE 'http://127.0.0.1:9200/.monitoring-es-6-YYYY.MM.DD'
curl -XDELETE 'http://127.0.0.1:9200/.monitoring-alerts-6'
curl -XDELETE 'http://127.0.0.1:9200/.watcher-history-6-YYYY.MM.DD'
 
= memo =
 
[https://github.com/nxhack/munin-plugin-logstash https://github.com/nxhack/munin-plugin-logstash]
 
Munin plugin for elasticsearch も Pull Request がマージされた。
 
[https://github.com/y-ken/munin-plugin-elasticsearch https://github.com/y-ken/munin-plugin-elasticsearch]
[https://github.com/y-ken/munin-plugin-elasticsearch/commit/389725c05a8c43815e38bc30a81216891cc43720 Merge pull request #14 from nxhack/patch_for_ES_5.0.0 ]