From 2782204920c79f71323ce291a5f0e72026317135 Mon Sep 17 00:00:00 2001 From: geek Date: Wed, 12 Apr 2017 13:06:47 +0900 Subject: [PATCH] shared project --- pom.xml | 38 +++++++++ redis_crawler_java.iml | 24 ++++++ .../loafle/overflow/crawler/redis/App.java | 10 +++ .../overflow/crawler/redis/RedisCralwer.java | 82 +++++++++++++++++++ src/main/resources/_ | 0 .../java/com/loafle/overflow/AppTest.java | 11 +++ src/test/resources/logback.xml | 17 ++++ 7 files changed, 182 insertions(+) create mode 100644 pom.xml create mode 100644 redis_crawler_java.iml create mode 100644 src/main/java/com/loafle/overflow/crawler/redis/App.java create mode 100644 src/main/java/com/loafle/overflow/crawler/redis/RedisCralwer.java create mode 100644 src/main/resources/_ create mode 100644 src/test/java/com/loafle/overflow/AppTest.java create mode 100644 src/test/resources/logback.xml diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a725fde --- /dev/null +++ b/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + + com.loafle + maven_parent_jar + 1.0.0-RELEASE + + + com.loafle.overflow + cralwer_redis + jar + 1.0.0-SNAPSHOT + com.loafle.overflow.cralwer_redis + + + + 2.9.0 + + + + + com.loafle.overflow + crawler_java + 1.0.0-SNAPSHOT + + + redis.clients + jedis + ${redis.client.version} + + + + + \ No newline at end of file diff --git a/redis_crawler_java.iml b/redis_crawler_java.iml new file mode 100644 index 0000000..4b9e57b --- /dev/null +++ b/redis_crawler_java.iml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/crawler/redis/App.java b/src/main/java/com/loafle/overflow/crawler/redis/App.java new file mode 100644 index 0000000..851f8e4 --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/redis/App.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.crawler.redis; + +import java.util.Map; + +public class App { + public static void main(String[] args) { + RedisCralwer redisCralwer = new RedisCralwer(); + Map r = redisCralwer.collectMetric("192.168.1.215", (short) 6379, "","ALL"); + } +} \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/crawler/redis/RedisCralwer.java b/src/main/java/com/loafle/overflow/crawler/redis/RedisCralwer.java new file mode 100644 index 0000000..d2b5176 --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/redis/RedisCralwer.java @@ -0,0 +1,82 @@ +package com.loafle.overflow.crawler.redis; + +import com.loafle.overflow.crawler.Crawler; +import redis.clients.jedis.Jedis; + +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Created by geek on 2017-04-12. + */ +public class RedisCralwer extends Crawler { + private Jedis jedis; + + private static final Logger LOGGER = Logger.getLogger(RedisCralwer.class.getName()); + + public RedisCralwer() { + + } + + @Override + public Object getInternal(Map map) throws Exception { + LOGGER.log(Level.INFO ,"getInternal call"); + //접속 + + Map re = collectMetric("192.168.1.215", (short) 6379, "","ALL"); + + return re; + } + + protected Map collectMetric(String ip, short port, String authpw ,String category ) { + Jedis jedis = new Jedis(ip, port,false); + String t = jedis.set("AUTH", authpw); + String dd = jedis.info(category); + + // 파싱 + Map re = parseToMap(dd); + + System.out.println("re : "+re); + //연결 해제 + jedis.close(); + //데이터 출력 + return re; + } + + private Map parseToMap(String source) { + String[] categorys = source.split("\r\n\r\n"); + Map result = new HashMap(); + + for (String category : categorys) { + if (category.length() == 0) { + continue; + } + Map sm = new HashMap(); + String[] lines = category.split("\r\n"); + + int idx = 0; + for (String line : lines) { + if (idx == 0) { + idx++; + continue; + } + + if (line.length() == 0) { + continue; + } + + String[] items = line.split(":"); + + if (items.length != 0&& items.length > 1) { + sm.put(items[0], items[1]); + } + } + String[] ca = lines[0].split(" "); + + result.put(ca[1], sm); + } + return result; + } +} diff --git a/src/main/resources/_ b/src/main/resources/_ new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/com/loafle/overflow/AppTest.java b/src/test/java/com/loafle/overflow/AppTest.java new file mode 100644 index 0000000..6208f31 --- /dev/null +++ b/src/test/java/com/loafle/overflow/AppTest.java @@ -0,0 +1,11 @@ + +package com.loafle.overflow; +import static org.junit.Assert.*; +import org.junit.Test; + +public class AppTest { + @Test + public void testSum() { + assertEquals(1,1); + } +} \ No newline at end of file diff --git a/src/test/resources/logback.xml b/src/test/resources/logback.xml new file mode 100644 index 0000000..2220b49 --- /dev/null +++ b/src/test/resources/logback.xml @@ -0,0 +1,17 @@ + + + redis_cralwer_java + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{32} - %msg%n + + + + + + + + + \ No newline at end of file