需求:
在k8s平台中的pod,内網監控并将資料發送到newrelic做alert。
實作:
1. 參考https://docs.newrelic.com/docs/insights/insights-data-sources/custom-data/send-custom-data-insights#transaction-defaults
https://docs.newrelic.com/docs/insights/insights-data-sources/custom-data/send-custom-events-event-api
選擇使用event-api将pod内擷取到的資料發送到newrelic
2. 在newrelic裡建立alert

點選”Alerts“ 打開alert界面-> 選擇”Alert Policies“
在界面右上角點選”New alert policy“
輸入 name, preference選擇by condition.
3. 在insight中檢視data是否成功上傳
在newrelic首頁菜單欄選擇”insights“,打開如下界面:
在該界面輸入查詢語句來檢索結果。
如 上傳如下json資料,NRQL語句可以寫作 select * from Purchase when account >=3
參考https://docs.newrelic.com/docs/insights/nrql-new-relic-query-language/using-nrql/query-page-create-edit-nrql-queries
[
{
"eventType":"Purchase",
"account":3,
"amount":259.54
},
{
"eventType":"Purchase",
"account":5,
"amount":12309,
"product":"Item"
}
]
4. 如果資料成功上傳,那麼接下來需要建立codition
打開alert policy界面:
選擇”create a codition“
選擇”NRQL“,
輸入NRQL的query語句。thresholds中設定針對query結果的政策。輸入condition name後,點選”create codition“。
至此,使用api發送資料,并使用newrelic建立alert做監控的基本工作完成。