protected void connectSensors()

in software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/redis/RedisStoreImpl.java [56:108]


    protected void connectSensors() {
        super.connectSensors();

        connectServiceUpIsRunning();

        // Find an SshMachineLocation for the UPTIME feed
        Optional<Location> location = Iterables.tryFind(getLocations(), Predicates.instanceOf(SshMachineLocation.class));
        if (!location.isPresent()) throw new IllegalStateException("Could not find SshMachineLocation in list of locations");
        SshMachineLocation machine = (SshMachineLocation) location.get();
        String statsCommand = getDriver().getRunDir() + "/bin/redis-cli -p " + getRedisPort() + " info stats";
        boolean retrieveUsageMetrics = getConfig(RETRIEVE_USAGE_METRICS);
        
        sshFeed = SshFeed.builder()
                .entity(this)
                .machine(machine)
                .period(5, TimeUnit.SECONDS)
                .poll(new SshPollConfig<Integer>(UPTIME)
                        .command(getDriver().getRunDir() + "/bin/redis-cli -p " + getRedisPort() + " info server")
                        .onFailureOrException(Functions.constant(-1))
                        .onSuccess(infoFunction("uptime_in_seconds"))
                        .enabled(retrieveUsageMetrics))
                .poll(new SshPollConfig<Integer>(TOTAL_CONNECTIONS_RECEIVED)
                        .command(statsCommand)
                        .onFailureOrException(Functions.constant(-1))
                        .onSuccess(infoFunction("total_connections_received"))
                        .enabled(retrieveUsageMetrics))
                .poll(new SshPollConfig<Integer>(TOTAL_COMMANDS_PROCESSED)
                        .command(statsCommand)
                        .onFailureOrException(Functions.constant(-1))
                        .onSuccess(infoFunction("total_commands_processed"))
                        .enabled(retrieveUsageMetrics))
                .poll(new SshPollConfig<Integer>(EXPIRED_KEYS)
                        .command(statsCommand)
                        .onFailureOrException(Functions.constant(-1))
                        .onSuccess(infoFunction("expired_keys"))
                        .enabled(retrieveUsageMetrics))
                .poll(new SshPollConfig<Integer>(EVICTED_KEYS)
                        .command(statsCommand)
                        .onFailureOrException(Functions.constant(-1))
                        .onSuccess(infoFunction("evicted_keys"))
                        .enabled(retrieveUsageMetrics))
                .poll(new SshPollConfig<Integer>(KEYSPACE_HITS)
                        .command(statsCommand)
                        .onFailureOrException(Functions.constant(-1))
                        .onSuccess(infoFunction("keyspace_hits"))
                        .enabled(retrieveUsageMetrics))
                .poll(new SshPollConfig<Integer>(KEYSPACE_MISSES)
                        .command(statsCommand)
                        .onFailureOrException(Functions.constant(-1))
                        .onSuccess(infoFunction("keyspace_misses"))
                        .enabled(retrieveUsageMetrics))
                .build();
    }