使用SolrNet获取Solr状态

时间:2019-11-13 13:01:33

标签: solrcloud solrnet

在Solr实例上,我可以使用以下命令获取状态:bin / solr status 有没有办法使用SolrNet获取状态?有时我需要导入大量数据,并且如果堆大小> = 80%

,我想停止导入

查询示例以获取状态

http://my-solr.bigboss.com/solr/admin/collections?_=1573650195955&action=CLUSTERSTATUS&wt=json
http://my-solr.bigboss.com/solr/admin/info/system?_=1573650195955&nodes=10.0.1.138:8983_solr,10.0.1.232:8983_solr,10.0.5.244:8983_solr&wt=json

我现在正在使用httpClient,但是仍然对通过SolrNet可以做到这一点感兴趣

 private List<string> GetSolrNodes()
    {
        using (var httpClient = new HttpClient())
        {
            httpClient.Timeout = TimeSpan.FromSeconds(20);
            var url = _solrBaseUrl + "admin/collections?action=CLUSTERSTATUS&wt=json";
            var json = httpClient.GetStringAsync(url).Result;
            var obj = JObject.Parse(json);
            var liveNodes = (JArray)obj["cluster"]["live_nodes"];
            return liveNodes.HasValues ? liveNodes.Select(liveNode => liveNode.ToString()).ToList() : new List<string>();
        }
    }


private int GetSolrNodeWithMaxHeapSize()
    {
        var nodes = GetSolrNodes();

        using (var httpClient = new HttpClient())
        {
            httpClient.Timeout = TimeSpan.FromSeconds(20);
            var stringNodes = nodes.Join(",");
            var url = _solrBaseUrl + $"admin/info/system?nodes={stringNodes}&wt=json";
            var json = httpClient.GetStringAsync(url).Result;
            var obj = JObject.Parse(json);

            return nodes.Select(node => (int) obj[node]["jvm"]["memory"]["raw"]["used%"]).Concat(new[] {0}).Max();
        }
    }

0 个答案:

没有答案