[英]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.