【问题标题】:logstash cron schedule to run every 12 hours starting at certain timelogstash cron 计划从特定时间开始每 12 小时运行一次
【发布时间】:2018-07-31 12:03:29
【问题描述】:

我正在尝试0 1/12 * * * cron 表达式,但它每天只触发一次。以下是我的配置之一。

input {
    jdbc {
        jdbc_connection_string => "jdbc:redshift://xxx.us-west-2.redshift.amazonaws.com:5439/xxx"
        jdbc_user => "xxx"
        jdbc_password => "xxx"
        jdbc_validate_connection => true
        jdbc_driver_library => "/mnt/logstash-6.0.0/RedshiftJDBC42-1.2.10.1009.jar"
        jdbc_driver_class => "com.amazon.redshift.jdbc42.Driver"
        schedule => "0 1/12 * * *" #01:00,13:00, tried from https://crontab.guru/#0_1/12_*_*_*
        statement_filepath => "conf/log_event_query.sql"
        use_column_value => true
        tracking_column => dw_insert_dt
        last_run_metadata_path => "metadata/logstash_jdbc_last_run_log_event"
    }
}
output {
    elasticsearch {
        index => "logs-ics_%{+dd_MM_YYYY}"
        document_type => "log_event"
        document_id => "%{log_entry_id}"
        hosts => [ "x.x.x.x:xxxx" ]
    }
}

我也在0 0 1/12 ? * * *下面从https://www.freeformatter.com/cron-expression-generator-quartz.html尝试过,但是lostash不支持这种类型。 Original 已使用 cron。

请帮我获得一个根据以下日期在logstash中工作的cron表达式,还有一个在线页面可以让我测试我未来的logstash cron表达式吗?

1st  at 2018-08-01 01:00:00
then at 2018-08-01 13:00:00
then at 2018-08-02 01:00:00
then at 2018-08-02 13:00:00
then at 2018-08-03 01:00:00

【问题讨论】:

  • 你的 cron 似乎是对的。您绝对确定 Logstash 不会每天启动两次吗?你是怎么调查的?
  • @Val:我检查了 logstash 日志以验证它何时触发。所以我每天凌晨 1 点看到一次触发器。

标签: elasticsearch logstash


【解决方案1】:

您的日程安排格式似乎有误。

要执行每十二小时一次的任务,您应该使用*/12,而不是1/12

0 */12 * * * # Every twelve hours at minute 0 of the hour.

您的日程安排看起来更像是尝试在 1 和 12 运行任务,但要做到这一点,您需要使用逗号,如下所示:

0 1,12 * * * # Run at one and twelve hours at minute 0.

rufus 扩展还允许添加时区(如 Asia/Kuala_Lumpur),如果您需要在不是默认机器时钟的特定时区按计划运行。

您上面的代码没有向我们显示您正在运行的 SQL 查询。查询可能正在触发,但如果查询没有结果,您将不会在 logstash 中获得任何输入。在任何情况下,您的调度语法都需要从 1/12 更改为 */12 以执行您想要的操作。

更一般地说,根据logstash jdbc输入插件文档,调度格式被认为是cron-“like”。 logstash jdbc 输入插件使用 ruby​​ Rufus 调度程序。该调度格式的文档在这里:https://github.com/jmettraux/rufus-scheduler#parsing-cronlines-and-time-strings

Logstash 6.0 JDBC 插件文档在这里:https://www.elastic.co/guide/en/logstash/6.0/plugins-inputs-jdbc.html

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2021-08-22
    • 1970-01-01
    • 2012-03-12
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    相关资源
    最近更新 更多