shared project
This commit is contained in:
commit
a69aadd1f7
23
mongodb_crawler_java.iml
Normal file
23
mongodb_crawler_java.iml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?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$/../mongo_crawler_java/target/classes" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/../mongo_crawler_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:1.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.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>
|
36
pom.xml
Normal file
36
pom.xml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?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>crawler_mongodb</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<name>com.loafle.overflow.crawler_mongo</name>
|
||||||
|
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<mogodb.client.version>3.4.2</mogodb.client.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.loafle.overflow</groupId>
|
||||||
|
<artifactId>crawler</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mongodb</groupId>
|
||||||
|
<artifactId>mongo-java-driver</artifactId>
|
||||||
|
<version>${mogodb.client.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.loafle.overflow.crawler.mongo;
|
||||||
|
|
||||||
|
import com.loafle.overflow.crawler.Crawler;
|
||||||
|
import com.mongodb.MongoClient;
|
||||||
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
import org.bson.Document;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
public class MongoCrawler extends Crawler {
|
||||||
|
|
||||||
|
protected Map<String, Object> collectMetric(String ip, String port, String dbName) {
|
||||||
|
|
||||||
|
MongoClient mb = null;
|
||||||
|
Map<String, Object> result = null;
|
||||||
|
try {
|
||||||
|
short p = Short.parseShort(port);
|
||||||
|
mb = new MongoClient(ip, p);
|
||||||
|
MongoDatabase database = mb.getDatabase(dbName);
|
||||||
|
Document serverStatus = database.runCommand(new Document("serverStatus", 1));
|
||||||
|
|
||||||
|
// System.out.println("serverStatus.size() = " + serverStatus.size());
|
||||||
|
result = new HashMap<String, Object>();
|
||||||
|
for (Map.Entry<String, Object> set : serverStatus.entrySet()){
|
||||||
|
result.put(set.getKey(), set.getValue());
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}finally {
|
||||||
|
if (mb != null) {
|
||||||
|
mb.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> testColect(String ip, String port, String dbName) {
|
||||||
|
return this.collectMetric(ip,port,dbName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getInternal(Map<String, Object> map) throws Exception {
|
||||||
|
Map<String ,Object> re = collectMetric((String) map.get("ip"), (String)map.get("port"), (String)map.get("dbName"));
|
||||||
|
System.out.println("re = " + re);
|
||||||
|
return re;
|
||||||
|
}
|
||||||
|
}
|
0
src/main/resources/_
Normal file
0
src/main/resources/_
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
package com.loafle.overflow.crawler;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import com.loafle.overflow.crawler.mongo.MongoCrawler;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MongoCrawlerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void TestCollectMetric() {
|
||||||
|
MongoCrawler cr = new MongoCrawler();
|
||||||
|
Map<String,Object> m = cr.testColect("192.168.1.104", "27017", "admin");
|
||||||
|
|
||||||
|
assertEquals(23, m.size());
|
||||||
|
}
|
||||||
|
}
|
17
src/test/resources/logback.xml
Normal file
17
src/test/resources/logback.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="3 seconds">
|
||||||
|
<contextName>mongo_crawler</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>
|
Loading…
x
Reference in New Issue
Block a user