You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Splunk月度时间图表如何获取每月1日数值而非整月总和?

Splunk 查询解决方案:获取每月1日的统计数值

原查询source=all_month.csv place=*alaska* mag>=3.5 | timechart span=mon@mon1 count BY mag会统计整月所有符合条件事件的总数,并将结果对齐到每月1日的时间点,这并不是你需要的「每月1日当天的数值」。以下是两种可行的解决方法:

方法一:先筛选每月1日的事件再统计

直接过滤出发生在每月1日的事件,再用timechart按月份分组统计:

source=all_month.csv place=*alaska* mag>=3.5 
| where strftime(_time, "%d") == "01"
| timechart span=1mon count BY mag
  • strftime(_time, "%d")会提取事件时间的日部分(格式为两位数字,如"01"),where语句只保留日为"01"的事件
  • timechart span=1mon会将每月1日的统计结果对应到该月的时间节点,最终输出就是你需要的2022-10-01、2022-09-01等时间点的数值

方法二:生成月起始时间戳后统计

如果需要更灵活的时间格式控制,可以先生成每月1日的时间戳,再用stats统计:

source=all_month.csv place=*alaska* mag>=3.5 
| where strftime(_time, "%d") == "01"
| eval month_start = strptime(strftime(_time, "%Y-%m-01"), "%Y-%m-%d")
| stats count BY month_start mag
| rename month_start AS _time
| sort _time
  • eval month_start将事件时间转换为当月1日的标准时间戳
  • stats按时间戳和mag分组统计数量,最后将字段改回_time并排序,得到规范的时间序列结果

注意事项

  • 确保事件的_time字段是正确的事件发生时间,否则筛选逻辑会出错
  • 如果你的数据中日部分是单数字格式(如"1"而非"01"),请将where条件改为strftime(_time, "%d") == "1"或strftime(_time, "%e") == " 1"(根据实际日期格式调整)

内容的提问来源于stack exchange,提问作者Ann

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 04:45:35