View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.regionserver;
19  
20  import java.io.IOException;
21  import java.util.Collection;
22  import java.util.List;
23  import java.util.concurrent.ScheduledExecutorService;
24  import java.util.concurrent.TimeUnit;
25  
26  import org.apache.commons.lang.StringUtils;
27  import org.apache.commons.logging.Log;
28  import org.apache.commons.logging.LogFactory;
29  import org.apache.hadoop.hbase.classification.InterfaceAudience;
30  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
31  import org.apache.hadoop.hbase.HConstants;
32  import org.apache.hadoop.hbase.HDFSBlocksDistribution;
33  import org.apache.hadoop.hbase.HRegionInfo;
34  import org.apache.hadoop.hbase.ServerName;
35  import org.apache.hadoop.hbase.io.hfile.BlockCache;
36  import org.apache.hadoop.hbase.io.hfile.CacheConfig;
37  import org.apache.hadoop.hbase.io.hfile.CacheStats;
38  import org.apache.hadoop.hbase.mob.MobCacheConfig;
39  import org.apache.hadoop.hbase.mob.MobFileCache;
40  import org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource;
41  import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
42  import org.apache.hadoop.hbase.util.FSUtils;
43  import org.apache.hadoop.hbase.wal.WALProvider;
44  import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
45  import org.apache.hadoop.hdfs.DFSHedgedReadMetrics;
46  import org.apache.hadoop.metrics2.MetricsExecutor;
47  
48  /**
49   * Impl for exposing HRegionServer Information through Hadoop's metrics 2 system.
50   */
51  @InterfaceAudience.Private
52  class MetricsRegionServerWrapperImpl
53      implements MetricsRegionServerWrapper {
54  
55    private static final Log LOG = LogFactory.getLog(MetricsRegionServerWrapperImpl.class);
56  
57    private final HRegionServer regionServer;
58    private final MetricsWALSource metricsWALSource;
59  
60    private BlockCache blockCache;
61    private MobFileCache mobFileCache;
62  
63    private volatile long numStores = 0;
64    private volatile long numWALFiles = 0;
65    private volatile long walFileSize = 0;
66    private volatile long numStoreFiles = 0;
67    private volatile long memstoreSize = 0;
68    private volatile long storeFileSize = 0;
69    private volatile long maxStoreFileAge = 0;
70    private volatile long minStoreFileAge = 0;
71    private volatile long avgStoreFileAge = 0;
72    private volatile long numReferenceFiles = 0;
73    private volatile double requestsPerSecond = 0.0;
74    private volatile long readRequestsCount = 0;
75    private volatile long filteredReadRequestsCount = 0;
76    private volatile long writeRequestsCount = 0;
77    private volatile long checkAndMutateChecksFailed = 0;
78    private volatile long checkAndMutateChecksPassed = 0;
79    private volatile long storefileIndexSize = 0;
80    private volatile long totalStaticIndexSize = 0;
81    private volatile long totalStaticBloomSize = 0;
82    private volatile long numMutationsWithoutWAL = 0;
83    private volatile long dataInMemoryWithoutWAL = 0;
84    private volatile double percentFileLocal = 0;
85    private volatile double percentFileLocalSecondaryRegions = 0;
86    private volatile long flushedCellsCount = 0;
87    private volatile long compactedCellsCount = 0;
88    private volatile long majorCompactedCellsCount = 0;
89    private volatile long flushedCellsSize = 0;
90    private volatile long compactedCellsSize = 0;
91    private volatile long majorCompactedCellsSize = 0;
92    private volatile long cellsCountCompactedToMob = 0;
93    private volatile long cellsCountCompactedFromMob = 0;
94    private volatile long cellsSizeCompactedToMob = 0;
95    private volatile long cellsSizeCompactedFromMob = 0;
96    private volatile long mobFlushCount = 0;
97    private volatile long mobFlushedCellsCount = 0;
98    private volatile long mobFlushedCellsSize = 0;
99    private volatile long mobScanCellsCount = 0;
100   private volatile long mobScanCellsSize = 0;
101   private volatile long mobFileCacheAccessCount = 0;
102   private volatile long mobFileCacheMissCount = 0;
103   private volatile double mobFileCacheHitRatio = 0;
104   private volatile long mobFileCacheEvictedCount = 0;
105   private volatile long mobFileCacheCount = 0;
106   private volatile long blockedRequestsCount = 0L;
107   private volatile long averageRegionSize = 0L;
108 
109   private CacheStats cacheStats;
110   private ScheduledExecutorService executor;
111   private Runnable runnable;
112   private long period;
113 
114   /**
115    * Can be null if not on hdfs.
116    */
117   private DFSHedgedReadMetrics dfsHedgedReadMetrics;
118 
119   public MetricsRegionServerWrapperImpl(final HRegionServer regionServer) {
120     this.regionServer = regionServer;
121     initBlockCache();
122     initMobFileCache();
123 
124     this.period =
125         regionServer.conf.getLong(HConstants.REGIONSERVER_METRICS_PERIOD,
126           HConstants.DEFAULT_REGIONSERVER_METRICS_PERIOD);
127 
128     this.executor = CompatibilitySingletonFactory.getInstance(MetricsExecutor.class).getExecutor();
129     this.runnable = new RegionServerMetricsWrapperRunnable();
130     this.executor.scheduleWithFixedDelay(this.runnable, this.period, this.period,
131       TimeUnit.MILLISECONDS);
132     this.metricsWALSource = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
133 
134     try {
135       this.dfsHedgedReadMetrics = FSUtils.getDFSHedgedReadMetrics(regionServer.getConfiguration());
136     } catch (IOException e) {
137       LOG.warn("Failed to get hedged metrics", e);
138     }
139     if (LOG.isInfoEnabled()) {
140       LOG.info("Computing regionserver metrics every " + this.period + " milliseconds");
141     }
142   }
143 
144   /**
145    * It's possible that due to threading the block cache could not be initialized
146    * yet (testing multiple region servers in one jvm).  So we need to try and initialize
147    * the blockCache and cacheStats reference multiple times until we succeed.
148    */
149   private synchronized  void initBlockCache() {
150     CacheConfig cacheConfig = this.regionServer.cacheConfig;
151     if (cacheConfig != null && this.blockCache == null) {
152       this.blockCache = cacheConfig.getBlockCache();
153     }
154 
155     if (this.blockCache != null && this.cacheStats == null) {
156       this.cacheStats = blockCache.getStats();
157     }
158   }
159 
160   /**
161    * Initializes the mob file cache.
162    */
163   private synchronized void initMobFileCache() {
164     MobCacheConfig mobCacheConfig = this.regionServer.mobCacheConfig;
165     if (mobCacheConfig != null && this.mobFileCache == null) {
166       this.mobFileCache = mobCacheConfig.getMobFileCache();
167     }
168   }
169 
170   @Override
171   public String getClusterId() {
172     return regionServer.getClusterId();
173   }
174 
175   @Override
176   public long getStartCode() {
177     return regionServer.getStartcode();
178   }
179 
180   @Override
181   public String getZookeeperQuorum() {
182     ZooKeeperWatcher zk = regionServer.getZooKeeper();
183     if (zk == null) {
184       return "";
185     }
186     return zk.getQuorum();
187   }
188 
189   @Override
190   public String getCoprocessors() {
191     String[] coprocessors = regionServer.getRegionServerCoprocessors();
192     if (coprocessors == null || coprocessors.length == 0) {
193       return "";
194     }
195     return StringUtils.join(coprocessors, ", ");
196   }
197 
198   @Override
199   public String getServerName() {
200     ServerName serverName = regionServer.getServerName();
201     if (serverName == null) {
202       return "";
203     }
204     return serverName.getServerName();
205   }
206 
207   @Override
208   public long getNumOnlineRegions() {
209     Collection<Region> onlineRegionsLocalContext = regionServer.getOnlineRegionsLocalContext();
210     if (onlineRegionsLocalContext == null) {
211       return 0;
212     }
213     return onlineRegionsLocalContext.size();
214   }
215 
216   @Override
217   public long getTotalRequestCount() {
218     return regionServer.rpcServices.requestCount.get();
219   }
220 
221   @Override
222   public int getSplitQueueSize() {
223     if (this.regionServer.compactSplitThread == null) {
224       return 0;
225     }
226     return this.regionServer.compactSplitThread.getSplitQueueSize();
227   }
228 
229   @Override
230   public int getCompactionQueueSize() {
231     //The thread could be zero.  if so assume there is no queue.
232     if (this.regionServer.compactSplitThread == null) {
233       return 0;
234     }
235     return this.regionServer.compactSplitThread.getCompactionQueueSize();
236   }
237 
238   @Override
239   public int getSmallCompactionQueueSize() {
240     //The thread could be zero.  if so assume there is no queue.
241     if (this.regionServer.compactSplitThread == null) {
242       return 0;
243     }
244     return this.regionServer.compactSplitThread.getSmallCompactionQueueSize();
245   }
246 
247   @Override
248   public int getLargeCompactionQueueSize() {
249     //The thread could be zero.  if so assume there is no queue.
250     if (this.regionServer.compactSplitThread == null) {
251       return 0;
252     }
253     return this.regionServer.compactSplitThread.getLargeCompactionQueueSize();
254   }
255 
256   @Override
257   public int getFlushQueueSize() {
258     //If there is no flusher there should be no queue.
259     if (this.regionServer.cacheFlusher == null) {
260       return 0;
261     }
262     return this.regionServer.cacheFlusher.getFlushQueueSize();
263   }
264 
265   @Override
266   public long getBlockCacheCount() {
267     if (this.blockCache == null) {
268       return 0;
269     }
270     return this.blockCache.getBlockCount();
271   }
272 
273   @Override
274   public long getBlockCacheSize() {
275     if (this.blockCache == null) {
276       return 0;
277     }
278     return this.blockCache.getCurrentSize();
279   }
280 
281   @Override
282   public long getBlockCacheFreeSize() {
283     if (this.blockCache == null) {
284       return 0;
285     }
286     return this.blockCache.getFreeSize();
287   }
288 
289   @Override
290   public long getBlockCacheHitCount() {
291     if (this.cacheStats == null) {
292       return 0;
293     }
294     return this.cacheStats.getHitCount();
295   }
296 
297   @Override
298   public long getBlockCachePrimaryHitCount() {
299     if (this.cacheStats == null) {
300       return 0;
301     }
302     return this.cacheStats.getPrimaryHitCount();
303   }
304 
305   @Override
306   public long getBlockCacheMissCount() {
307     if (this.cacheStats == null) {
308       return 0;
309     }
310     return this.cacheStats.getMissCount();
311   }
312 
313   @Override
314   public long getBlockCachePrimaryMissCount() {
315     if (this.cacheStats == null) {
316       return 0;
317     }
318     return this.cacheStats.getPrimaryMissCount();
319   }
320 
321   @Override
322   public long getBlockCacheEvictedCount() {
323     if (this.cacheStats == null) {
324       return 0;
325     }
326     return this.cacheStats.getEvictedCount();
327   }
328 
329   @Override
330   public long getBlockCachePrimaryEvictedCount() {
331     if (this.cacheStats == null) {
332       return 0;
333     }
334     return this.cacheStats.getPrimaryEvictedCount();
335   }
336 
337   @Override
338   public double getBlockCacheHitPercent() {
339     if (this.cacheStats == null) {
340       return 0;
341     }
342     double ratio = this.cacheStats.getHitRatio();
343     if (Double.isNaN(ratio)) {
344       ratio = 0;
345     }
346     return (ratio * 100);
347   }
348 
349   @Override
350   public double getBlockCacheHitCachingPercent() {
351     if (this.cacheStats == null) {
352       return 0;
353     }
354 
355     double ratio = this.cacheStats.getHitCachingRatio();
356 
357     if (Double.isNaN(ratio)) {
358       ratio = 0;
359     }
360     return (ratio * 100);
361   }
362 
363   @Override
364   public long getBlockCacheFailedInsertions() {
365     return this.cacheStats.getFailedInserts();
366   }
367 
368   @Override public void forceRecompute() {
369     this.runnable.run();
370   }
371 
372   @Override
373   public long getNumStores() {
374     return numStores;
375   }
376   
377   @Override
378   public long getNumWALFiles() {
379     return numWALFiles;
380   }
381 
382   @Override
383   public long getWALFileSize() {
384     return walFileSize;
385   }
386 
387   @Override
388   public long getNumWALSlowAppend() {
389     return metricsWALSource.getSlowAppendCount();
390   }
391   
392   @Override
393   public long getNumStoreFiles() {
394     return numStoreFiles;
395   }
396 
397   @Override
398   public long getMaxStoreFileAge() {
399     return maxStoreFileAge;
400   }
401 
402   @Override
403   public long getMinStoreFileAge() {
404     return minStoreFileAge;
405   }
406 
407   @Override
408   public long getAvgStoreFileAge() {
409     return avgStoreFileAge;
410   }
411 
412   @Override
413   public long getNumReferenceFiles() {
414     return numReferenceFiles;
415   }
416 
417   @Override
418   public long getMemstoreSize() {
419     return memstoreSize;
420   }
421 
422   @Override
423   public long getStoreFileSize() {
424     return storeFileSize;
425   }
426 
427   @Override public double getRequestsPerSecond() {
428     return requestsPerSecond;
429   }
430 
431   @Override
432   public long getReadRequestsCount() {
433     return readRequestsCount;
434   }
435 
436   @Override
437   public long getFilteredReadRequestsCount() {
438     return filteredReadRequestsCount;
439   }
440 
441   @Override
442   public long getWriteRequestsCount() {
443     return writeRequestsCount;
444   }
445 
446   @Override
447   public long getRpcGetRequestsCount() {
448     return regionServer.rpcServices.rpcGetRequestCount.get();
449   }
450 
451   @Override
452   public long getRpcScanRequestsCount() {
453     return regionServer.rpcServices.rpcScanRequestCount.get();
454   }
455 
456   @Override
457   public long getRpcMultiRequestsCount() {
458     return regionServer.rpcServices.rpcMultiRequestCount.get();
459   }
460 
461   @Override
462   public long getRpcMutateRequestsCount() {
463     return regionServer.rpcServices.rpcMutateRequestCount.get();
464   }
465 
466   @Override
467   public long getCheckAndMutateChecksFailed() {
468     return checkAndMutateChecksFailed;
469   }
470 
471   @Override
472   public long getCheckAndMutateChecksPassed() {
473     return checkAndMutateChecksPassed;
474   }
475 
476   @Override
477   public long getStoreFileIndexSize() {
478     return storefileIndexSize;
479   }
480 
481   @Override
482   public long getTotalStaticIndexSize() {
483     return totalStaticIndexSize;
484   }
485 
486   @Override
487   public long getTotalStaticBloomSize() {
488     return totalStaticBloomSize;
489   }
490 
491   @Override
492   public long getNumMutationsWithoutWAL() {
493     return numMutationsWithoutWAL;
494   }
495 
496   @Override
497   public long getDataInMemoryWithoutWAL() {
498     return dataInMemoryWithoutWAL;
499   }
500 
501   @Override
502   public double getPercentFileLocal() {
503     return percentFileLocal;
504   }
505 
506   @Override
507   public double getPercentFileLocalSecondaryRegions() {
508     return percentFileLocalSecondaryRegions;
509   }
510 
511   @Override
512   public long getUpdatesBlockedTime() {
513     if (this.regionServer.cacheFlusher == null) {
514       return 0;
515     }
516     return this.regionServer.cacheFlusher.getUpdatesBlockedMsHighWater().get();
517   }
518 
519   @Override
520   public long getFlushedCellsCount() {
521     return flushedCellsCount;
522   }
523 
524   @Override
525   public long getCompactedCellsCount() {
526     return compactedCellsCount;
527   }
528 
529   @Override
530   public long getMajorCompactedCellsCount() {
531     return majorCompactedCellsCount;
532   }
533 
534   @Override
535   public long getFlushedCellsSize() {
536     return flushedCellsSize;
537   }
538 
539   @Override
540   public long getCompactedCellsSize() {
541     return compactedCellsSize;
542   }
543 
544   @Override
545   public long getMajorCompactedCellsSize() {
546     return majorCompactedCellsSize;
547   }
548 
549   @Override
550   public long getCellsCountCompactedFromMob() {
551     return cellsCountCompactedFromMob;
552   }
553 
554   @Override
555   public long getCellsCountCompactedToMob() {
556     return cellsCountCompactedToMob;
557   }
558 
559   @Override
560   public long getCellsSizeCompactedFromMob() {
561     return cellsSizeCompactedFromMob;
562   }
563 
564   @Override
565   public long getCellsSizeCompactedToMob() {
566     return cellsSizeCompactedToMob;
567   }
568 
569   @Override
570   public long getMobFlushCount() {
571     return mobFlushCount;
572   }
573 
574   @Override
575   public long getMobFlushedCellsCount() {
576     return mobFlushedCellsCount;
577   }
578 
579   @Override
580   public long getMobFlushedCellsSize() {
581     return mobFlushedCellsSize;
582   }
583 
584   @Override
585   public long getMobScanCellsCount() {
586     return mobScanCellsCount;
587   }
588 
589   @Override
590   public long getMobScanCellsSize() {
591     return mobScanCellsSize;
592   }
593 
594   @Override
595   public long getMobFileCacheAccessCount() {
596     return mobFileCacheAccessCount;
597   }
598 
599   @Override
600   public long getMobFileCacheMissCount() {
601     return mobFileCacheMissCount;
602   }
603 
604   @Override
605   public long getMobFileCacheCount() {
606     return mobFileCacheCount;
607   }
608 
609   @Override
610   public long getMobFileCacheEvictedCount() {
611     return mobFileCacheEvictedCount;
612   }
613 
614   @Override
615   public double getMobFileCacheHitPercent() {
616     return mobFileCacheHitRatio * 100;
617   }
618 
619   /**
620    * This is the runnable that will be executed on the executor every PERIOD number of seconds
621    * It will take metrics/numbers from all of the regions and use them to compute point in
622    * time metrics.
623    */
624   public class RegionServerMetricsWrapperRunnable implements Runnable {
625 
626     private long lastRan = 0;
627     private long lastRequestCount = 0;
628 
629     @Override
630     synchronized public void run() {
631       try {
632         initBlockCache();
633         initMobFileCache();
634         cacheStats = blockCache.getStats();
635 
636         HDFSBlocksDistribution hdfsBlocksDistribution =
637             new HDFSBlocksDistribution();
638         HDFSBlocksDistribution hdfsBlocksDistributionSecondaryRegions =
639             new HDFSBlocksDistribution();
640 
641         long tempNumStores = 0, tempNumStoreFiles = 0, tempMemstoreSize = 0, tempStoreFileSize = 0;
642         long tempMaxStoreFileAge = 0, tempNumReferenceFiles = 0;
643         long avgAgeNumerator = 0, numHFiles = 0;
644         long tempMinStoreFileAge = Long.MAX_VALUE;
645         long tempReadRequestsCount = 0, tempFilteredReadRequestsCount = 0,
646           tempWriteRequestsCount = 0;
647         long tempCheckAndMutateChecksFailed = 0;
648         long tempCheckAndMutateChecksPassed = 0;
649         long tempStorefileIndexSize = 0;
650         long tempTotalStaticIndexSize = 0;
651         long tempTotalStaticBloomSize = 0;
652         long tempNumMutationsWithoutWAL = 0;
653         long tempDataInMemoryWithoutWAL = 0;
654         double tempPercentFileLocal = 0;
655         double tempPercentFileLocalSecondaryRegions = 0;
656         long tempFlushedCellsCount = 0;
657         long tempCompactedCellsCount = 0;
658         long tempMajorCompactedCellsCount = 0;
659         long tempFlushedCellsSize = 0;
660         long tempCompactedCellsSize = 0;
661         long tempMajorCompactedCellsSize = 0;
662         long tempCellsCountCompactedToMob = 0;
663         long tempCellsCountCompactedFromMob = 0;
664         long tempCellsSizeCompactedToMob = 0;
665         long tempCellsSizeCompactedFromMob = 0;
666         long tempMobFlushCount = 0;
667         long tempMobFlushedCellsCount = 0;
668         long tempMobFlushedCellsSize = 0;
669         long tempMobScanCellsCount = 0;
670         long tempMobScanCellsSize = 0;
671         long tempBlockedRequestsCount = 0;
672         int regionCount = 0;
673         for (Region r : regionServer.getOnlineRegionsLocalContext()) {
674           tempNumMutationsWithoutWAL += r.getNumMutationsWithoutWAL();
675           tempDataInMemoryWithoutWAL += r.getDataInMemoryWithoutWAL();
676           tempReadRequestsCount += r.getReadRequestsCount();
677           tempFilteredReadRequestsCount += r.getFilteredReadRequestsCount();
678           tempWriteRequestsCount += r.getWriteRequestsCount();
679           tempCheckAndMutateChecksFailed += r.getCheckAndMutateChecksFailed();
680           tempCheckAndMutateChecksPassed += r.getCheckAndMutateChecksPassed();
681           tempBlockedRequestsCount += r.getBlockedRequestsCount();
682           List<Store> storeList = r.getStores();
683           tempNumStores += storeList.size();
684           for (Store store : storeList) {
685             tempNumStoreFiles += store.getStorefilesCount();
686             tempMemstoreSize += store.getMemStoreSize();
687             tempStoreFileSize += store.getStorefilesSize();
688 
689             long storeMaxStoreFileAge = store.getMaxStoreFileAge();
690             tempMaxStoreFileAge = (storeMaxStoreFileAge > tempMaxStoreFileAge) ?
691               storeMaxStoreFileAge : tempMaxStoreFileAge;
692 
693             long storeMinStoreFileAge = store.getMinStoreFileAge();
694             tempMinStoreFileAge = (storeMinStoreFileAge < tempMinStoreFileAge) ?
695               storeMinStoreFileAge : tempMinStoreFileAge;
696 
697             long storeHFiles = store.getNumHFiles();
698             avgAgeNumerator += store.getAvgStoreFileAge() * storeHFiles;
699             numHFiles += storeHFiles;
700             tempNumReferenceFiles += store.getNumReferenceFiles();
701 
702             tempStorefileIndexSize += store.getStorefilesIndexSize();
703             tempTotalStaticBloomSize += store.getTotalStaticBloomSize();
704             tempTotalStaticIndexSize += store.getTotalStaticIndexSize();
705             tempFlushedCellsCount += store.getFlushedCellsCount();
706             tempCompactedCellsCount += store.getCompactedCellsCount();
707             tempMajorCompactedCellsCount += store.getMajorCompactedCellsCount();
708             tempFlushedCellsSize += store.getFlushedCellsSize();
709             tempCompactedCellsSize += store.getCompactedCellsSize();
710             tempMajorCompactedCellsSize += store.getMajorCompactedCellsSize();
711             if (store instanceof HMobStore) {
712               HMobStore mobStore = (HMobStore) store;
713               tempCellsCountCompactedToMob += mobStore.getCellsCountCompactedToMob();
714               tempCellsCountCompactedFromMob += mobStore.getCellsCountCompactedFromMob();
715               tempCellsSizeCompactedToMob += mobStore.getCellsSizeCompactedToMob();
716               tempCellsSizeCompactedFromMob += mobStore.getCellsSizeCompactedFromMob();
717               tempMobFlushCount += mobStore.getMobFlushCount();
718               tempMobFlushedCellsCount += mobStore.getMobFlushedCellsCount();
719               tempMobFlushedCellsSize += mobStore.getMobFlushedCellsSize();
720               tempMobScanCellsCount += mobStore.getMobScanCellsCount();
721               tempMobScanCellsSize += mobStore.getMobScanCellsSize();
722             }
723           }
724 
725           HDFSBlocksDistribution distro = r.getHDFSBlocksDistribution();
726           hdfsBlocksDistribution.add(distro);
727           if (r.getRegionInfo().getReplicaId() != HRegionInfo.DEFAULT_REPLICA_ID) {
728             hdfsBlocksDistributionSecondaryRegions.add(distro);
729           }
730           regionCount++;
731         }
732         float localityIndex = hdfsBlocksDistribution.getBlockLocalityIndex(
733             regionServer.getServerName().getHostname());
734         tempPercentFileLocal = Double.isNaN(tempBlockedRequestsCount) ? 0 : (localityIndex * 100);
735 
736         float localityIndexSecondaryRegions = hdfsBlocksDistributionSecondaryRegions
737             .getBlockLocalityIndex(regionServer.getServerName().getHostname());
738         tempPercentFileLocalSecondaryRegions = Double.
739             isNaN(localityIndexSecondaryRegions) ? 0 : (localityIndexSecondaryRegions * 100);
740 
741         // Compute the number of requests per second
742         long currentTime = EnvironmentEdgeManager.currentTime();
743 
744         // assume that it took PERIOD seconds to start the executor.
745         // this is a guess but it's a pretty good one.
746         if (lastRan == 0) {
747           lastRan = currentTime - period;
748         }
749         // If we've time traveled keep the last requests per second.
750         if ((currentTime - lastRan) > 0) {
751           long currentRequestCount = getTotalRequestCount();
752           requestsPerSecond = (currentRequestCount - lastRequestCount) /
753               ((currentTime - lastRan) / 1000.0);
754           lastRequestCount = currentRequestCount;
755         }
756         lastRan = currentTime;
757 
758         WALProvider provider = regionServer.walFactory.getWALProvider();
759         WALProvider metaProvider = regionServer.walFactory.getMetaWALProvider();
760         numWALFiles = (provider == null ? 0 : provider.getNumLogFiles()) +
761             (metaProvider == null ? 0 : metaProvider.getNumLogFiles());
762         walFileSize = (provider == null ? 0 : provider.getLogFileSize()) +
763             (provider == null ? 0 : provider.getLogFileSize());
764         // Copy over computed values so that no thread sees half computed values.
765         numStores = tempNumStores;
766         numStoreFiles = tempNumStoreFiles;
767         memstoreSize = tempMemstoreSize;
768         storeFileSize = tempStoreFileSize;
769         maxStoreFileAge = tempMaxStoreFileAge;
770         if (regionCount > 0) {
771           averageRegionSize = (memstoreSize + storeFileSize) / regionCount;
772         }
773         if (tempMinStoreFileAge != Long.MAX_VALUE) {
774           minStoreFileAge = tempMinStoreFileAge;
775         }
776 
777         if (numHFiles != 0) {
778           avgStoreFileAge = avgAgeNumerator / numHFiles;
779         }
780 
781         numReferenceFiles= tempNumReferenceFiles;
782         readRequestsCount = tempReadRequestsCount;
783         filteredReadRequestsCount = tempFilteredReadRequestsCount;
784         writeRequestsCount = tempWriteRequestsCount;
785         checkAndMutateChecksFailed = tempCheckAndMutateChecksFailed;
786         checkAndMutateChecksPassed = tempCheckAndMutateChecksPassed;
787         storefileIndexSize = tempStorefileIndexSize;
788         totalStaticIndexSize = tempTotalStaticIndexSize;
789         totalStaticBloomSize = tempTotalStaticBloomSize;
790         numMutationsWithoutWAL = tempNumMutationsWithoutWAL;
791         dataInMemoryWithoutWAL = tempDataInMemoryWithoutWAL;
792         percentFileLocal = tempPercentFileLocal;
793         percentFileLocalSecondaryRegions = tempPercentFileLocalSecondaryRegions;
794         flushedCellsCount = tempFlushedCellsCount;
795         compactedCellsCount = tempCompactedCellsCount;
796         majorCompactedCellsCount = tempMajorCompactedCellsCount;
797         flushedCellsSize = tempFlushedCellsSize;
798         compactedCellsSize = tempCompactedCellsSize;
799         majorCompactedCellsSize = tempMajorCompactedCellsSize;
800         cellsCountCompactedToMob = tempCellsCountCompactedToMob;
801         cellsCountCompactedFromMob = tempCellsCountCompactedFromMob;
802         cellsSizeCompactedToMob = tempCellsSizeCompactedToMob;
803         cellsSizeCompactedFromMob = tempCellsSizeCompactedFromMob;
804         mobFlushCount = tempMobFlushCount;
805         mobFlushedCellsCount = tempMobFlushedCellsCount;
806         mobFlushedCellsSize = tempMobFlushedCellsSize;
807         mobScanCellsCount = tempMobScanCellsCount;
808         mobScanCellsSize = tempMobScanCellsSize;
809         mobFileCacheAccessCount = mobFileCache.getAccessCount();
810         mobFileCacheMissCount = mobFileCache.getMissCount();
811         mobFileCacheHitRatio = Double.
812             isNaN(mobFileCache.getHitRatio())?0:mobFileCache.getHitRatio();
813         mobFileCacheEvictedCount = mobFileCache.getEvictedFileCount();
814         mobFileCacheCount = mobFileCache.getCacheSize();
815         blockedRequestsCount = tempBlockedRequestsCount;
816       } catch (Throwable e) {
817         LOG.warn("Caught exception! Will suppress and retry.", e);
818       }
819     }
820   }
821 
822   @Override
823   public long getHedgedReadOps() {
824     return this.dfsHedgedReadMetrics == null? 0: this.dfsHedgedReadMetrics.getHedgedReadOps();
825   }
826 
827   @Override
828   public long getHedgedReadWins() {
829     return this.dfsHedgedReadMetrics == null? 0: this.dfsHedgedReadMetrics.getHedgedReadWins();
830   }
831 
832   @Override
833   public long getBlockedRequestsCount() {
834     return blockedRequestsCount;
835   }
836 
837   @Override
838   public long getAverageRegionSize() {
839     return averageRegionSize;
840   }
841 
842   public long getDataMissCount() {
843     if (this.cacheStats == null) {
844       return 0;
845     }
846     return cacheStats.getDataMissCount();
847   }
848 
849   @Override
850   public long getLeafIndexMissCount() {
851     if (this.cacheStats == null) {
852       return 0;
853     }
854     return cacheStats.getLeafIndexMissCount();
855   }
856 
857   @Override
858   public long getBloomChunkMissCount() {
859     if (this.cacheStats == null) {
860       return 0;
861     }
862     return cacheStats.getBloomChunkMissCount();
863   }
864 
865   @Override
866   public long getMetaMissCount() {
867     if (this.cacheStats == null) {
868       return 0;
869     }
870     return cacheStats.getMetaMissCount();
871   }
872 
873   @Override
874   public long getRootIndexMissCount() {
875     if (this.cacheStats == null) {
876       return 0;
877     }
878     return cacheStats.getRootIndexMissCount();
879   }
880 
881   @Override
882   public long getIntermediateIndexMissCount() {
883     if (this.cacheStats == null) {
884       return 0;
885     }
886     return cacheStats.getIntermediateIndexMissCount();
887   }
888 
889   @Override
890   public long getFileInfoMissCount() {
891     if (this.cacheStats == null) {
892       return 0;
893     }
894     return cacheStats.getFileInfoMissCount();
895   }
896 
897   @Override
898   public long getGeneralBloomMetaMissCount() {
899     if (this.cacheStats == null) {
900       return 0;
901     }
902     return cacheStats.getGeneralBloomMetaMissCount();
903   }
904 
905   @Override
906   public long getDeleteFamilyBloomMissCount() {
907     if (this.cacheStats == null) {
908       return 0;
909     }
910     return cacheStats.getDeleteFamilyBloomMissCount();
911   }
912 
913   @Override
914   public long getTrailerMissCount() {
915     if (this.cacheStats == null) {
916       return 0;
917     }
918     return cacheStats.getTrailerMissCount();
919   }
920 
921   @Override
922   public long getDataHitCount() {
923     if (this.cacheStats == null) {
924       return 0;
925     }
926     return cacheStats.getDataHitCount();
927   }
928 
929   @Override
930   public long getLeafIndexHitCount() {
931     if (this.cacheStats == null) {
932       return 0;
933     }
934     return cacheStats.getLeafIndexHitCount();
935   }
936 
937   @Override
938   public long getBloomChunkHitCount() {
939     if (this.cacheStats == null) {
940       return 0;
941     }
942     return cacheStats.getBloomChunkHitCount();
943   }
944 
945   @Override
946   public long getMetaHitCount() {
947     if (this.cacheStats == null) {
948       return 0;
949     }
950     return cacheStats.getMetaHitCount();
951   }
952 
953   @Override
954   public long getRootIndexHitCount() {
955     if (this.cacheStats == null) {
956       return 0;
957     }
958     return cacheStats.getRootIndexHitCount();
959   }
960 
961   @Override
962   public long getIntermediateIndexHitCount() {
963     if (this.cacheStats == null) {
964       return 0;
965     }
966     return cacheStats.getIntermediateIndexHitCount();
967   }
968 
969   @Override
970   public long getFileInfoHitCount() {
971     if (this.cacheStats == null) {
972       return 0;
973     }
974     return cacheStats.getFileInfoHitCount();
975   }
976 
977   @Override
978   public long getGeneralBloomMetaHitCount() {
979     if (this.cacheStats == null) {
980       return 0;
981     }
982     return cacheStats.getGeneralBloomMetaHitCount();
983   }
984 
985   @Override
986   public long getDeleteFamilyBloomHitCount() {
987     if (this.cacheStats == null) {
988       return 0;
989     }
990     return cacheStats.getDeleteFamilyBloomHitCount();
991   }
992 
993   @Override
994   public long getTrailerHitCount() {
995     if (this.cacheStats == null) {
996       return 0;
997     }
998     return cacheStats.getTrailerHitCount();
999   }
1000 }