-1

此 bash 命令 " etcdctl get system config/log/timestamp" 返回时间类型 UTC 或 System. 现在我想用它来将时间转换为相同的格式。我怎样才能做到这一点?

我试过了,但 td-agent 运行失败。

<source>
  @type exec
  command etcdctl get system config/log/timestamp
  <parse>
    keys timeType
  </parse>
</source>

现在我想使用那个 timeType 将我的时间从给定的日志转换为那个 timeType

{"host":"sp-1","level":"INFO","log":{"classname":"common.server.hacluster.CSFHATopologyChangeHandlerMBean:93","message":"Finished processing CSF HA 'become standby' message.","stacktrace":"","threadname":"RMI TCP Connection(1784)-192.168.20.11"},"process":"becomeStandby","service":"SP","time":"2020-03-19T10:15:36.514Z","timezone":"America/Toronto","type":"log","system":"SP_IG_20_3_R1_I2002","systemid":"SP_IG_20_3_R1_I2002"}

这是我想使用 $timeType 的地方

<filter com.logging.tmplog>
  @type record_modifier
  <record>
  type log
  time ${record["time"]}.$timeType   ## It's not working
  arun ${tag}
  </record>
</filter>
4

1 回答 1

0

通过使用记录修饰符的 prepare_value 解决了这个问题

<filter com.logging.tmplog> @type record_modifier prepare_value @timeType =`etcdctl 获取系统配置/日志/时间戳`.strip

<record> timeType ${@timeType} time ${if @timeType == 'UTC' then Time.at(time).utc.strftime('%FT%T') else Time.at(time).to_s; end} </record> </filter>

于 2020-03-27T08:57:43.740 回答