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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to