Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 890B9200B16 for ; Mon, 20 Jun 2016 12:33:43 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 87CFB160A55; Mon, 20 Jun 2016 10:33:43 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D05B3160A24 for ; Mon, 20 Jun 2016 12:33:42 +0200 (CEST) Received: (qmail 92691 invoked by uid 500); 20 Jun 2016 10:33:42 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 92669 invoked by uid 99); 20 Jun 2016 10:33:41 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Jun 2016 10:33:41 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5E34DDFC6F; Mon, 20 Jun 2016 10:33:41 +0000 (UTC) From: neykov To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #204: Move machine metrics to SoftwareProcess e... Content-Type: text/plain Message-Id: <20160620103341.5E34DDFC6F@git1-us-west.apache.org> Date: Mon, 20 Jun 2016 10:33:41 +0000 (UTC) archived-at: Mon, 20 Jun 2016 10:33:43 -0000 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(UPTIME) - .command("cat /proc/uptime") - .onFailureOrException(Functions.constant(null)) - .onSuccess(new Function() { - @Override - public Duration apply(SshPollValue input) { - return Duration.seconds( Double.valueOf( Strings.getFirstWord(input.getStdout()) ) ); - } - })) - .poll(new SshPollConfig(LOAD_AVERAGE) - .command("uptime") - .onFailureOrException(Functions.constant(-1d)) - .onSuccess(new Function() { - @Override - public Double apply(SshPollValue input) { - String loadAverage = Strings.getFirstWordAfter(input.getStdout(), "load average:").replace(",", ""); - return Double.valueOf(loadAverage); - } - })) - .poll(new SshPollConfig(CPU_USAGE) - .command("cat /proc/stat") - .onFailureOrException(Functions.constant(-1d)) - .onSuccess(new Function() { - @Override - public Double apply(SshPollValue input) { - List 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(USED_MEMORY) - .command("free | grep Mem:") - .onFailureOrException(Functions.constant(-1L)) - .onSuccess(new Function() { - @Override - public Long apply(SshPollValue input) { - List memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout())); - return Long.parseLong(memoryData.get(2)); - } - })) - .poll(new SshPollConfig(FREE_MEMORY) - .command("free | grep Mem:") - .onFailureOrException(Functions.constant(-1L)) - .onSuccess(new Function() { - @Override - public Long apply(SshPollValue input) { - List memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout())); - return Long.parseLong(memoryData.get(3)); - } - })) - .poll(new SshPollConfig(TOTAL_MEMORY) - .command("free | grep Mem:") - .onFailureOrException(Functions.constant(-1L)) - .onSuccess(new Function() { - @Override - public Long apply(SshPollValue input) { - List memoryData = Splitter.on(" ").omitEmptyStrings().splitToList(Strings.getFirstLine(input.getStdout())); - return Long.parseLong(memoryData.get(1)); - } - })) - .build(); - + Maybe 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. ---