You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by grkvlt <gi...@git.apache.org> on 2016/06/16 08:12:13 UTC

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

GitHub user grkvlt opened a pull request:

    https://github.com/apache/brooklyn-server/pull/204

    Move machine metrics to SoftwareProcess entity

    Moves the sensor feed for machine metrics to the SoftwareProcess, controlled by a configuration key with default set to _false_ normally and _true_ for `MachineEntity`. Also contributes static helper methods for feed `PollConfig` creation.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/grkvlt/brooklyn-server move-machine-metrics

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/brooklyn-server/pull/204.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #204
    
----
commit 84b4d3fabd0d083d7ae4b6ab8faa7364467fa31a
Author: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Date:   2016-06-16T07:08:39Z

    Add static helper method to PollConfig objects

commit 4bb20b614f807cefb67bfa91a893760f5fdbbe42
Author: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Date:   2016-06-16T07:12:45Z

    Moved sensor feed for machine metrics to SoftwareProcess

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    Really happy with how the PR turned out btw, great changes!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67840071
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/machine/MachineEntityImpl.java ---
    @@ -18,126 +18,41 @@
      */
     package org.apache.brooklyn.entity.machine;
     
    -import java.util.List;
     import java.util.concurrent.TimeoutException;
     
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
    +
     import org.apache.brooklyn.core.effector.ssh.SshEffectorTasks;
     import org.apache.brooklyn.core.location.Machines;
     import org.apache.brooklyn.entity.software.base.AbstractSoftwareProcessSshDriver;
     import org.apache.brooklyn.entity.software.base.EmptySoftwareProcessDriver;
     import org.apache.brooklyn.entity.software.base.EmptySoftwareProcessImpl;
    -import org.apache.brooklyn.feed.ssh.SshFeed;
    -import org.apache.brooklyn.feed.ssh.SshPollConfig;
    -import org.apache.brooklyn.feed.ssh.SshPollValue;
     import org.apache.brooklyn.location.ssh.SshMachineLocation;
     import org.apache.brooklyn.util.core.task.DynamicTasks;
     import org.apache.brooklyn.util.core.task.system.ProcessTaskWrapper;
     import org.apache.brooklyn.util.exceptions.Exceptions;
    -import org.apache.brooklyn.util.text.Strings;
    +import org.apache.brooklyn.util.guava.Maybe;
     import org.apache.brooklyn.util.time.Duration;
     
    -import com.google.common.base.Function;
    -import com.google.common.base.Functions;
    -import com.google.common.base.Splitter;
    -
     public class MachineEntityImpl extends EmptySoftwareProcessImpl implements MachineEntity {
     
         private static final Logger LOG = LoggerFactory.getLogger(MachineEntityImpl.class);
     
    -    static {
    -        MachineAttributes.init();
    -    }
    -
    -    private transient SshFeed sensorFeed;
    -
         @Override
         public void init() {
             LOG.info("Starting server pool machine with id {}", getId());
    -        super.init();
    -    }
     
    -    @Override
    -    protected void connectSensors() {
    -        super.connectSensors();
    -
    -        // Sensors linux-specific
    -        if (!getMachine().getMachineDetails().getOsDetails().isLinux()) return;
    -
    -        sensorFeed = SshFeed.builder()
    -                .entity(this)
    -                .period(Duration.THIRTY_SECONDS)
    -                .poll(new SshPollConfig<Duration>(UPTIME)
    -                        .command("cat /proc/uptime")
    -                        .onFailureOrException(Functions.<Duration>constant(null))
    -                        .onSuccess(new Function<SshPollValue, Duration>() {
    -                            @Override
    -                            public Duration apply(SshPollValue input) {
    -                                return Duration.seconds( Double.valueOf( Strings.getFirstWord(input.getStdout()) ) );
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Double>(LOAD_AVERAGE)
    -                        .command("uptime")
    -                        .onFailureOrException(Functions.constant(-1d))
    -                        .onSuccess(new Function<SshPollValue, Double>() {
    -                            @Override
    -                            public Double apply(SshPollValue input) {
    -                                String loadAverage = Strings.getFirstWordAfter(input.getStdout(), "load average:").replace(",", "");
    -                                return Double.valueOf(loadAverage);
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Double>(CPU_USAGE)
    -                        .command("cat /proc/stat")
    -                        .onFailureOrException(Functions.constant(-1d))
    -                        .onSuccess(new Function<SshPollValue, Double>() {
    -                            @Override
    -                            public Double apply(SshPollValue input) {
    -                                List<String> cpuData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                Integer system = Integer.parseInt(cpuData.get(1));
    -                                Integer user = Integer.parseInt(cpuData.get(3));
    -                                Integer idle = Integer.parseInt(cpuData.get(4));
    -                                return (double) (system + user) / (double) (system + user + idle);
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(USED_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(2));
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(FREE_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(3));
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(TOTAL_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(1));
    -                            }
    -                        }))
    -                .build();
    -
    -    }
    +        Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(getLocations(), SshMachineLocation.class);
    +        if (location.isPresent() && location.get().getOsDetails().isLinux()) {
    +            LOG.info("Adding machine metrics feed and enrichers.");
    +            AddMachineMetrics.createMachineMetricsFeed(this);
    --- End diff --
    
    Having the feeds initialized here means that stopping and starting the entity won't start the feeds again. Better move them back to `connectSensors` while keeping `addMachineMetricsEnrichers` here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    LGTM. Will hold off merging so people get the chance to read and respond the dev@ mail.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67304808
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java ---
    @@ -85,15 +89,23 @@
      * It exposes sensors for service state (Lifecycle) and status (String), and for host info, log file location.
      */
     public abstract class SoftwareProcessImpl extends AbstractEntity implements SoftwareProcess, DriverDependentEntity {
    -    private static final Logger log = LoggerFactory.getLogger(SoftwareProcessImpl.class);
    -    
    +
    +    private static final Logger LOG = LoggerFactory.getLogger(SoftwareProcess.class);
    --- End diff --
    
    Did you remove the `Impl` suffix on purpose? I think we should keep it - it points to the file where the logging occurs.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    Not convinced. What happens when SshFeed can't find the machine on a stopped entity? Does it start logging errors or is that silently discarded?
    There's a similar problem on creation - `apply` is called just after `init`, so there's no machine available yet.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    @neykov the feeds are managed by `FeedSupport` in the entity - I think this should stop them, and also handle rebind


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    @neykov good feedback; will address your comments


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67668240
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/machine/MachineEntityImpl.java ---
    @@ -61,82 +51,17 @@ public void init() {
         @Override
         protected void connectSensors() {
             super.connectSensors();
    -
    -        // Sensors linux-specific
    -        if (!getMachine().getMachineDetails().getOsDetails().isLinux()) return;
    -
    -        sensorFeed = SshFeed.builder()
    -                .entity(this)
    -                .period(Duration.THIRTY_SECONDS)
    -                .poll(new SshPollConfig<Duration>(UPTIME)
    -                        .command("cat /proc/uptime")
    -                        .onFailureOrException(Functions.<Duration>constant(null))
    -                        .onSuccess(new Function<SshPollValue, Duration>() {
    -                            @Override
    -                            public Duration apply(SshPollValue input) {
    -                                return Duration.seconds( Double.valueOf( Strings.getFirstWord(input.getStdout()) ) );
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Double>(LOAD_AVERAGE)
    -                        .command("uptime")
    -                        .onFailureOrException(Functions.constant(-1d))
    -                        .onSuccess(new Function<SshPollValue, Double>() {
    -                            @Override
    -                            public Double apply(SshPollValue input) {
    -                                String loadAverage = Strings.getFirstWordAfter(input.getStdout(), "load average:").replace(",", "");
    -                                return Double.valueOf(loadAverage);
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Double>(CPU_USAGE)
    -                        .command("cat /proc/stat")
    -                        .onFailureOrException(Functions.constant(-1d))
    -                        .onSuccess(new Function<SshPollValue, Double>() {
    -                            @Override
    -                            public Double apply(SshPollValue input) {
    -                                List<String> cpuData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                Integer system = Integer.parseInt(cpuData.get(1));
    -                                Integer user = Integer.parseInt(cpuData.get(3));
    -                                Integer idle = Integer.parseInt(cpuData.get(4));
    -                                return (double) (system + user) / (double) (system + user + idle);
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(USED_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(2));
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(FREE_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(3));
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(TOTAL_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(1));
    -                            }
    -                        }))
    -                .build();
    -
    +        Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(getLocations(), SshMachineLocation.class);
    +        if (location.isPresent() && location.get().getOsDetails().isLinux()) {
    +            machineMetricsFeed = AddMachineMetrics.createMachineMetricsFeed(this);
    +            AddMachineMetrics.addMachineMetricsEnrichers(this);
    +        } else {
    +            LOG.warn("Not adding machine metrics feed as no suitable location available on entity");
    +        }
         }
     
    -    @Override
         public void disconnectSensors() {
    -        if (sensorFeed != null) sensorFeed.stop();
    +        if (machineMetricsFeed != null) machineMetricsFeed.stop();
    --- End diff --
    
    Could be removed now that feeds are stopped out of the box.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by ceeaspb <gi...@git.apache.org>.
Github user ceeaspb commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67308359
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java ---
    @@ -287,6 +299,89 @@ protected void postDriverStart() {
          */
         protected void connectSensors() {
             connectedSensors = true;
    +        boolean retrieveMachineMetrics = config().get(RETRIEVE_MACHINE_METRICS);
    +        if (retrieveMachineMetrics) connectMachineSensors();
    +    }
    +
    +    /**
    +     * Adds sensors returning details about the machine the process is running on.
    +     * <p>
    +     * The machine must be SSHable and running Linux.
    +     */
    +    protected void connectMachineSensors() {
    +        Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(getLocations(), SshMachineLocation.class);
    +        if (location.isPresent() && location.get().getOsDetails().isLinux()) {
    +            machineSensorFeed = SshFeed.builder()
    +                    .entity(this)
    +                    .period(Duration.THIRTY_SECONDS)
    +                    .poll(SshPollConfig.forSensor(UPTIME)
    +                            .command("cat /proc/uptime")
    +                            .onFailureOrException(Functions.<Duration>constant(null))
    +                            .onSuccess(new Function<SshPollValue, Duration>() {
    +                                @Override
    +                                public Duration apply(SshPollValue input) {
    +                                    return Duration.seconds( Double.valueOf( Strings.getFirstWord(input.getStdout()) ) );
    +                                }
    +                            }))
    +                    .poll(SshPollConfig.forSensor(LOAD_AVERAGE)
    +                            .command("uptime")
    +                            .onFailureOrException(Functions.constant(-1d))
    +                            .onSuccess(new Function<SshPollValue, Double>() {
    +                                @Override
    +                                public Double apply(SshPollValue input) {
    +                                    String loadAverage = Strings.getFirstWordAfter(input.getStdout(), "load average:").replace(",", "");
    +                                    return Double.valueOf(loadAverage);
    +                                }
    +                            }))
    +                    .poll(SshPollConfig.forSensor(CPU_USAGE)
    +                            .command("cat /proc/stat")
    --- End diff --
    
    A problem with the cpu stats is that they are avarage since boot time, not since the last feed poll [ .period(Duration.THIRTY_SECONDS) ]
    likely a separate issue but can we change this so it only accounts for usage since the last poll. It would require maintaining the counters as at the last poll time to calculate the difference.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    Looks like Brooklyn will handle starting them (on [creation](https://github.com/apache/brooklyn-server/blob/master/core/src/main/java/org/apache/brooklyn/feed/ssh/SshFeed.java#L168) and on [rebind](https://github.com/apache/brooklyn-server/blob/master/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java#L169)). But looks like they are not stopped as part of the entity lifecycle - couldn't find anything in the sources.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    @Graeme-Miller I have updated, rebased, and fixed tests; will merge with master now.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67305518
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java ---
    @@ -373,6 +468,8 @@ protected void postRestart() {
          */
         protected void disconnectSensors() {
             connectedSensors = false;
    +        boolean retrieveMachineMetrics = config().get(RETRIEVE_MACHINE_METRICS);
    +        if (retrieveMachineMetrics) disconnectMachineSensors();
    --- End diff --
    
    (minor) I'd always call that and depend on the null check inside.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67667163
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java ---
    @@ -1737,7 +1738,6 @@ public boolean removeAllPolicies() {
          * {@link BasicEnricherSupport}.
          */
         @Beta
    -    // TODO revert to private when config() is reverted to return SensorSupportInternal
    --- End diff --
    
    I believe this still needs to be addressed, though the comment has copy&paste error referring to sensors.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67902133
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/machine/MachineEntityImpl.java ---
    @@ -18,126 +18,41 @@
      */
     package org.apache.brooklyn.entity.machine;
     
    -import java.util.List;
     import java.util.concurrent.TimeoutException;
     
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
    +
     import org.apache.brooklyn.core.effector.ssh.SshEffectorTasks;
     import org.apache.brooklyn.core.location.Machines;
     import org.apache.brooklyn.entity.software.base.AbstractSoftwareProcessSshDriver;
     import org.apache.brooklyn.entity.software.base.EmptySoftwareProcessDriver;
     import org.apache.brooklyn.entity.software.base.EmptySoftwareProcessImpl;
    -import org.apache.brooklyn.feed.ssh.SshFeed;
    -import org.apache.brooklyn.feed.ssh.SshPollConfig;
    -import org.apache.brooklyn.feed.ssh.SshPollValue;
     import org.apache.brooklyn.location.ssh.SshMachineLocation;
     import org.apache.brooklyn.util.core.task.DynamicTasks;
     import org.apache.brooklyn.util.core.task.system.ProcessTaskWrapper;
     import org.apache.brooklyn.util.exceptions.Exceptions;
    -import org.apache.brooklyn.util.text.Strings;
    +import org.apache.brooklyn.util.guava.Maybe;
     import org.apache.brooklyn.util.time.Duration;
     
    -import com.google.common.base.Function;
    -import com.google.common.base.Functions;
    -import com.google.common.base.Splitter;
    -
     public class MachineEntityImpl extends EmptySoftwareProcessImpl implements MachineEntity {
     
         private static final Logger LOG = LoggerFactory.getLogger(MachineEntityImpl.class);
     
    -    static {
    -        MachineAttributes.init();
    -    }
    -
    -    private transient SshFeed sensorFeed;
    -
         @Override
         public void init() {
             LOG.info("Starting server pool machine with id {}", getId());
    -        super.init();
    -    }
     
    -    @Override
    -    protected void connectSensors() {
    -        super.connectSensors();
    -
    -        // Sensors linux-specific
    -        if (!getMachine().getMachineDetails().getOsDetails().isLinux()) return;
    -
    -        sensorFeed = SshFeed.builder()
    -                .entity(this)
    -                .period(Duration.THIRTY_SECONDS)
    -                .poll(new SshPollConfig<Duration>(UPTIME)
    -                        .command("cat /proc/uptime")
    -                        .onFailureOrException(Functions.<Duration>constant(null))
    -                        .onSuccess(new Function<SshPollValue, Duration>() {
    -                            @Override
    -                            public Duration apply(SshPollValue input) {
    -                                return Duration.seconds( Double.valueOf( Strings.getFirstWord(input.getStdout()) ) );
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Double>(LOAD_AVERAGE)
    -                        .command("uptime")
    -                        .onFailureOrException(Functions.constant(-1d))
    -                        .onSuccess(new Function<SshPollValue, Double>() {
    -                            @Override
    -                            public Double apply(SshPollValue input) {
    -                                String loadAverage = Strings.getFirstWordAfter(input.getStdout(), "load average:").replace(",", "");
    -                                return Double.valueOf(loadAverage);
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Double>(CPU_USAGE)
    -                        .command("cat /proc/stat")
    -                        .onFailureOrException(Functions.constant(-1d))
    -                        .onSuccess(new Function<SshPollValue, Double>() {
    -                            @Override
    -                            public Double apply(SshPollValue input) {
    -                                List<String> cpuData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                Integer system = Integer.parseInt(cpuData.get(1));
    -                                Integer user = Integer.parseInt(cpuData.get(3));
    -                                Integer idle = Integer.parseInt(cpuData.get(4));
    -                                return (double) (system + user) / (double) (system + user + idle);
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(USED_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(2));
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(FREE_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(3));
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(TOTAL_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(1));
    -                            }
    -                        }))
    -                .build();
    -
    -    }
    +        Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(getLocations(), SshMachineLocation.class);
    +        if (location.isPresent() && location.get().getOsDetails().isLinux()) {
    +            LOG.info("Adding machine metrics feed and enrichers.");
    +            AddMachineMetrics.createMachineMetricsFeed(this);
    --- End diff --
    
    OK, good point. I didn't want to duplicate the `SshMachineLocation` check and was in a hurry ;(


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    Will merge after moving enricher creation to `init` method.
    
    Stopping feeds in the stop effector feels like the right thing to do. This is the practice we follow in connect/disconnectSensors and having this done out of the box will simplify entity implementations. Still think feeds need some more attention in future PRs, especially around creation. Currently we create the feeds even if it's already added to the entity (and try to handle duplicates gracefully). Rebind will start the feeds without taking into consideration the entity state. Overall feels like feed workflow needs cleanup.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by Graeme-Miller <gi...@git.apache.org>.
Github user Graeme-Miller commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67863025
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java ---
    @@ -709,9 +710,11 @@ protected void doStop(ConfigBag parameters, Callable<StopMachineDetails<Integer>
             DynamicTasks.queue("pre-stop", new PreStopCustomTask());
     
             Maybe<MachineLocation> machine = Machines.findUniqueMachineLocation(entity().getLocations());
    -        Task<String> stoppingProcess = null;
    +        Task<List<?>> stoppingProcess = null;
             if (canStop(stopProcessMode, entity())) {
    -            stoppingProcess = DynamicTasks.queue("stopping (process)", new StopProcessesAtMachineTask());
    +            stoppingProcess = Tasks.parallel(
    --- End diff --
    
    Aled and I debugged the hanging test today and narrowed it down to this line. The stoppingProcess task is created, but never started.
    
    The following code can be used instead:
    `
    stoppingProcess = Tasks.parallel(
                        Tasks.<String>builder().displayName("stopping (process)").body(new StopProcessesAtMachineTask()).build(),
                        Tasks.<String>builder().displayName("stopping (feeds)").body(new StopFeedsAtMachineTask()).build());
                DynamicTasks.queue(stoppingProcess);
    `


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    @neykov see last commit, feeds are now stopped when software process stops, using a new task.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/brooklyn-server/pull/204


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67669549
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/machine/MachineEntityImpl.java ---
    @@ -61,82 +51,17 @@ public void init() {
         @Override
         protected void connectSensors() {
             super.connectSensors();
    -
    -        // Sensors linux-specific
    -        if (!getMachine().getMachineDetails().getOsDetails().isLinux()) return;
    -
    -        sensorFeed = SshFeed.builder()
    -                .entity(this)
    -                .period(Duration.THIRTY_SECONDS)
    -                .poll(new SshPollConfig<Duration>(UPTIME)
    -                        .command("cat /proc/uptime")
    -                        .onFailureOrException(Functions.<Duration>constant(null))
    -                        .onSuccess(new Function<SshPollValue, Duration>() {
    -                            @Override
    -                            public Duration apply(SshPollValue input) {
    -                                return Duration.seconds( Double.valueOf( Strings.getFirstWord(input.getStdout()) ) );
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Double>(LOAD_AVERAGE)
    -                        .command("uptime")
    -                        .onFailureOrException(Functions.constant(-1d))
    -                        .onSuccess(new Function<SshPollValue, Double>() {
    -                            @Override
    -                            public Double apply(SshPollValue input) {
    -                                String loadAverage = Strings.getFirstWordAfter(input.getStdout(), "load average:").replace(",", "");
    -                                return Double.valueOf(loadAverage);
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Double>(CPU_USAGE)
    -                        .command("cat /proc/stat")
    -                        .onFailureOrException(Functions.constant(-1d))
    -                        .onSuccess(new Function<SshPollValue, Double>() {
    -                            @Override
    -                            public Double apply(SshPollValue input) {
    -                                List<String> cpuData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                Integer system = Integer.parseInt(cpuData.get(1));
    -                                Integer user = Integer.parseInt(cpuData.get(3));
    -                                Integer idle = Integer.parseInt(cpuData.get(4));
    -                                return (double) (system + user) / (double) (system + user + idle);
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(USED_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(2));
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(FREE_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(3));
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(TOTAL_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(1));
    -                            }
    -                        }))
    -                .build();
    -
    +        Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(getLocations(), SshMachineLocation.class);
    +        if (location.isPresent() && location.get().getOsDetails().isLinux()) {
    +            machineMetricsFeed = AddMachineMetrics.createMachineMetricsFeed(this);
    +            AddMachineMetrics.addMachineMetricsEnrichers(this);
    --- End diff --
    
    Move this to the `init` method - don't want enrichers added on each startup.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    Couldn't figure out how feeds get stopped with the enricher? What about starting when rebind is involved? `connectSensors` is called on rebind so that took care of it before.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    @neykov it just doesn't do anything (well, throws an exception and returns `null`) until it can actually SSH


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67902204
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java ---
    @@ -709,9 +710,11 @@ protected void doStop(ConfigBag parameters, Callable<StopMachineDetails<Integer>
             DynamicTasks.queue("pre-stop", new PreStopCustomTask());
     
             Maybe<MachineLocation> machine = Machines.findUniqueMachineLocation(entity().getLocations());
    -        Task<String> stoppingProcess = null;
    +        Task<List<?>> stoppingProcess = null;
             if (canStop(stopProcessMode, entity())) {
    -            stoppingProcess = DynamicTasks.queue("stopping (process)", new StopProcessesAtMachineTask());
    +            stoppingProcess = Tasks.parallel(
    --- End diff --
    
    Of course! That's easily fixed - will do that.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by Graeme-Miller <gi...@git.apache.org>.
Github user Graeme-Miller commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67338633
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java ---
    @@ -85,15 +81,20 @@
      * It exposes sensors for service state (Lifecycle) and status (String), and for host info, log file location.
      */
     public abstract class SoftwareProcessImpl extends AbstractEntity implements SoftwareProcess, DriverDependentEntity {
    -    private static final Logger log = LoggerFactory.getLogger(SoftwareProcessImpl.class);
    -    
    +
    +    private static final Logger LOG = LoggerFactory.getLogger(SoftwareProcessImpl.class);
    +
    +    static {
    +        MachineAttributes.init();
    --- End diff --
    
    do we need to call init, if we are already calling it in AddMachineMetrics?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    Tested on various clouds and works well as input to an `AutoScalerPolicy` 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    Still needs a bit of testing done with deployed clusters


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by ceeaspb <gi...@git.apache.org>.
Github user ceeaspb commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67323169
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java ---
    @@ -287,6 +299,89 @@ protected void postDriverStart() {
          */
         protected void connectSensors() {
             connectedSensors = true;
    +        boolean retrieveMachineMetrics = config().get(RETRIEVE_MACHINE_METRICS);
    +        if (retrieveMachineMetrics) connectMachineSensors();
    +    }
    +
    +    /**
    +     * Adds sensors returning details about the machine the process is running on.
    +     * <p>
    +     * The machine must be SSHable and running Linux.
    +     */
    +    protected void connectMachineSensors() {
    +        Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(getLocations(), SshMachineLocation.class);
    +        if (location.isPresent() && location.get().getOsDetails().isLinux()) {
    +            machineSensorFeed = SshFeed.builder()
    +                    .entity(this)
    +                    .period(Duration.THIRTY_SECONDS)
    +                    .poll(SshPollConfig.forSensor(UPTIME)
    +                            .command("cat /proc/uptime")
    +                            .onFailureOrException(Functions.<Duration>constant(null))
    +                            .onSuccess(new Function<SshPollValue, Duration>() {
    +                                @Override
    +                                public Duration apply(SshPollValue input) {
    +                                    return Duration.seconds( Double.valueOf( Strings.getFirstWord(input.getStdout()) ) );
    +                                }
    +                            }))
    +                    .poll(SshPollConfig.forSensor(LOAD_AVERAGE)
    +                            .command("uptime")
    +                            .onFailureOrException(Functions.constant(-1d))
    +                            .onSuccess(new Function<SshPollValue, Double>() {
    +                                @Override
    +                                public Double apply(SshPollValue input) {
    +                                    String loadAverage = Strings.getFirstWordAfter(input.getStdout(), "load average:").replace(",", "");
    +                                    return Double.valueOf(loadAverage);
    +                                }
    +                            }))
    +                    .poll(SshPollConfig.forSensor(CPU_USAGE)
    +                            .command("cat /proc/stat")
    +                            .onFailureOrException(Functions.constant(-1d))
    +                            .onSuccess(new Function<SshPollValue, Double>() {
    +                                @Override
    +                                public Double apply(SshPollValue input) {
    +                                    List<String> cpuData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    +                                    Integer system = Integer.parseInt(cpuData.get(1));
    +                                    Integer user = Integer.parseInt(cpuData.get(3));
    +                                    Integer idle = Integer.parseInt(cpuData.get(4));
    +                                    return (double) (system + user) / (double) (system + user + idle);
    --- End diff --
    
    the divisor total time is missing some fields new in 2.6.3* and later kernels, eg. see 
    http://procps.cvs.sourceforge.net/viewvc/procps/procps/vmstat.c
    eg.
    Div= duse+dsys+didl+diow+dstl;


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67669494
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/machine/MachineEntityImpl.java ---
    @@ -61,82 +51,17 @@ public void init() {
         @Override
         protected void connectSensors() {
             super.connectSensors();
    -
    -        // Sensors linux-specific
    -        if (!getMachine().getMachineDetails().getOsDetails().isLinux()) return;
    -
    -        sensorFeed = SshFeed.builder()
    -                .entity(this)
    -                .period(Duration.THIRTY_SECONDS)
    -                .poll(new SshPollConfig<Duration>(UPTIME)
    -                        .command("cat /proc/uptime")
    -                        .onFailureOrException(Functions.<Duration>constant(null))
    -                        .onSuccess(new Function<SshPollValue, Duration>() {
    -                            @Override
    -                            public Duration apply(SshPollValue input) {
    -                                return Duration.seconds( Double.valueOf( Strings.getFirstWord(input.getStdout()) ) );
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Double>(LOAD_AVERAGE)
    -                        .command("uptime")
    -                        .onFailureOrException(Functions.constant(-1d))
    -                        .onSuccess(new Function<SshPollValue, Double>() {
    -                            @Override
    -                            public Double apply(SshPollValue input) {
    -                                String loadAverage = Strings.getFirstWordAfter(input.getStdout(), "load average:").replace(",", "");
    -                                return Double.valueOf(loadAverage);
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Double>(CPU_USAGE)
    -                        .command("cat /proc/stat")
    -                        .onFailureOrException(Functions.constant(-1d))
    -                        .onSuccess(new Function<SshPollValue, Double>() {
    -                            @Override
    -                            public Double apply(SshPollValue input) {
    -                                List<String> cpuData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                Integer system = Integer.parseInt(cpuData.get(1));
    -                                Integer user = Integer.parseInt(cpuData.get(3));
    -                                Integer idle = Integer.parseInt(cpuData.get(4));
    -                                return (double) (system + user) / (double) (system + user + idle);
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(USED_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(2));
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(FREE_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(3));
    -                            }
    -                        }))
    -                .poll(new SshPollConfig<Long>(TOTAL_MEMORY)
    -                        .command("free | grep Mem:")
    -                        .onFailureOrException(Functions.constant(-1L))
    -                        .onSuccess(new Function<SshPollValue, Long>() {
    -                            @Override
    -                            public Long apply(SshPollValue input) {
    -                                List<String> memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout()));
    -                                return Long.parseLong(memoryData.get(1));
    -                            }
    -                        }))
    -                .build();
    -
    +        Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(getLocations(), SshMachineLocation.class);
    +        if (location.isPresent() && location.get().getOsDetails().isLinux()) {
    +            machineMetricsFeed = AddMachineMetrics.createMachineMetricsFeed(this);
    --- End diff --
    
    This will add the feeds multiple times, on each start. It's a problem with the original code as well. We have checks in place to prevent actually having multiple instances of the same feed, so it's not a problem in practice. Feels like feeds API needs a cleanup.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67329989
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java ---
    @@ -287,6 +299,89 @@ protected void postDriverStart() {
          */
         protected void connectSensors() {
             connectedSensors = true;
    +        boolean retrieveMachineMetrics = config().get(RETRIEVE_MACHINE_METRICS);
    +        if (retrieveMachineMetrics) connectMachineSensors();
    +    }
    +
    +    /**
    +     * Adds sensors returning details about the machine the process is running on.
    +     * <p>
    +     * The machine must be SSHable and running Linux.
    +     */
    +    protected void connectMachineSensors() {
    +        Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(getLocations(), SshMachineLocation.class);
    +        if (location.isPresent() && location.get().getOsDetails().isLinux()) {
    +            machineSensorFeed = SshFeed.builder()
    +                    .entity(this)
    +                    .period(Duration.THIRTY_SECONDS)
    +                    .poll(SshPollConfig.forSensor(UPTIME)
    +                            .command("cat /proc/uptime")
    +                            .onFailureOrException(Functions.<Duration>constant(null))
    +                            .onSuccess(new Function<SshPollValue, Duration>() {
    +                                @Override
    +                                public Duration apply(SshPollValue input) {
    +                                    return Duration.seconds( Double.valueOf( Strings.getFirstWord(input.getStdout()) ) );
    +                                }
    +                            }))
    +                    .poll(SshPollConfig.forSensor(LOAD_AVERAGE)
    +                            .command("uptime")
    +                            .onFailureOrException(Functions.constant(-1d))
    +                            .onSuccess(new Function<SshPollValue, Double>() {
    +                                @Override
    +                                public Double apply(SshPollValue input) {
    +                                    String loadAverage = Strings.getFirstWordAfter(input.getStdout(), "load average:").replace(",", "");
    +                                    return Double.valueOf(loadAverage);
    +                                }
    +                            }))
    +                    .poll(SshPollConfig.forSensor(CPU_USAGE)
    +                            .command("cat /proc/stat")
    --- End diff --
    
    @ceeaspb I changed this to a command that sums the CPU field of the `ps` output, which should work on almost all Linux machines


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    @neykov the feed stopping should be addressed in another PR I think?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #204: Move machine metrics to SoftwareProcess entity

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/204
  
    Configure an entity to use the machine metrics as follows:
    
    ```YAML
    services:
      - type: org.apache.brooklyn.entity.software.base.EmptySoftwareProcess
        brooklyn.initializers:
          - type: org.apache.brooklyn.entity.machine.AddMachineMetrics
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...

Posted by ceeaspb <gi...@git.apache.org>.
Github user ceeaspb commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/204#discussion_r67339178
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java ---
    @@ -287,6 +299,89 @@ protected void postDriverStart() {
          */
         protected void connectSensors() {
             connectedSensors = true;
    +        boolean retrieveMachineMetrics = config().get(RETRIEVE_MACHINE_METRICS);
    +        if (retrieveMachineMetrics) connectMachineSensors();
    +    }
    +
    +    /**
    +     * Adds sensors returning details about the machine the process is running on.
    +     * <p>
    +     * The machine must be SSHable and running Linux.
    +     */
    +    protected void connectMachineSensors() {
    +        Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(getLocations(), SshMachineLocation.class);
    +        if (location.isPresent() && location.get().getOsDetails().isLinux()) {
    +            machineSensorFeed = SshFeed.builder()
    +                    .entity(this)
    +                    .period(Duration.THIRTY_SECONDS)
    +                    .poll(SshPollConfig.forSensor(UPTIME)
    +                            .command("cat /proc/uptime")
    +                            .onFailureOrException(Functions.<Duration>constant(null))
    +                            .onSuccess(new Function<SshPollValue, Duration>() {
    +                                @Override
    +                                public Duration apply(SshPollValue input) {
    +                                    return Duration.seconds( Double.valueOf( Strings.getFirstWord(input.getStdout()) ) );
    +                                }
    +                            }))
    +                    .poll(SshPollConfig.forSensor(LOAD_AVERAGE)
    +                            .command("uptime")
    +                            .onFailureOrException(Functions.constant(-1d))
    +                            .onSuccess(new Function<SshPollValue, Double>() {
    +                                @Override
    +                                public Double apply(SshPollValue input) {
    +                                    String loadAverage = Strings.getFirstWordAfter(input.getStdout(), "load average:").replace(",", "");
    +                                    return Double.valueOf(loadAverage);
    +                                }
    +                            }))
    +                    .poll(SshPollConfig.forSensor(CPU_USAGE)
    +                            .command("cat /proc/stat")
    --- End diff --
    
    @grkvlt ok thanks
    on review, ps averages the cpu since process start time.
    It also caps the utilisation at 99% I think even if the %age is per cpu core, I'd have to check that though.
    
    http://procps.cvs.sourceforge.net/viewvc/procps/procps/ps/display.c?revision=1.32&content-type=text%2Fplain
      used_jiffies = buf->utime + buf->stime;
      if(include_dead_children) used_jiffies += (buf->cutime + buf->cstime);
      seconds = seconds_since_boot - buf->start_time / Hertz;
      if(seconds) pcpu = (used_jiffies * 1000ULL / Hertz) / seconds;


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---