├── .gitignore
├── flume-logging-monitor-handler
├── src
│ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── shawn
│ │ │ ├── logging
│ │ │ └── monitor
│ │ │ │ └── handler
│ │ │ │ ├── EventSendingTestScript.java
│ │ │ │ ├── LogWatchRunScript.java
│ │ │ │ ├── EventSendingTest.java
│ │ │ │ ├── JsonFormatMapConfigHelper.java
│ │ │ │ ├── LogAttribute.java
│ │ │ │ ├── LogMonitorClient.java
│ │ │ │ ├── LogWatcher.java
│ │ │ │ ├── LogWatcherBySchedule.java
│ │ │ │ └── LogWatcherByWatchEvent.java
│ │ │ └── App.java
│ │ └── resources
│ │ ├── applicationContext.xml
│ │ └── configuration.properties
└── pom.xml
├── flume-logging-monitor-client
├── src
│ └── main
│ │ ├── conf
│ │ ├── applicationContext.xml
│ │ ├── configuration.properties
│ │ ├── logHeader.json.example
│ │ └── developer-guide.md
│ │ ├── assembly
│ │ └── bin.xml
│ │ └── bin
│ │ └── monitor
└── pom.xml
├── README.md
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # kdiff3 ignore
2 | *.orig
3 |
4 | # maven ignore
5 | target/
6 |
7 | # eclipse ignore
8 | .settings/
9 | .project
10 | .classpath
11 |
12 | # idea ignore
13 | .idea/
14 | *.ipr
15 | *.iml
16 | *.iws
17 |
18 | # temp ignore
19 | *.log
20 | *.cache
21 | *.diff
22 | *.patch
23 | *.tmp
24 |
25 | # system ignore
26 | .DS_Store
27 | Thumbs.db
28 |
29 | # configuration ignore
30 | *.json
31 | log4j.properties
32 | # package ignore (optional)
33 | # *.jar
34 | # *.war
35 | # *.zip
36 | # *.tar
37 | # *.tar.gz
38 |
--------------------------------------------------------------------------------
/flume-logging-monitor-handler/src/main/java/com/shawn/logging/monitor/handler/EventSendingTestScript.java:
--------------------------------------------------------------------------------
1 | package com.shawn.logging.monitor.handler;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.support.ClassPathXmlApplicationContext;
5 |
6 | public class EventSendingTestScript {
7 | public static void main(String[] args) throws Exception{
8 | ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
9 | LogWatcher service = context.getBean(EventSendingTest.class);
10 | service.start();
11 | service.process();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/flume-logging-monitor-handler/src/main/java/com/shawn/logging/monitor/handler/LogWatchRunScript.java:
--------------------------------------------------------------------------------
1 | package com.shawn.logging.monitor.handler;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.support.ClassPathXmlApplicationContext;
5 |
6 |
7 | public class LogWatchRunScript {
8 | public static void main(String[] args) throws Exception {
9 | ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
10 | // LogWatcher service = context.getBean(LogWatcherByWatchEvent.class);
11 | LogWatcher service = context.getBean(LogWatcherBySchedule.class);
12 | service.start();
13 | service.process();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/flume-logging-monitor-client/src/main/conf/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/flume-logging-monitor-handler/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/flume-logging-monitor-handler/src/main/resources/configuration.properties:
--------------------------------------------------------------------------------
1 | #the agent host
2 | monitor.agent.host=127.0.0.1
3 | #the agent port
4 | monitor.agent.port=41414
5 | #timeout on connecting the agent port
6 | monitor.client.timeout=10000
7 | #retry times on connecting the agent
8 | monitor.client.maxAttempts = 2
9 | #time interval of the scheduling thread detects the log changes (in milliseconds)
10 | monitor.client.schedule.delay=1000
11 | #for multiple file ,separated by commas
12 | monitor.client.schedule.watchpaths=/opt/apache-tomcat-7.0.42/logs/test_logs/append-medium_0,/opt/apache-tomcat-7.0.42/logs/test_logs/append-medium_1,/opt/apache-tomcat-7.0.42/logs/test_logs/append-medium_2,/opt/apache-tomcat-7.0.42/logs/test_logs/append-medium_3
13 |
14 | #stash the log status to local file when client shutdown
15 | monitor.client.logStatusRecordPath=log_record
16 |
17 | #max size for each source event; theoretically, less than Integer.MAX_VALUE : 2147483647
18 | monitor.client.event.size = 5242880
19 |
20 | #event header configuration
21 | monitor.event.headerConfigPath=/home/shawncao/Desktop/logHeader.json
22 |
23 | # log suffix date format
24 | monitor.log.suffix.date=yy-MM-dd
25 |
--------------------------------------------------------------------------------
/flume-logging-monitor-client/src/main/conf/configuration.properties:
--------------------------------------------------------------------------------
1 | #the agent host
2 | monitor.agent.host=10.40.5.3
3 | #the agent port
4 | monitor.agent.port=41410
5 | #timeout on connecting the agent port
6 | monitor.client.timeout=10000
7 | #retry times on connecting the agent
8 | monitor.client.maxAttempts = 2
9 | #time interval of the scheduling thread detects the log changes (in milliseconds)
10 | monitor.client.schedule.delay=2000
11 | #for multiple file ,separated by commas
12 | monitor.client.schedule.watchpaths=/var/log/nginx/www.shawn.com.access_log,/var/log/nginx/www.shawn.com.error_log,/var/log/nginx/login.shawn.com.access_log,/var/log/nginx/login.shawn.com.error_log,/var/log/nginx/job.shawn.com.access_log,/var/log/nginx/job.shawn.com.error_log,/var/log/nginx/image.shawn.com.access_log,/var/log/nginx/image.shawn.com.error_log,/var/log/nginx/rest.shawn.com.access_log,/var/log/nginx/rest.shawn.com.error_log,/var/log/haproxy.log,
13 |
14 | #max size for each source event; theoretically, less than Integer.MAX_VALUE : 2147483647
15 | monitor.client.event.size = 5242880
16 |
17 | #stash the log status to local file when client shutdown
18 | monitor.client.logStatusRecordPath=log_record
19 |
20 | #event header configuration
21 | monitor.event.headerConfigPath=./conf/logHeader_integ.json
22 |
23 |
24 |
--------------------------------------------------------------------------------
/flume-logging-monitor-client/src/main/assembly/bin.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 | bin
9 |
10 | tar.gz
11 |
12 |
13 | false
14 |
15 |
16 |
17 | flume-client/lib/
18 | false
19 |
20 |
21 |
22 |
23 |
24 | src/main/README.md
25 | flume-client/
26 | true
27 |
28 |
29 |
30 |
31 |
32 | src/main/conf
33 | flume-client/conf
34 |
35 |
36 |
37 | src/main/bin
38 | flume-client/bin
39 | 0775
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/flume-logging-monitor-client/src/main/conf/logHeader.json.example:
--------------------------------------------------------------------------------
1 | {
2 | "/var/log/nginx/www.shawn.com.access_log": {
3 | "domain": "www",
4 | "log_type": "access",
5 | "server_type":"nginx"
6 | },
7 | "/var/log/nginx/www.shawn.com.error_log": {
8 | "domain": "www",
9 | "log_type": "error",
10 | "server_type":"nginx"
11 | },
12 | "/var/log/nginx/login.shawn.com.access_log": {
13 | "domain": "login",
14 | "log_type": "access",
15 | "server_type":"nginx"
16 | },
17 | "/var/log/nginx/login.shawn.com.error_log": {
18 | "domain": "login",
19 | "log_type": "error",
20 | "server_type":"nginx"
21 | },
22 | "/var/log/nginx/job.shawn.com.access_log": {
23 | "domain": "job",
24 | "log_type": "access",
25 | "server_type":"nginx"
26 | },
27 | "/var/log/nginx/job.shawn.com.error_log": {
28 | "domain": "job",
29 | "log_type": "error",
30 | "server_type":"nginx"
31 | },
32 | "/var/log/nginx/image.shawn.com.access_log": {
33 | "domain": "image",
34 | "log_type": "access",
35 | "server_type":"nginx"
36 | },
37 | "/var/log/nginx/image.shawn.com.error_log": {
38 | "domain": "image",
39 | "log_type": "error",
40 | "server_type":"nginx"
41 | },
42 | "/var/log/nginx/rest.shawn.com.access_log": {
43 | "domain": "rest",
44 | "log_type": "access",
45 | "server_type":"nginx"
46 | },
47 | "/var/log/nginx/rest.shawn.com.error_log": {
48 | "domain": "rest",
49 | "log_type": "error",
50 | "server_type":"nginx"
51 | },
52 | "/var/log/haproxy.log": {
53 | "domain": "default",
54 | "log_type": "default",
55 | "server_type":"haproxy"
56 | }
57 | }
--------------------------------------------------------------------------------
/flume-logging-monitor-client/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | com.shawn
6 | flume-logging-monitor
7 | 0.1-SNAPSHOT
8 |
9 | flume-logging-monitor-client
10 | pom
11 | flume-logging-monitor-client
12 | http://maven.apache.org
13 |
14 | UTF-8
15 |
16 |
17 |
18 | junit
19 | junit
20 | test
21 |
22 |
23 | ${project.groupId}
24 | flume-logging-monitor-handler
25 | ${project.version}
26 |
27 |
28 |
29 |
30 |
31 | org.apache.maven.plugins
32 | maven-assembly-plugin
33 |
34 |
35 | assembly
36 | package
37 |
38 | single
39 |
40 |
41 |
42 | src/main/assembly/bin.xml
43 |
44 | gnu
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/flume-logging-monitor-handler/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | com.shawn
6 | flume-logging-monitor
7 | 0.1-SNAPSHOT
8 |
9 | flume-logging-monitor-handler
10 | jar
11 | flume-logging-monitor-handler
12 | http://maven.apache.org
13 |
14 | UTF-8
15 |
16 |
17 |
18 | junit
19 | junit
20 | test
21 |
22 |
23 | org.apache.flume
24 | flume-ng-core
25 |
26 |
27 | org.slf4j
28 | slf4j-api
29 |
30 |
31 | org.slf4j
32 | slf4j-log4j12
33 |
34 |
35 | org.springframework
36 | spring-core
37 |
38 |
39 | org.springframework
40 | spring-beans
41 |
42 |
43 | org.springframework
44 | spring-context
45 |
46 |
47 | com.google.code.gson
48 | gson
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/flume-logging-monitor-client/src/main/bin/monitor:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | source /etc/profile
3 | export LANG=en_US.utf8
4 | PRG=$0
5 | PRGDIR=`dirname "$PRG"`
6 | CLASSPATH="$PRGDIR/../conf"
7 | FILES=$PRGDIR/../lib/*
8 |
9 | test() {
10 | ps aux |grep -v grep|grep EventSendingTestScript -q
11 | if [ $? -eq 0 ];then
12 | echo eventsTest is already running
13 | exit 1
14 | fi
15 |
16 | echo EventSendingTest is starting.
17 | for f in $FILES
18 | do
19 | CLASSPATH=${CLASSPATH}:$f
20 | done
21 | echo ${CLASSPATH}
22 | java -classpath ${CLASSPATH} com.shawn.logging.monitor.handler.EventSendingTestScript &
23 |
24 | }
25 |
26 | start(){
27 | ps aux |grep -v grep|grep LogWatchRunScript -q
28 | if [ $? -eq 0 ];then
29 | echo log watcher is already running
30 | exit 1
31 | fi
32 |
33 | echo log watcher client is starting.
34 | for f in $FILES
35 | do
36 | CLASSPATH=${CLASSPATH}:$f
37 | done
38 | echo ${CLASSPATH}
39 | java -Xms1024m -Xmx2048m -classpath ${CLASSPATH} com.shawn.logging.monitor.handler.LogWatchRunScript &
40 | }
41 |
42 | stop(){
43 | ps aux |grep -v grep|grep LogWatchRunScript -q
44 | if [ $? -ne 0 ];then
45 | echo LogWatchRunScript is not running
46 | else
47 | ps aux |grep -v grep|grep LogWatchRunScript|awk '{print $2}'|xargs kill -15
48 | sleep 3
49 | ps aux |grep -v grep|grep LogWatchRunScript -q
50 | [ $? -eq 0 ] && ps aux |grep LogWatchRunScript|grep -v grep|awk '{print $2}'|xargs kill -9
51 | fi
52 |
53 |
54 | }
55 |
56 | status(){
57 | ps aux |grep -v grep|grep LogWatchRunScript -q
58 | if [ $? -eq 0 ];then
59 | echo LogWatchRunScript is running
60 | else
61 | echo LogWatchRunScript is not running
62 | fi
63 | }
64 |
65 | help(){
66 | echo "Usage : [start|stop|restart|status]"
67 | }
68 |
69 | case $1 in
70 | help)
71 | help
72 | ;;
73 | test)
74 | test
75 | ;;
76 | start)
77 | start
78 | ;;
79 | stop)
80 | stop
81 | ;;
82 | restart)
83 | stop
84 | sleep 1
85 | start
86 | ;;
87 | status)
88 | status
89 | ;;
90 | *)
91 | echo "Usage : $0 [start|stop|restart|status|test]"
92 | ;;
93 | esac
--------------------------------------------------------------------------------
/flume-logging-monitor-client/src/main/conf/developer-guide.md:
--------------------------------------------------------------------------------
1 | Log Monitor
2 | =========
3 |
4 | logging client is used to capture the changed text and send them by avro client in the format of flume event.
5 |
6 | In the conf folder , there are configurations that you can work with .
7 | - *configuration.propreties* is the basic config , like the listening agent host and port ,the file that you want to watch the changes and send these to flume .etc .
8 | - *logHeader.json.sample* is the sample log header file that indicates the format of customized event header for certain watching file .The path of such header config can be specified by *monitor.event.headerConfigPath* in configuration.properties
9 | - everytime the client shuts down ,a hook method will automatically execute in order to stash the current status of the watching paths . When the client starts again ,it will first check the log status file ,if there is any , the status of the watching paths will be loaded and be further processed .
10 |
11 | To start the client:
12 | >./bin/logWatcherClient start
13 |
14 | Abstraction:
15 | The client consists of three phases .
16 | - Initialization phase
17 |
18 | Firstly, The client loads all static configuration from *configuration.properties*.If the the log status is pre stashed , it will load the log status file and map each log status to the current watching path .If the customized header file exists ,the client will also map the header to the current watching path.
19 |
20 | - Process phase
21 |
22 | During the process phase ,the client will firstly initialized a schedule thread to in order to do the job at fixed time interval and a thread pool with each thread assigning a task of checking the log changes on given path .When the changes occurs , the thread pool will return the result set of changes (List>) to the schedule thread ,eventually the schedule thread will initilize the avro client and send the event batch to the target agent . If the sending procedure is unsuccessful , the client will roll back the status of the watching path back to the status before the patches being sent.
23 |
24 | - Shutdown phase
25 |
26 | If the client is shut down by keyboard interruption or kill -5 . The status of current watching path will be logged to a file by a shut down hook method .Next time the client start , it will read and load the path status from that file .
27 |
28 |
--------------------------------------------------------------------------------
/flume-logging-monitor-handler/src/main/java/com/shawn/logging/monitor/handler/EventSendingTest.java:
--------------------------------------------------------------------------------
1 | package com.shawn.logging.monitor.handler;
2 |
3 | import java.util.Date;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | import org.apache.flume.Event;
8 | import org.apache.flume.event.EventBuilder;
9 | import org.apache.http.protocol.HTTP;
10 | import org.springframework.stereotype.Service;
11 |
12 | import com.google.common.base.Charsets;
13 | import com.google.common.collect.ImmutableMap;
14 | import com.google.common.collect.Lists;
15 | import com.google.common.collect.Maps;
16 | import com.google.common.net.HttpHeaders;
17 |
18 | @Service
19 | public class EventSendingTest extends LogWatcher{
20 |
21 | public EventSendingTest() throws Exception {
22 | }
23 | private String test = "TestTestTestTestTest";
24 | @Override
25 | public void start() throws Exception {
26 | // logStatusMap = JsonFormatMapConfigHelper.loadJsonMap(logStatusMap, logStatusRecordPath,new TypeToken() {});
27 | // headerConfigMap = JsonFormatMapConfigHelper.loadJsonMap(headerConfigMap, headerConfigPath,new TypeToken