Skip to content

Commit

Permalink
Merge pull request #11 from indigo-dc/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Jose Antonio Sanchez authored Oct 10, 2016
2 parents d726383 + b28bd54 commit 976d1f3
Show file tree
Hide file tree
Showing 30 changed files with 639 additions and 208 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/MonitoringProbes.iml
/.idea/
/zabbix-probes/mesos-zabbix-probe/mesos-zabbix-probe.iml
/zabbix-probes/zabbix-probes-common/zabbix-probes-common.iml
Binary file not shown.
13 changes: 11 additions & 2 deletions zabbix-probes/mesos-zabbix-probe/mesos-zabbix-probe.iml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?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_7" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
Expand All @@ -16,9 +16,18 @@
<orderEntry type="library" name="Maven: com.netflix.feign:feign-core:8.14.1" level="project" />
<orderEntry type="library" name="Maven: com.netflix.feign:feign-gson:8.14.1" level="project" />
<orderEntry type="library" name="Maven: com.mesosphere:marathon-client:0.3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" />
<orderEntry type="module" module-name="zabbix-probes-common" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-configuration2:2.0" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" />
<orderEntry type="library" name="Maven: io.github.hengyunabc:zabbix-sender:0.0.3" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.8" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.5" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: ch.qos.logback:logback-classic:1.0.13" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: ch.qos.logback:logback-core:1.0.13" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-client:2.22" level="project" />
<orderEntry type="library" name="Maven: javax.ws.rs:javax.ws.rs-api:2.0.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-common:2.22" level="project" />
Expand Down
18 changes: 10 additions & 8 deletions zabbix-probes/mesos-zabbix-probe/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>org.indigo</groupId>
<artifactId>zabbix-probes-base</artifactId>
<relativePath>../zabbix-probes-base</relativePath>
<version>0.95</version>
<version>1.01</version>
</parent>


Expand Down Expand Up @@ -52,12 +52,6 @@
<version>0.3.0</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.0</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down Expand Up @@ -151,7 +145,15 @@
</mappings>
</configuration>
</plugin>
</plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.indigo.mesosprobe;

import com.indigo.zabbix.utils.PropertiesManager;

