在azure中測試API端點的最佳方法是什麼?如果端點不工作,我正在尋找警報。如何在azure中創建API健康檢查?
2
A
回答
1
我建議你創建一個WebJob來測試你的API端點。在您的WebJob中,您可以使用TimerTrigger及時運行測試功能(例如,每2分鐘)。
要使用TimerTrigger,您需要使用NuGet安裝Microsoft.Azure.WebJobs.Extensions包。之後,您可以使用以下代碼將WebJob配置爲使用計時器擴展。
static void Main()
{
var config = new JobHostConfiguration();
//Configure WebJob to use TimerTrigger
config.UseTimers();
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
在函數中,您可以發送請求到您的Web API。如果您無法從服務器獲得響應,或者響應狀態不等於200 OK,則表示Web API不可用。
public static void StartupJob([TimerTrigger("0 */2 * * * *", RunOnStartup = true)] TimerInfo timerInfo)
{
WebRequest request = WebRequest.Create("URL of your api");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response == null || response.StatusCode != HttpStatusCode.OK)
{
//API is not useable
}
}
1
查看Application Insights中的webtest功能。
相關問題
- 1. gitlab健康檢查不健康
- 2. SSRS健康檢查
- 3. MySQL健康檢查
- 4. UDP健康檢查
- 5. DB健康檢查Rails中
- 6. elb健康檢查和ec2健康檢查有什麼區別?
- 7. python boto - 如何爲路線創建健康檢查53
- 8. 如何爲Marathon任務創建健康檢查HTTP端點?
- 9. AWS AutoScaling:如何禁用健康檢查
- 10. WSO2流健康檢查
- 11. Elixir的Postgres健康檢查
- 12. Haproxy健康檢查端口
- 13. Js noob健康檢查
- 14. 健康檢查MassTransit和Rabbitmq
- 15. C3P0連接健康檢查
- 16. HAproxy被動健康檢查
- 17. 如何創建彎曲的健康欄?
- 18. 谷歌健康API
- 19. 如何在春季開機創建自定義mongo健康檢查?
- 20. Azure資源健康監測
- 21. 無法從配置文件創建Http健康檢查Consul
- 22. 爲ASP.NET MVC 4應用程序創建健康檢查頁面
- 23. Cloud Foundry中的健康檢查
- 24. 添加健康檢查中Startup.Configure
- 25. 如何檢查的SQLite文件的一致性(健康檢查)
- 26. 如何檢查後端在vcl_recv中是否健康
- 27. 如何在遠程系統中自動進行健康檢查?
- 28. Azure中的不健康實例
- 29. Azure中的不健康雲服務
- 30. 健康檢查爲使用SQL Server 2008