Have you ever wondered if Logstash was sending data to your outputs? There's a brand new way to check if Logstash has a "pulse." Introducing the heartbeat input plugin! It’s bundled with Logstash 1.5 so you can start using it immediately!

Why?

Logstash currently has a single pipeline. All events generated by inputs travel through the filter block, and then out of Logstash through the output block.

Even if you have multiple outputs and are separating events using conditionals all events pass through this single pipeline. If any one of your outputs backs up, the entire pipeline stops flowing. The heartbeat plugin takes advantage of this to help you know when the flow of events slows, or stops altogether.

How?

The heartbeat plugin sends a message at a definable interval. Here are the options available for the message configuration parameter:

  • Any string value: The message field will contain the specified string value.  If unset, the message field will contain the string value ok
  • epoch: Rather than a message field, this will result in a clock field which will contain the current epoch timestamp (UTC). If you are unfamiliar with this, it means the number of seconds elapsed since Jan 1, 1970.
  • sequence: Rather than a message field, this will result in a clock field which will contain a number. At start time, the sequence starts at zero and will increment each time your specified interval time has elapsed. Note that this means that if you restart Logstash, the counter resets to zero again.

Examples

Be sure to assign a type to your heartbeat events. This will make it possible to conditionally act on these events later on.

"ok" Message

Perhaps you only want to know that Logstash is still sending messages. Your monitoring system can interpret an "ok" received within a time window as an indicator that everything is working. Your monitoring system would be responsible for tracking the time between "ok" messages.

I can send the default "ok" message every 10 seconds like this:

input {
heartbeat {
interval => 10
type => "heartbeat"
}
# ... other input blocks go here
}

The events would look like this:

{"message":"ok","host":"example.com","@version":"1","@timestamp":"2015-03-18T17:05:24.696Z","type":"heartbeat"}
{"message":"ok","host":"example.com","@version":"1","@timestamp":"2015-03-18T17:05:34.696Z","type":"heartbeat"}
{"message":"ok","host":"example.com","@version":"1","@timestamp":"2015-03Read More

Epoch timestamp

Perhaps your monitoring system uses unix timestamps to track event timing (like Zabbix, for example). If so, you can use the epoch timestamp in the clock field to calculate the difference between "now" and when Logstash generated the heartbeat event. You can calculate lag in this way. This may be especially useful if you inject the heartbeat before events go into a broker, or buffering system, like Redis, RabbitMQ, or Kafka. If the buffer begins to fill up, the time difference will become immediately apparent. You could use this to track the elapsed time--from event creation, to indexing--for your entire Logstash pipeline.

This example will send the epoch timestamp in the clock field:

input {

  heartbeat {
message => "epoch"
interval => 10
type => "heartbeat"
}
# ... other input blocks go here
}

The events would look like this:

{"clock":1426698365,"host":"example.com","@version":"1","@timestamp":"2015-03-18T17:06:05.360Z","type":"heartbeat"}
{"clock":1426698375,"host":"example.com","@version":"1","@timestamp":"2015-03-18T17:06:15.364Z","type":"heartbeat"}
{"clock":1426698385,"host":"example.com","@version":"1","@timestamp":"2015Read More

Sequence of numbers

This example makes it easy to immediately check if new events are occurring because the clock will continuously increase.

input {
heartbeat {
message => "sequence"
interval => 10
type => "heartbeat"
}
# ... other input blocks go here
}

The events would look like this:

{"clock":1,"host":"example.com","@version":"1","@timestamp":"2015-03-18T17:08:13.024Z","type":"heartbeat"}
{"clock":2,"host":"example.com","@version":"1","@timestamp":"2015-03-18T17:08:23.027Z","type":"heartbeat"}
{"clock":3,"host":"example.com","@version":"1","@timestamp":"2015-03-18T17Read More

Output

Now let's add a conditional to send this to our monitoring system, and not to our other outputs:

output {
if [type] == "heartbeat" {
# Define the output block for your monitoring system here
} else {
# ... other output blocks go here
}
}

Of course, if you do want your heartbeat messages to be indexed alongside your log data, you are free to do so.

Conclusion

The new heartbeat plugin provides a simple, but effective way to monitor the availability of your Logstash instances right now. We have big plans for the future, though.  Take a look at our road map!

In the future we plan to have a full API, complete with visibility into the pipeline, plugin performance, queue status, event throughput and so much more.  We are super excited to bring these improvements to you!

Happy Logstashing!

input {
heartbeat {
tags => ["heartbeat"]
type => "heartbeat"
message => "epoch"
interval =>
}
} output {
if "heartbeat" in [tags] {
file {
path => "/var/log/cloudchef/logstash/logstash-hearbeat.log"
}
}
}

最新文章

  1. python 小程序 复制目录树
  2. PHP WAMP 文件上传 及 简单的上传预览
  3. Windows下 Maven 使用 阿里云镜像配置
  4. loadrunner-VUserGen录制脚本及回放时注意的问题
  5. 剑指Offer 斐波那契数列
  6. 用node-webkit 开发 PC 客户端
  7. Matlab实现抽样定理
  8. C#属性(Attribute)用法实例解析
  9. JVM内存分配
  10. ASP.NET Web Service如何工作(1)
  11. mysql5.7.14安装与配置
  12. git学习利器:《Git Pro》中文版
  13. asp.net Global.asax 不运行解决
  14. 分布式事务的典型处理方式:2PC、TCC、异步确保和最大努力型
  15. xampp——apache服务启动问题(端口占用)
  16. Holer实现外网访问本地MySQL数据库
  17. 优化MySQL性能的几种方法-总结
  18. Python—全局变量、局部变量、匿名函数
  19. hdu 5326(基础题) work
  20. pyinstaller基本操作

热门文章

  1. Hdu1151 Air Raid(最小覆盖路径)
  2. 微信小程序-button组件
  3. redis解决保存快照失败后redis无法写入的问题
  4. Swift3 页面顶部实现拉伸效果代码
  5. 最小生成树Prim poj1258 poj2485 poj1789
  6. FastReport之实现打印固定行数,不足补打空白行的办法
  7. Jquery学习(表单-Button)-----jQuery1.4.2
  8. SQL SERVER的锁机制(三)——概述(锁与事务隔离级别)
  9. BZOJ 1016--[JSOI2008]最小生成树计数(kruskal&搜索)
  10. 基本数据类型补充 set集合 深浅拷贝