import it.infn.ba.indigo.chronos.client.Chronos;
import it.infn.ba.indigo.chronos.client.model.v1.Container;
import it.infn.ba.indigo.chronos.client.model.v1.Job;
Expand All @@ -20,6 +22,7 @@ public class ChronosClient {

/**
* Test that chronos is running ok.
*
* @return the chronos status.
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.indigo.mesosprobe;


import com.indigo.zabbix.utils.PropertiesManager;

import mesosphere.marathon.client.Marathon;
import mesosphere.marathon.client.model.v2.App;
import mesosphere.marathon.client.model.v2.Container;
Expand All @@ -13,14 +15,14 @@
import org.apache.commons.logging.LogFactory;



public class MarathonClient {

private static final Log logger = LogFactory.getLog(MarathonClient.class);
public static final String APP_NAME = "zabbix-test-app";

/**
* Test that Marathon installation is working.
*
* @return result of the test.
*/
public boolean testMarathon() {
Expand All @@ -47,7 +49,7 @@ public boolean testMarathon() {
}

} catch (MarathonException e) {
logger.error("Error creating app " + APP_NAME,e);
logger.error("Error creating app " + APP_NAME, e);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.indigo.mesosprobe;

import com.indigo.mesosprobe.mesos.MesosClient;
import com.indigo.zabbix.utils.ProbeClientFactory;

/**
* Created by jose on 4/10/16.
*/
public class MesosClientFactory extends ProbeClientFactory {

public static MesosClient getMesosClient(String endpoint) {
return getClient(MesosClient.class, endpoint);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.indigo.mesosprobe;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import com.indigo.mesosprobe.mesos.MesosClient;
import com.indigo.mesosprobe.mesos.beans.MesosMasterInfoBean;
import com.indigo.zabbix.utils.MetricsCollector;
import com.indigo.zabbix.utils.PropertiesManager;
import com.indigo.zabbix.utils.ZabbixMetrics;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by jose on 4/10/16.
*/
public class MesosCollector implements MetricsCollector {

private Map<String, String> readMetrics(JsonObject metrics, List<String> properties) {
Map<String, String> result = new HashMap<>();
properties.forEach(property -> {
JsonElement elem = metrics.get(property);
if (elem != null && elem.isJsonPrimitive()) {
result.put(property.replace("/", "."), elem.getAsString());
}
});
return result;
}

private String findLeader() {
String masterEndpoint = PropertiesManager.getProperty(MesosProbeTags.MESOS_MASTER_ENDPOINT);
if (masterEndpoint != null) {
MesosClient client = MesosClientFactory.getMesosClient(masterEndpoint);
MesosMasterInfoBean redirect = client.getInfo();
String leader = redirect.getLeader();
if (leader != null) {
String[] leaderInfo = leader.split("@");
if (leaderInfo.length == 2) {
return leaderInfo[1];
}
}
}
return null;
}

@Override
public ZabbixMetrics getMetrics() {
String leader = findLeader();
if (leader != null) {

List<String> properties = PropertiesManager.getListProperty(
MesosProbeTags.MESOS_METRIC);

if (properties != null && !properties.isEmpty()) {
MesosClient mesosClient = MesosClientFactory.getMesosClient("http://" + leader);

MesosMasterInfoBean leaderInfo = mesosClient.getInfo();
if (leaderInfo.getHostname() != null) {

ZabbixMetrics result = new ZabbixMetrics();

result.setHostName(leaderInfo.getHostname());

JsonObject metrics = mesosClient.getMetrics();
result.setMetrics(readMetrics(metrics, properties));

result.setTimestamp(new Date().getTime());

return result;
}
}
}

return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public interface MesosProbeTags {
String CHRONOS_ENDPOINT = "chronos.endpoint";
String MARATHON_ENDPOINT = "marathon.endpoint";

String ZABBIX_WRAPPER_ENDPOINT = "zabbix.wrapper.location";

String CHRONOS_USERNAME = "chronos.username";
String CHRONOS_PASSWORD = "chronos.password";

Expand All @@ -19,4 +17,6 @@ public interface MesosProbeTags {

String CONFIG_FILE = "mesosprobe.properties";
String MESOS_METRIC = "mesos.metric";


}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.indigo.mesosprobe;

import com.indigo.zabbix.utils.PropertiesManager;
import com.indigo.zabbix.utils.ZabbixClient;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.IOException;

/**
* Created by jose on 22/09/16.
*/
public class ProbeThread {

private static final Log logger = LogFactory.getLog(ProbeThread.class);

private ZabbixClient zabbixClient = new ZabbixClient();

private void startMonitoring() {
MesosCollector collector = new MesosCollector();
zabbixClient.sendMetrics(collector.getMetrics());
}



/**
* Start monitoring process.
* @param args Arguments will be ignored.
*/
public static void main(String[] args) {

try {
PropertiesManager.loadProperties(MesosProbeTags.CONFIG_FILE);
ProbeThread thread = new ProbeThread();
thread.startMonitoring();
} catch (IOException e) {
logger.error("Error reading configuration file", e);
}

}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.indigo.mesosprobe;
package com.indigo.mesosprobe.mesos;

import com.google.gson.JsonObject;

import com.indigo.mesosprobe.mesos.beans.MesosMasterInfoBean;

import feign.RequestLine;

/**
Expand All @@ -12,4 +14,7 @@ public interface MesosClient {
@RequestLine("GET /metrics/snapshot")
JsonObject getMetrics();

@RequestLine("GET /state")
MesosMasterInfoBean getInfo();

}
Loading

0 comments on commit 976d1f3

Please sign in to comment.