Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/650#discussion_r30615834
  
    --- Diff: 
core/src/main/java/brooklyn/event/feed/windows/WindowsPerformanceCounterFeed.java
 ---
    @@ -251,10 +258,71 @@ public T call() throws Exception {
             }
         }
     
    +    private static class SendPerfCountersToSensors implements 
PollHandler<WinRmToolResponse> {
    +
    +        private final EntityLocal entity;
    +        private final List<WindowsPerformanceCounterPollConfig<?>> polls;
    +
    +        public SendPerfCountersToSensors(EntityLocal entity, 
List<WindowsPerformanceCounterPollConfig<?>> polls) {
    +            this.entity = entity;
    +            this.polls = polls;
    +        }
    +
    +        @Override
    +        public boolean checkSuccess(WinRmToolResponse val) {
    +            if (val.getStatusCode() != 0) return false;
    +            String stderr = val.getStdErr();
    +            if (stderr == null || stderr.length() != 0) return false;
    +            String out = val.getStdOut();
    +            if (out == null || out.length() == 0) return false;
    +            return true;
    +        }
    +
    +        @Override
    +        public void onSuccess(WinRmToolResponse val) {
    +            String[] values = val.getStdOut().split("\r\n");
    +            for (int i = 0; i < polls.size(); i++) {
    +                Class<?> clazz = polls.get(i).getSensor().getType();
    +                Maybe<? extends Object> maybeValue = 
TypeCoercions.tryCoerce(values[i], TypeToken.of(clazz));
    +                Object value = maybeValue.isAbsent() ? null : 
maybeValue.get();
    +                AttributeSensor<Object> attribute = 
(AttributeSensor<Object>) Sensors.newSensor(clazz, 
polls.get(i).getSensor().getName(), polls.get(i).getDescription());
    +                entity.setAttribute(attribute, value);
    +            }
    +        }
    +
    +        @Override
    +        public void onFailure(WinRmToolResponse val) {
    +            log.error("Windows Performance Counter query did not respond 
as expected. exitcode={} stdout={} stderr={}",
    +                    new Object[]{val.getStatusCode(), val.getStdOut(), 
val.getStdErr()});
    +            for (WindowsPerformanceCounterPollConfig<?> config : polls) {
    +                
entity.setAttribute(Sensors.newSensor(config.getSensor().getClass(), 
config.getPerformanceCounterName(), config.getDescription()), null);
    --- End diff --
    
    Above (for `onSuccess`) we did `polls.get(i).getSensor().getName()`. Why 
are we using `config.getPerformanceCounterName()` here instead? Same below for 
`onException`.


---
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