Logstash:运用 makelogs 创建测试日志

我们在使用 Elasticsearch 时,经常想找一些数据来进行测试,比如我们想试一下 Kibana 的可视化工具。我们有时想有很多的数据,但是有时就是找不到合适的数据。那么我们该怎么办呢?当然,我们有一种简单的办法就是使用 Kibana 给我们提供的测试数据,但是它可能也有很多的局限性:

另外一种方法就是使用一些工具来生成我们想要数量或要求的数据。在今天的文章中,我们就来介绍这样的一个工具 makelogs

下载 makelogs

我们在地址 https://github.com/elastic/makelogs 下载 makelogs:

git clone https://github.com/elastic/makelogs
cd makelogs

按照项目的要求,我们进行如下的安装:

npm install -g @elastic/makelogs

在实际使用中,我发现还需要安装另外的两个模块:

npm install update-notifier
npm install commander --save

这样我们的安装就完成了。

运行 makelogs

接下来,我们就可以运行 makelogs。为了能够了解这个工具的作用,我们使用如下的命令:

./bin/makelogs --help
$ ./bin/makelogs --help
Usage: makelogs [options]

A utility to generate sample log data.

Options:
  -c, --count <number>       Total event that will be created, accepts
                             expressions like "1m" for 1 million (b,m,t,h)
                             (default: 14000)
  -d, --days <number>        Number of days ± today to generate data for. Use
                             one number or two separated by a slash, e.g.
                             "1/10" to go back one day, and forward 10
                             (default: 1)
  --url <url>                Elasticsearch url, overrides host and auth, can
                             include any url part.
  -h, --host <host>          The host name and port (default:
                             "localhost:9200")
  --auth <auth>              user:password when you want to connect to a
                             secured elasticsearch cluster over basic auth
                             (default: null)
  --indexPrefix <name>       Name of the prefix of the index (default:
                             "logstash-")
  -s, --shards <number>      The number of primary shards (default: 1)
  -r, --replicas <number>    The number of replica shards (default: 0)
  --dry                      Test/Parse your arguments, but don't actually do
                             anything
  --reset                    Clear all {prefix}-* indices and the makelogs
                             index template before generating (default:
                             prompt)
  --no-reset                 Do not clear all {prefix}-* indices and the
                             makelogs index template before generating
                             (default: prompt)
  --verbose                  Log more info to the console
  --trace                    Log every request to elasticsearch, including
                             request bodies. BE CAREFUL!
  -o, --omit <...>           Omit a field from every event. See "formatting an
                             omit path"
  -i, --indexInterval <...>  The interval that indices should roll over,
                             either "daily", "monthly", "yearly", or a number
                             of documents. (default: 100000)
  --types                    Pass to enable types in index and document
                             creation
  --indexTemplatesV1         Pass to enable types in index templates v1
                             compatibility
  -V, --version              output the version number
  --help                     This help message

formatting an omit path
=======================

To remove a single top level property, you can simply specify the name of the property you want to remove:

  $ makelogs --omit request

To remove multiple properties, simply use omit multiple times

  $ makelogs --omit request --omit referrer

You can use dot notation to access properties of object values

  $ makelogs --omit machine.os

Or, you can omit the entire object value

  $ makelogs --omit machine

Finally, to traverse into arrays/nested fields you must use the [] operator

  $ makelogs --omit relatedContent[].title

上面显示了这个命令的所有的帮助信息。

接下来我们使用上面的命令来生成我们想要的 logstash 日志:

makelogs -c 10

等上面的命令运行完后,我们在 Kibana 里进行检查:

GET _cat/indices

我们看到一个新生成的叫做 logstash-0 的索引。我们使用如下的命令来检查文档的个数:

GET logstash-0/_count

上面显示共有 11 个文档生成。

我们可以对这个索引进行搜索:

我们可以看到这些被 makelogs 所生成的 logstash 文档。这些文档可以成为我们对数据分析的一个基础供我们进行练手。在生产环境中,当然不能进行使用了。

猜你喜欢

转载自blog.csdn.net/UbuntuTouch/article/details/106651151
今日推荐