shared project

This commit is contained in:
geek 2017-04-12 13:06:47 +09:00
commit 2782204920
7 changed files with 182 additions and 0 deletions

38
pom.xml Normal file
View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.loafle</groupId>
<artifactId>maven_parent_jar</artifactId>
<version>1.0.0-RELEASE</version>
</parent>
<groupId>com.loafle.overflow</groupId>
<artifactId>cralwer_redis</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>com.loafle.overflow.cralwer_redis</name>
<properties>
<redis.client.version>2.9.0</redis.client.version>
</properties>
<dependencies>
<dependency>
<groupId>com.loafle.overflow</groupId>
<artifactId>crawler_java</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${redis.client.version}</version>
</dependency>
</dependencies>
</project>

24
redis_crawler_java.iml Normal file
View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/../redis_cralwer_java/target/classes" />
<output-test url="file://$MODULE_DIR$/../redis_cralwer_java/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.loafle.overflow:crawler_java:1.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: redis.clients:jedis:2.9.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
</component>
</module>

View File

@ -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<String, Object> r = redisCralwer.collectMetric("192.168.1.215", (short) 6379, "","ALL");
}
}

View File

@ -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<String, Object> map) throws Exception {
LOGGER.log(Level.INFO ,"getInternal call");
//접속
Map<String, Object> re = collectMetric("192.168.1.215", (short) 6379, "","ALL");
return re;
}
protected Map<String, Object> 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<String, Object> re = parseToMap(dd);
System.out.println("re : "+re);
//연결 해제
jedis.close();
//데이터 출력
return re;
}
private Map<String, Object> parseToMap(String source) {
String[] categorys = source.split("\r\n\r\n");
Map<String, Object> result = new HashMap<String, Object>();
for (String category : categorys) {
if (category.length() == 0) {
continue;
}
Map<String, String> sm = new HashMap<String,String>();
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;
}
}

0
src/main/resources/_ Normal file
View File

View File

@ -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);
}
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="3 seconds">
<contextName>redis_cralwer_java</contextName>
<!-- TRACE > DEBUG > INFO > WARN > ERROR -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{32} - %msg%n
</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
<logger name="com.loafle.overflow" level="ALL" />
</configuration>