-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from indigo-dc/dev
Dev
- Loading branch information
Showing
30 changed files
with
639 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
zabbix-probes/mesos-zabbix-probe/src/main/java/com/indigo/mesosprobe/MesosClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
zabbix-probes/mesos-zabbix-probe/src/main/java/com/indigo/mesosprobe/MesosCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
zabbix-probes/mesos-zabbix-probe/src/main/java/com/indigo/mesosprobe/ProbeClient.java
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
zabbix-probes/mesos-zabbix-probe/src/main/java/com/indigo/mesosprobe/ProbeThread.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
|
||
} |
55 changes: 0 additions & 55 deletions
55
zabbix-probes/mesos-zabbix-probe/src/main/java/com/indigo/mesosprobe/ZabbixClient.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.