繁体   English   中英

从 python 将指标发送到 splunk

[英]send metrics to splunk from python

我有一个包含一些指标的字典列表,比如说

[{"a": 1, "b": 2},
 {"a": 3, "b": 4},
 {"a": 1, "b": 2}]

作为最终结果,我需要发送两条指标消息

value: 2, dimensions: {"a": 1, "b": 2}  #just amount of elements with same dim values
value: 1, dimensions: {"a": 3, "b": 4}

有没有办法像原始字典列表一样发送它们,所以 splunk 可以自己计算所有内容?

您可以使用 HEC 将所有维度作为事件发送,然后在 splunk 中进行后处理。 stats 命令可以派上用场,我在下面附上了一个示例。 A nice Python class to help sending events to the HTTP Event Collector in your code can be found here: https://github.com/georgestarcher/Splunk-Class-httpevent

示例调用:

curl -k "https://localhost:8088/services/collector" \
    -H "Authorization: Splunk hec-token-here" \
    -d '{"event": "{\"a\": 1, \"b\": 2}"}{"event": "{\"a\": 3, \"b\": 4}"}{"event": "{\"a\": 1, \"b\": 2}"}'

Splunk 统计数据

index=main
|stats c by _raw

请注意结果如何显示您有两个{"a": 1, "b": 2}事件和一个{"a": 3, "b": 4}事件

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM