【问题标题】:Parse IBM MQ Event Monitoring messages in local time在本地时间解析 IBM MQ Event Monitoring 消息
【发布时间】:2019-02-12 02:40:53
【问题描述】:

我正在使用 IBM 提供的示例程序 amqsevt 来监控 MQ 事件队列并解析消息。但我注意到,默认情况下,事件创建时间以 GMT 时间表示。我想让它转换为系统本地时间。有没有办法做到这一点?

**** Message #1 (120 Bytes) on Queue SYSTEM.ADMIN.CHANNEL.EVENT ****
Event Type                       : Channel Event [46]
Reason                           : Channel Stopped By User [2279]
Event created                    : 2018/09/04 20:17:39.48 GMT

【问题讨论】:

  • 我建议修改并重新编译示例程序,让它以您喜欢的格式输出日期。请注意,在 Mark Taylor 的一篇关于事件主题的博客文章中,他发布了一个可以以 JSON 格式输出的修改版本,这个相同的版本现在包含在 9.1.0.0 版本中,它可能是一种更容易输入监控的格式工具。

标签: events timezone ibm-mq gmt


【解决方案1】:

可以在/opt/mqm/opt/mqm/samp/amqsevta.c 安装 MQ 的 Linux 上找到示例的源代码。

在每条消息的MQMD(消息描述符)中,有一个PutDatePutTime 字段始终存储在GMT 中,每个字段都是简单的8 位字符串,例如:

  • PutDate: 20180904 (YYYYMMDD)
  • 放置时间:20173948 (HHMMSSSS)

在示例程序中,它只是将其转换为2018/09/04 20:17:39.48 的显示格式,并将GMT 附加到末尾,因为它知道这始终是GMT。

  /**********************************************************/
  /* Timestamp is read from the MQMD - it is always in GMT  */
  /* regardless of local timezone. Do not want to try to    */
  /* convert it, because this machine may be a client in a  */
  /* different timezone than the server generating the      */
  /* event. So stick to GMT (or UCT if you prefer).         */
  /**********************************************************/
  sprintf(valbuf,"%4.4s/%2.2s/%2.2s %2.2s:%2.2s:%2.2s.%2.2s GMT",
     &pMsgDesc->PutDate[0],
     &pMsgDesc->PutDate[4],
     &pMsgDesc->PutDate[6],
     &pMsgDesc->PutTime[0],
     &pMsgDesc->PutTime[2],
     &pMsgDesc->PutTime[4],
     &pMsgDesc->PutTime[6]);
  printLine(offset,"Event created",valbuf);

看来您可以使用 c 函数 strptime 将字符串解析为纪元时间戳,然后在本地时区打印。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-04
    • 2022-07-21
    相关资源
    最近更新 更多