private void sendNodeThreadPoolStats(ThreadPoolStats threadPoolStats) { String prefix = this.getPrefix("thread_pool"); Iterator<ThreadPoolStats.Stats> statsIterator = threadPoolStats.iterator(); while (statsIterator.hasNext()) { ThreadPoolStats.Stats stats = statsIterator.next(); String threadPoolType = prefix + "." + stats.getName(); this.sendGauge(threadPoolType, "threads", stats.getThreads()); this.sendGauge(threadPoolType, "queue", stats.getQueue()); this.sendGauge(threadPoolType, "active", stats.getActive()); this.sendGauge(threadPoolType, "rejected", stats.getRejected()); this.sendGauge(threadPoolType, "largest", stats.getLargest()); this.sendGauge(threadPoolType, "completed", stats.getCompleted()); } }
@Override public void execute() throws Exception { // If Elasticsearch is started then only start the monitoring if (!ElasticsearchProcessMonitor.isElasticsearchRunning()) { String exceptionMsg = "Elasticsearch is not yet started, check back again later"; logger.info(exceptionMsg); return; } ThreadPoolStatsBean tpStatsBean = new ThreadPoolStatsBean(); try { NodesStatsResponse ndsStatsResponse = ESTransportClient.getNodesStatsResponse(config); ThreadPoolStats tpstats = null; NodeStats ndStat = null; if (ndsStatsResponse.getNodes().length > 0) { ndStat = ndsStatsResponse.getAt(0); } if (ndStat == null) { logger.info("NodeStats is null,hence returning (No ThreadPoolStats)."); return; } tpstats = ndStat.getThreadPool(); if (tpstats == null) { logger.info("ThreadPoolStats is null,hence returning (No ThreadPoolStats)."); return; } Iterator<ThreadPoolStats.Stats> iter = tpstats.iterator(); while (iter.hasNext()) { ThreadPoolStats.Stats stat = iter.next(); if (stat.getName().equals("index")) { tpStatsBean.indexThreads = stat.getThreads(); tpStatsBean.indexQueue = stat.getQueue(); tpStatsBean.indexActive = stat.getActive(); tpStatsBean.indexRejected = stat.getRejected(); tpStatsBean.indexLargest = stat.getLargest(); tpStatsBean.indexCompleted = stat.getCompleted(); } else if (stat.getName().equals("get")) { tpStatsBean.getThreads = stat.getThreads(); tpStatsBean.getQueue = stat.getQueue(); tpStatsBean.getActive = stat.getActive(); tpStatsBean.getRejected = stat.getRejected(); tpStatsBean.getLargest = stat.getLargest(); tpStatsBean.getCompleted = stat.getCompleted(); } else if (stat.getName().equals("search")) { tpStatsBean.searchThreads = stat.getThreads(); tpStatsBean.searchQueue = stat.getQueue(); tpStatsBean.searchActive = stat.getActive(); tpStatsBean.searchRejected = stat.getRejected(); tpStatsBean.searchLargest = stat.getLargest(); tpStatsBean.searchCompleted = stat.getCompleted(); } else if (stat.getName().equals("bulk")) { tpStatsBean.bulkThreads = stat.getThreads(); tpStatsBean.bulkQueue = stat.getQueue(); tpStatsBean.bulkActive = stat.getActive(); tpStatsBean.bulkRejected = stat.getRejected(); tpStatsBean.bulkLargest = stat.getLargest(); tpStatsBean.bulkCompleted = stat.getCompleted(); } } } catch (Exception e) { logger.warn("failed to load Thread Pool stats data", e); } tpStatsReporter.threadPoolBean.set(tpStatsBean); }