Repository: incubator-brooklyn Updated Branches: refs/heads/master 65bc06adc -> 2ebc307a3
Added additional sensors Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/62c7d20f Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/62c7d20f Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/62c7d20f Branch: refs/heads/master Commit: 62c7d20f2a1477fbe9291d491891eebb6e70c55f Parents: b158aa3 Author: Martin Harris <[email protected]> Authored: Fri May 30 12:33:45 2014 +0100 Committer: Martin Harris <[email protected]> Committed: Tue Jun 17 10:19:57 2014 +0100 ---------------------------------------------------------------------- .../nosql/elasticsearch/ElasticSearchNode.java | 6 ++++ .../elasticsearch/ElasticSearchNodeImpl.java | 38 +++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/62c7d20f/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java ---------------------------------------------------------------------- diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java b/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java index 30d80e9..32ec9af 100644 --- a/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java +++ b/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java @@ -31,4 +31,10 @@ public interface ElasticSearchNode extends SoftwareProcess, DatastoreMixins.HasD AttributeSensor<String> NODE_ID = Sensors.newStringSensor("elasticsearch.node.id"); AttributeSensor<String> NODE_NAME = Sensors.newStringSensor("elasticsearch.node.name"); AttributeSensor<String> CLUSTER_NAME = Sensors.newStringSensor("elasticsearch.cluster.name"); + AttributeSensor<Integer> DOCUMENT_COUNT = Sensors.newIntegerSensor("elasticsearch.docs.count"); + AttributeSensor<Integer> STORE_BYTES = Sensors.newIntegerSensor("elasticsearch.store.bytes"); + AttributeSensor<Integer> GET_TOTAL = Sensors.newIntegerSensor("elasticsearch.get.total"); + AttributeSensor<Integer> GET_TIME_IN_MILLIS = Sensors.newIntegerSensor("elasticsearch.get.time.in.millis"); + AttributeSensor<Integer> SEARCH_QUERY_TOTAL = Sensors.newIntegerSensor("elasticsearch.search.query.total"); + AttributeSensor<Integer> SEARCH_QUERY_TIME_IN_MILLIS = Sensors.newIntegerSensor("elasticsearch.search.query.time.in.millis"); } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/62c7d20f/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeImpl.java ---------------------------------------------------------------------- diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeImpl.java b/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeImpl.java index 92c809c..f25d0bf 100644 --- a/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeImpl.java +++ b/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeImpl.java @@ -7,6 +7,7 @@ import brooklyn.event.feed.http.HttpPollConfig; import brooklyn.event.feed.http.HttpValueFunctions; import brooklyn.event.feed.http.JsonFunctions; import brooklyn.location.access.BrooklynAccessUtils; +import brooklyn.util.http.HttpToolResponse; import com.google.common.base.Function; import com.google.common.base.Functions; @@ -37,15 +38,20 @@ public class ElasticSearchNodeImpl extends SoftwareProcessImpl implements Elasti return input.getAsJsonObject().entrySet().iterator().next().getKey(); } }; - Function<JsonElement, JsonElement> getFirstNode = new Function<JsonElement, JsonElement>() { + + Function<JsonElement, JsonElement> getFirstNodeFromNodes = new Function<JsonElement, JsonElement>() { @Override public JsonElement apply(JsonElement input) { return input.getAsJsonObject().entrySet().iterator().next().getValue(); } }; + + Function<HttpToolResponse, JsonElement> getFirstNode = HttpValueFunctions.chain(HttpValueFunctions.jsonContents(), + JsonFunctions.walk("nodes"), getFirstNodeFromNodes); + httpFeed = HttpFeed.builder() .entity(this) .period(1000) - .baseUri(String.format("http://%s:%s/_nodes/_local", hp.getHostText(), hp.getPort())) + .baseUri(String.format("http://%s:%s/_nodes/_local/stats", hp.getHostText(), hp.getPort())) .poll(new HttpPollConfig<Boolean>(SERVICE_UP) .onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(false))) @@ -53,13 +59,29 @@ public class ElasticSearchNodeImpl extends SoftwareProcessImpl implements Elasti .onSuccess(HttpValueFunctions.chain(HttpValueFunctions.jsonContents(), JsonFunctions.walk("nodes"), getNodeId)) .onFailureOrException(Functions.constant(""))) .poll(new HttpPollConfig<String>(NODE_NAME) - .onSuccess(HttpValueFunctions.chain(HttpValueFunctions.chain(HttpValueFunctions.jsonContents(), JsonFunctions.walk("nodes"), getFirstNode), - JsonFunctions.walk("name"), JsonFunctions.cast(String.class))) - .onFailureOrException(Functions.constant(""))) + .onSuccess(HttpValueFunctions.chain(getFirstNode, JsonFunctions.walk("name"), JsonFunctions.cast(String.class))) + .onFailureOrException(Functions.<String>constant(null))) .poll(new HttpPollConfig<String>(CLUSTER_NAME) - .onSuccess(HttpValueFunctions.chain(HttpValueFunctions.chain(HttpValueFunctions.jsonContents(), JsonFunctions.walk("nodes"), getFirstNode), - JsonFunctions.walk("settings", "cluster", "name"), JsonFunctions.cast(String.class))) - .onFailureOrException(Functions.constant(""))) + .onSuccess(HttpValueFunctions.chain(getFirstNode, JsonFunctions.walk("settings", "cluster", "name"), JsonFunctions.cast(String.class))) + .onFailureOrException(Functions.<String>constant(null))) + .poll(new HttpPollConfig<Integer>(DOCUMENT_COUNT) + .onSuccess(HttpValueFunctions.chain(getFirstNode, JsonFunctions.walk("indices", "docs", "count"), JsonFunctions.cast(Integer.class))) + .onFailureOrException(Functions.<Integer>constant(null))) + .poll(new HttpPollConfig<Integer>(STORE_BYTES) + .onSuccess(HttpValueFunctions.chain(getFirstNode, JsonFunctions.walk("indices", "store", "size_in_bytes"), JsonFunctions.cast(Integer.class))) + .onFailureOrException(Functions.<Integer>constant(null))) + .poll(new HttpPollConfig<Integer>(GET_TOTAL) + .onSuccess(HttpValueFunctions.chain(getFirstNode, JsonFunctions.walk("indices", "get", "total"), JsonFunctions.cast(Integer.class))) + .onFailureOrException(Functions.<Integer>constant(null))) + .poll(new HttpPollConfig<Integer>(GET_TIME_IN_MILLIS) + .onSuccess(HttpValueFunctions.chain(getFirstNode, JsonFunctions.walk("indices", "get", "time_in_millis"), JsonFunctions.cast(Integer.class))) + .onFailureOrException(Functions.<Integer>constant(null))) + .poll(new HttpPollConfig<Integer>(SEARCH_QUERY_TOTAL) + .onSuccess(HttpValueFunctions.chain(getFirstNode, JsonFunctions.walk("indices", "search", "query_total"), JsonFunctions.cast(Integer.class))) + .onFailureOrException(Functions.<Integer>constant(null))) + .poll(new HttpPollConfig<Integer>(SEARCH_QUERY_TIME_IN_MILLIS) + .onSuccess(HttpValueFunctions.chain(getFirstNode, JsonFunctions.walk("indices", "search", "query_time_in_millis"), JsonFunctions.cast(Integer.class))) + .onFailureOrException(Functions.<Integer>constant(null))) .build(); }
