0

我们需要在 Windows 服务启动和停止时获取它的状态,因为我返回了一个查询,但是在加入 2 个表以获取输出时我遇到了问题。

我已经尝试使用内部和左外部连接,但仍然得到重复

Event
| where EventLog == "System" and EventID == 7036 and Source == "Service Control Manager"
| parse kind=relaxed EventData with * '<Data Name="param1">' Windows_Service_Name '</Data><Data Name="param2">' Windows_Service_State '</Data>' *
| where Windows_Service_State == "running" and Windows_Service_Name == "Microsoft Monitoring Agent Azure VM Extension Heartbeat Service"
| extend startedtime = TimeGenerated 
| join   (
Event
| where EventLog == "System" and EventID == 7036 and Source == "Service Control Manager"
| parse kind=relaxed EventData with * '<Data Name="param1">' Windows_Service_Name '</Data><Data Name="param2">' Windows_Service_State '</Data>' *
| where Windows_Service_State == "stopped" and Windows_Service_Name == "Microsoft Monitoring Agent Azure VM Extension Heartbeat Service"
| extend stoppedtime = TimeGenerated 
) on Computer 
| extend downtime = startedtime - stoppedtime
| project Computer, Windows_Service_Name,stoppedtime , startedtime  ,downtime
| top 10  by Windows_Service_Name desc 

如果服务在一天内多次重新启动,我们希望获得该服务启动和停止的次数我们在加入时在启动时间得到重复的时间,请查看链接(https://ibb.co/JzqxjC0

4

1 回答 1

1

我不确定我是否完全理解发生了什么,因为我无权访问数据。但。我可以看到您正在使用默认的 join flavor

默认是内部唯一的:

内连接函数类似于 SQL 世界中的标准内连接。只要左侧的记录与右侧的记录具有相同的连接键,就会生成输出记录。

这意味着在左侧和右侧之间的每次匹配时都会在结果中创建一个新行。所以。假设您有一台重新启动两次的计算机,因此它有 2 行 .stopped和 2 行running. 这将在 Kusto 答案中产生 4 行。

看着你的照片,这对我来说很有意义,因为你有负停机时间的线路。我想这是不可能的。

我要做的是寻找每次Computer运行时唯一的标识符。然后您可以加入其中,并保持安全,不要生成您不想要的数据。

于 2020-08-09T16:15:07.523 回答