/** * serialize all the MetricsTimeVaryingLong */ public void write(DataOutput out) throws IOException { out.writeByte(SCANMETRICS_VERSION); Collection<MetricsBase> mbs = registry.getMetricsList(); // we only handle MetricsTimeVaryingLong for now. int metricsCount = 0; for (MetricsBase mb : mbs) { if ( mb instanceof MetricsTimeVaryingLong) { metricsCount++; } else { throw new IOException("unsupported metrics type. metrics name: " + mb.getName() + ", metrics description: " + mb.getDescription()); } } out.writeInt(metricsCount); for (MetricsBase mb : mbs) { out.writeUTF(mb.getName()); out.writeLong(((MetricsTimeVaryingLong) mb).getCurrentIntervalValue()); } }
public void testDataNodeMetrics() throws Exception { Configuration conf = new HdfsConfiguration(); conf.setBoolean(SimulatedFSDataset.CONFIG_PROPERTY_SIMULATED, true); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build(); try { FileSystem fs = cluster.getFileSystem(); final long LONG_FILE_LEN = Integer.MAX_VALUE+1L; DFSTestUtil.createFile(fs, new Path("/tmp.txt"), LONG_FILE_LEN, (short)1, 1L); List<DataNode> datanodes = cluster.getDataNodes(); assertEquals(datanodes.size(), 1); DataNode datanode = datanodes.get(0); DataNodeMetrics metrics = datanode.getMetrics(); assertEquals(LONG_FILE_LEN, metrics.bytesWritten.getCurrentIntervalValue()); } finally { if (cluster != null) {cluster.shutdown();} } } }
private void updateCounters() throws IOException { // we can get access to counters only if hbase uses new mapreduce APIs if (this.getCounter == null) { return; } byte[] serializedMetrics = currentScan.getAttribute(Scan.SCAN_ATTRIBUTES_METRICS_DATA); if (serializedMetrics == null || serializedMetrics.length == 0) { return; } DataInputBuffer in = new DataInputBuffer(); in.reset(serializedMetrics, 0, serializedMetrics.length); ScanMetrics scanMetrics = new ScanMetrics(); scanMetrics.readFields(in); MetricsTimeVaryingLong[] mlvs = scanMetrics.getMetricsTimeVaryingLongArray(); try { for (MetricsTimeVaryingLong mlv : mlvs) { Counter ct = (Counter) this.getCounter.invoke(context, HBASE_COUNTER_GROUP_NAME, mlv.getName()); ct.increment(mlv.getCurrentIntervalValue()); } ((Counter) this.getCounter.invoke(context, HBASE_COUNTER_GROUP_NAME, "NUM_SCANNER_RESTARTS")) .increment(numRestarts); } catch (Exception e) { LOG.debug("can't update counter." + StringUtils.stringifyException(e)); } }
Counter ct = (Counter)this.getCounter.invoke(context, HBASE_COUNTER_GROUP_NAME, mlv.getName()); ct.increment(mlv.getCurrentIntervalValue());