This project has retired. For details please refer to its
Attic page.
HadoopMetricsProcessor xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.chukwa.extraction.hbase;
20
21 import java.nio.charset.Charset;
22 import java.security.NoSuchAlgorithmException;
23 import java.util.Iterator;
24 import java.util.Map;
25 import java.util.Set;
26 import java.util.Map.Entry;
27
28 import org.apache.log4j.Logger;
29 import org.json.simple.JSONObject;
30 import org.json.simple.JSONValue;
31
32 public class HadoopMetricsProcessor extends AbstractProcessor {
33
34 static Logger LOG = Logger.getLogger(HadoopMetricsProcessor.class);
35 static final String timestampField = "timestamp";
36 static final String contextNameField = "contextName";
37 static final String recordNameField = "recordName";
38 static final String hostName = "Hostname";
39 static final String processName = "ProcessName";
40 static final byte[] cf = "t".getBytes(Charset.forName("UTF-8"));
41
42 public HadoopMetricsProcessor() throws NoSuchAlgorithmException {
43 }
44
45 @Override
46 protected void parse(byte[] recordEntry) throws Throwable {
47 String body = new String(recordEntry, Charset.forName("UTF-8"));
48 int start = body.indexOf('{');
49 JSONObject json = (JSONObject) JSONValue.parse(body.substring(start));
50
51 time = ((Long) json.get(timestampField)).longValue();
52 String contextName = (String) json.get(contextNameField);
53 String recordName = (String) json.get(recordNameField);
54 String src = ((String) json.get(hostName)).toLowerCase();
55 if(json.get(processName)!=null) {
56 src = new StringBuilder(src).append(":").append(json.get(processName)).toString();
57 }
58 for(Entry<String, Object> entry : (Set<Map.Entry>) json.entrySet()) {
59 String keyName = entry.getKey();
60 if (timestampField.intern() == keyName.intern()) {
61 continue;
62 } else if (contextNameField.intern() == keyName.intern()) {
63 continue;
64 } else if (recordNameField.intern() == keyName.intern()) {
65 continue;
66 } else if (hostName.intern() == keyName.intern()) {
67 continue;
68 } else if (processName.intern() == keyName.intern()) {
69 continue;
70 } else {
71 if(json.get(keyName)!=null) {
72 String v = entry.getValue().toString();
73 String primaryKey = new StringBuilder(contextName).append(".")
74 .append(recordName).append(".").append(keyName).toString();
75 addRecord(time, primaryKey, src, v.getBytes(Charset.forName("UTF-8")), output);
76 }
77 }
78 }
79 }
80
81 }