Powershell和服务结构-如何选择特定信息并在以后的操作中使用它?

时间:2019-02-26 07:57:28

标签: powershell azure-service-fabric

下面是代码,我如何连接到服务结构集群并获取所需的应用程序运行状况信息:

EXECUTE format(
            'insert into tmp_booking_containers (
                booking_data_source,
                booking_place_of_creation,
                booking_prefix,
                booking_number,
                booking_prefix_number,
                booking_container_type,
                booking_container_quantity
            ) select 
                booking_data_source,
                booking_place_of_creation,
                booking_prefix,
                booking_number,
                booking_prefix_number,
                %I,
                %I
            from dim_booking_masters 
            where %I != 0',
            column01, column2, column02;

但是目前有很多信息,我不需要。如何仅从结果中选择特定信息?我只需要ServiceHealthState信息。我能够从应用程序运行状况中排除一些信息,但没有设法排除更多信息。

更新:

我找到了以下解决方案,与我尝试实现的解决方案很接近:

 @if($match->schedule > 0)
      &nbsp;<strong id="match_schedule">Match will start soon</strong>
 @endif

但是我不需要监视AggregatedHealthState,因为我只对ServiceHealthStates下的一部分感兴趣,请参见示例:

  

ApplicationName:织物:/ Myapp
  AggregatedHealthState:错误
  ServiceHealthStates:

     
    

ServiceName:结构:/ Myapp / Frontend
    AggregatedHealthState:错误
    ServiceName:结构:/ Myapp / Backend
     AggregatedHealthState:好

  

但是我不知道该如何选择该部分,也没有从Google找到该部分,希望有人可以提供帮助。

1 个答案:

答案 0 :(得分:0)

找到适合我的解决方案,也将其发布在此处,如果其他人遇到相同的问题,我的解决方案:

# Connect to Service Fabric cluster
$ConnectArgs = @{
 ConnectionEndpoint = "mycluster:19000";  
 X509Credential = $True;  
 StoreLocation = 'CurrentUser';  
 StoreName = "MY"; 
 FindType = 'FindByThumbprint';  
 FindValue = "My_Thumbprint"
 }
Connect-ServiceFabricCluster @ConnectArgs 

# Test Cluster connection
$Connection=Test-ServiceFabricClusterConnection
If ($Connection -eq "True") { 
    Write-Host "OK"}
Else 
{
    Write-Host "Connection to Service fabric cluster failed" 
}

# Service Fabric application health monotoring
$AppName="MyApp"

$AppHealth=Get-ServiceFabricApplicationHealth -ApplicationName $AppName 
$AppHealthBE=$AppHealth.ServiceHealthStates -match "Backend"

$node=Get-ServiceFabricApplicationHealth -ApplicationName $AppName
$nodetorestart=$node.DeployedApplicationHealthStates.NodeName -match  "MyNode"

If ($AppHealthBE.AggregatedHealthState -eq "Ok") {
   Write-Host "$($clusterApplication)/backend is OK"
   }
   Else
   {
   Write-Host "Need to perform restart on node: $nodetorestart)"
   #Restart-ServiceFabricNode -NodeName $nodetorestart
   }