.baseUri(getMesosCluster().sensors().get(Attributes.MAIN_URI)) .credentialsIfNotNull(config().get(MesosCluster.MESOS_USERNAME), config().get(MesosCluster.MESOS_PASSWORD)) .poll(HttpPollConfig.forSensor(MEMORY_AVAILABLE) .suburl("/master/state.json") .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.castM(Long.class))) .onFailureOrException(Functions.constant(-1L))) .poll(HttpPollConfig.forSensor(CPU_AVAILABLE) .suburl("/master/state.json") .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.castM(Double.class))) .onFailureOrException(Functions.constant(-1d))) .poll(HttpPollConfig.forSensor(DISK_AVAILABLE) .suburl("/master/state.json") .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.castM(Long.class))) .onFailureOrException(Functions.constant(-1L))) .poll(HttpPollConfig.forSensor(MEMORY_USED) .suburl("/master/state.json") .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.castM(Long.class))) .onFailureOrException(Functions.constant(-1L))) .poll(HttpPollConfig.forSensor(CPU_USED) .suburl("/master/state.json") .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(),
@Test public void testPollsAndParsesHttpGetResponse() throws Exception { feed = HttpFeed.builder() .entity(entity) .baseUrl(baseUrl) .poll(HttpPollConfig.forSensor(SENSOR_INT) .period(100) .onSuccess(HttpValueFunctions.responseCode())) .poll(HttpPollConfig.forSensor(SENSOR_STRING) .period(100) .onSuccess(HttpValueFunctions.stringContentsFunction())) .build(); assertSensorEventually(SENSOR_INT, 200, TIMEOUT_MS); assertSensorEventually(SENSOR_STRING, "{\"foo\":\"myfoo\"}", TIMEOUT_MS); }
@Test(groups="Integration") // marked integration as it takes a wee while public void testStartSuspended() throws Exception { feed = HttpFeed.builder() .entity(entity) .baseUrl(baseUrl) .poll(HttpPollConfig.forSensor(SENSOR_INT) .period(100) .onSuccess(HttpValueFunctions.responseCode())) .poll(HttpPollConfig.forSensor(SENSOR_STRING) .period(100) .onSuccess(HttpValueFunctions.stringContentsFunction())) .suspended() .build(); Asserts.continually(MutableMap.of("timeout", 500), Entities.attributeSupplier(entity, SENSOR_INT), Predicates.<Integer>equalTo(null)); int countWhenSuspended = server.getRequestCount(); feed.resume(); Asserts.eventually(Entities.attributeSupplier(entity, SENSOR_INT), Predicates.<Integer>equalTo(200)); if (server.getRequestCount() <= countWhenSuspended) Assert.fail("Request count failed to increment when feed was resumed, from "+countWhenSuspended+", still at "+server.getRequestCount()); log.info("RUN: "+countWhenSuspended+" - "+server.getRequestCount()); }
@Override public void connectSensors() { super.connectSensors(); HttpFeed.Builder httpFeedBuilder = HttpFeed.builder() .entity(this) .period(2000, TimeUnit.MILLISECONDS) .baseUri(sensors().get(FRAMEWORK_URL)) .credentialsIfNotNull(config().get(MesosCluster.MESOS_USERNAME), config().get(MesosCluster.MESOS_PASSWORD)) .poll(HttpPollConfig.forSensor(MARATHON_APPLICATIONS) .suppressDuplicates(true) .suburl("/v2/apps/") .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.walk("apps"), JsonFunctions.forEach(JsonFunctions.<String>getPath("id")))) .onFailureOrException(Functions.constant(Arrays.asList(new String[0])))) .poll(HttpPollConfig.forSensor(MARATHON_VERSION) .suppressDuplicates(true) .suburl("/v2/info/") .onSuccess(HttpValueFunctions.jsonContents("version", String.class)) .onFailureOrException(Functions.constant(""))) .poll(HttpPollConfig.forSensor(SERVICE_UP) .suppressDuplicates(true) .suburl("/ping") .onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(Boolean.FALSE))); httpFeed = httpFeedBuilder.build(); }
@Override public void init() { super.init(); addFeed(HttpFeed.builder() .entity(this) .baseUrl(getConfig(BASE_URL)) .poll(HttpPollConfig.forSensor(SENSOR_INT) .period(POLL_PERIOD) .onSuccess(HttpValueFunctions.responseCode())) .poll(HttpPollConfig.forSensor(SENSOR_STRING) .period(POLL_PERIOD) .onSuccess(HttpValueFunctions.stringContentsFunction())) .build()); } }
.poll(HttpPollConfig.forSensor(MIRROR_SUMMARY).onSuccess(new MirrorSummary())).build();
.baseUri(sensors().get(Attributes.MAIN_URI)) .credentialsIfNotNull(config().get(MESOS_USERNAME), config().get(MESOS_PASSWORD)) .poll(HttpPollConfig.forSensor(SERVICE_UP) .suburl("/master/health") .onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onSuccess(HttpValueFunctions.jsonContents("mem_free_bytes", Long.class)) .onFailureOrException(Functions.constant(-1L))) .poll(HttpPollConfig.forSensor(MEMORY_TOTAL_BYTES) .suburl("/system/stats.json") .onSuccess(HttpValueFunctions.jsonContents("mem_total_bytes", Long.class)) .baseUri(sensors().get(Attributes.MAIN_URI)) .credentialsIfNotNull(config().get(MESOS_USERNAME), config().get(MESOS_PASSWORD)) .poll(HttpPollConfig.forSensor(MESOS_SLAVE_LIST) .description("Scan Cluster Slaves") .suburl("/master/state.json")
@Override public void connectSensors() { Duration scanInterval = config().get(MesosCluster.SCAN_INTERVAL); HttpFeed.Builder taskScanBuilder = HttpFeed.builder() .entity(this) .period(scanInterval) .baseUri(config().get(MesosCluster.MESOS_URL)) .credentialsIfNotNull(config().get(MesosCluster.MESOS_USERNAME), config().get(MesosCluster.MESOS_PASSWORD)) .poll(HttpPollConfig.forSensor(MESOS_TASK_LIST) .description("Scan Tasks") .suburl("/master/state.json") .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.walk("frameworks"), new Function<JsonElement, List<String>>() { @Override public List<String> apply(JsonElement frameworks) { return scanTasks(frameworks.getAsJsonArray()); } })) .onFailureOrException(Functions.<List<String>>constant(null))); taskScan = taskScanBuilder.build(); }