public string GetStatus() { // Use the cluster health API to verify that the Best Bets index is functioning. // Maps to https://ncias-d1592-v.nci.nih.gov:9299/_cluster/health/bestbets?pretty (or other server) // // References: // https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html // https://github.com/elastic/elasticsearch/blob/master/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.health.json#L20 IClusterHealthResponse response = _elasticClient.ClusterHealth(hd => { hd = hd .Index("autosg"); return(hd); }); if (!response.IsValid) { _logger.LogError("Error checking ElasticSearch health."); _logger.LogError("Returned debug info: {0}.", response.DebugInformation); throw new APIErrorException(500, "Errors Occurred."); } if (response.Status != "green" && response.Status != "yellow") { _logger.LogError("Elasticsearch not healthy. Index status is '{0}'.", response.Status); throw new APIErrorException(500, "Service not healthy."); } return(HEALTHY_STATUS); }
/// <summary> /// Determines whether Elasticsearch cluster is ready. /// </summary> public async Task <Status> IsReadyAsync(CancellationToken cancellationToken) { var healthRequest = new ClusterHealthRequest { WaitForStatus = WaitForStatus.Green }; IClusterHealthResponse healthResponse = await _client .ClusterHealthAsync(healthRequest, cancellationToken); return(new Status { IsReady = healthResponse.IsValid, Message = healthResponse.DebugInformation }); }
public ActionResult Status() { IClusterHealthResponse res = null; int num = 0; string status = "unknown"; try { res = HlidacStatu.Lib.ES.Manager.GetESClient().ClusterHealth(); num = res?.NumberOfNodes ?? 0; status = res?.Status.ToString() ?? "unknown"; } catch (Exception e) { HlidacStatu.Util.Consts.Logger.Error("Status page error", e); ViewBag.Error = e; } return(Content(string.Format("{0}-{1}", num, status))); }
private static string BuildClusterHealthView(IClusterHealthResponse health) { StringBuilder stb = new StringBuilder(); stb.Append(@"<div>"); stb.Append(@"<style> .headerCell {width: 25%;} </style>"); stb.Append(@"<table class='full_width_table'>"); stb.Append(@"<tr><td class='tableheader' colspan=2>Cluster Health</td></tr>"); stb.Append($"<tr><td class='tablecell headerCell'>Cluster Name:</td><td class='tablecell' style='width: 100px'>{health.ClusterName}</td></tr>"); stb.Append($"<tr><td class='tablecell headerCell'>Status:</td><td class='tablecell' style='width: 100px color: {health.Status};'>{health.Status}</td></tr>"); stb.Append($"<tr><td class='tablecell headerCell'>Number of Nodes:</td><td class='tablecell' style='width: 100px'>{health.NumberOfNodes}</td></tr>"); stb.Append($"<tr><td class='tablecell headerCell'>Number of Data Nodes:</td><td class='tablecell' style='width: 100px'>{health.NumberOfDataNodes}</td></tr>"); stb.Append($"<tr><td class='tablecell headerCell'>Active Primary Shards:</td><td class='tablecell' style='width: 100px'>{health.ActivePrimaryShards}</td></tr>"); stb.Append($"<tr><td class='tablecell headerCell'>Active Shards:</td><td class='tablecell' style='width: 100px'>{health.ActiveShards}</td></tr>"); stb.Append($"<tr><td class='tablecell headerCell'>Number of Pending Tasks:</td><td class='tablecell' style='width: 100px'>{health.NumberOfPendingTasks}</td></tr>"); stb.Append(@" </table>"); stb.Append(@"</div>"); return(stb.ToString()); }
public IActionResult Index() { SearchRequest <Person> sr = new SearchRequest <Person> { Query = new MatchQuery { Field = "firstname", Query = "Hubert" } }; var searchResults = client.Search <Person>(sr); var searchResults2 = client.Search <Person>(s => s .Query(q => q.Match(m => m.Field("lastname") .Query("Dumas"))) ); var allPeople = client.Search <Person>(); var multiResults = client.Search <Person>(s => s .Query(q => q.MultiMatch(c => c .Fields(f => f.Field("lastname").Field("firstname")) .Query("Gaye") )) ); var multiResults2 = client.Search <Person>(s => s .Query(q => q.MultiMatch(c => c .Fields(f => f.Field(p => p.Firstname).Field(p => p.Lastname)) .Query("Dumas") )) ); IClusterHealthResponse res = client.ClusterHealth(); return(View(res)); }
/// <summary> /// Checks if a single host is healthy /// </summary> /// <returns>The host healthy.</returns> private async Task <bool> IsHostHealthy(string alias) { // Use the cluster health API to verify that the Best Bets index is functioning. // Maps to https://ncias-d1592-v.nci.nih.gov:9299/_cluster/health/bestbets?pretty (or other server) // // References: // https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html // https://github.com/elastic/elasticsearch/blob/master/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.health.json#L20 try { IClusterHealthResponse response = await _elasticClient.ClusterHealthAsync(hd => hd.Index(alias)); if (!response.IsValid) { _logger.LogError($"Error checking ElasticSearch health for {alias}."); _logger.LogError($"Returned debug info: {response.DebugInformation}."); } else { if (response.Status == "green" || response.Status == "yellow") { //This is the only condition that will return true return(true); } else { _logger.LogError($"Alias ${alias} status is not good"); } } } catch (Exception ex) { _logger.LogError($"Error checking ElasticSearch health for {alias}."); _logger.LogError($"Exception: {ex.Message}."); } return(false); }