获取iis中站点连接数

必须要有注册表的访问权限

 1 System.Threading.Tasks.Task.Run(async () =>
 2 {
 3     while (true)
 4     {
 5         try
 6         {
 7             //获取当前站点连接数
 8             var counter = new System.Diagnostics.PerformanceCounter
 9             {
10                 CategoryName = "Web Service",
11                 CounterName = "Current Connection",
12                 //web站点名
13                 InstanceName = "sys_web_test"
14             };
15             var count = counter.NextValue();
16             LogHelper.WriteInfo($"连接数:{count}", "ApiConnections");
17         }
18         catch (Exception ex)
19         {
20             LogHelper.WriteInfo(ex.ToString(), "Error_ApiConnections");
21         }
22         await System.Threading.Tasks.Task.Delay(1000);
23     }
24 });

 

posted @ 2024-05-22 16:51  util6  阅读(5)  评论(0编辑  收藏  举报