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.demux.processor.mapper;
20
21
22 import java.io.IOException;
23 import java.text.ParseException;
24 import java.text.SimpleDateFormat;
25 import java.util.Calendar;
26 import java.util.Date;
27
28 import org.apache.hadoop.chukwa.datacollection.writer.hbase.Annotation.Table;
29 import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
30 import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecordKey;
31 import org.apache.hadoop.mapred.OutputCollector;
32 import org.apache.hadoop.mapred.Reporter;
33 import org.apache.log4j.Logger;
34
35 @Table(name="SystemMetrics",columnFamily="SysLog")
36 public class SysLog extends AbstractProcessor {
37
38 static Logger log = Logger.getLogger(SysLog.class);
39 private static final String reduceType = "SysLog";
40 private SimpleDateFormat sdf = null;
41
42 public SysLog() {
43 sdf = new SimpleDateFormat("MMM d HH:mm:ss");
44 }
45
46 @Override
47 protected void parse(String recordEntry,
48 OutputCollector<ChukwaRecordKey, ChukwaRecord> output, Reporter reporter)
49 throws Throwable {
50 try {
51 String dStr = recordEntry.substring(0, 15);
52 int start = 15;
53 int idx = recordEntry.indexOf(' ', start);
54 start = idx + 1;
55 idx = recordEntry.indexOf(' ', start);
56 String body = recordEntry.substring(idx + 1);
57 body = body.replaceAll("\n", "");
58
59 Calendar convertDate = Calendar.getInstance();
60 Date d = sdf.parse(dStr);
61 int year = convertDate.get(Calendar.YEAR);
62 convertDate.setTime(d);
63 convertDate.set(Calendar.YEAR, year);
64 if(convertDate.getTimeInMillis() > Calendar.getInstance().getTimeInMillis()) {
65 convertDate.set(Calendar.YEAR, year - 1);
66 }
67
68 ChukwaRecord record = new ChukwaRecord();
69 buildGenericRecord(record, recordEntry, convertDate.getTime().getTime(),
70 reduceType);
71 output.collect(key, record);
72 } catch (ParseException e) {
73 e.printStackTrace();
74 log.warn("Wrong format in SysLog [" + recordEntry + "]", e);
75 throw e;
76 } catch (IOException e) {
77 e.printStackTrace();
78 log.warn("Unable to collect output in SysLog [" + recordEntry + "]", e);
79 throw e;
80 }
81
82 }
83
84 public String getDataType() {
85 return SysLog.class.getName();
86 }
87
88 }