brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e...
Date Tue, 21 Jun 2016 09:56:23 GMT
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.
---

Mime
View raw message