package com.octoperf.metrics.windows.pdh;

import com.octoperf.metrics.service.api.GaugeService;
import com.octoperf.metrics.windows.pdh.api.PerfmonQueryService;
import com.octoperf.metrics.windows.pdh.api.WindowsProcessMetrics;
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import org.hyperic.sigar.win32.Pdh;
import org.hyperic.sigar.win32.Win32Exception;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.jmx.export.annotation.AnnotationMBeanExporter;
import org.springframework.stereotype.Component;

import javax.management.JMException;
import javax.management.ObjectName;

import static java.lang.String.format;
import static javax.management.ObjectName.quote;

@Component
@ConditionalOnBean(Pdh.class)
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
final class PdhProcesses {
  private static final String PROCESS = "Process";
  private static final String OBJECT_NAME = "Windows:type=%s,instance=%s";

  PdhProcesses(
    final PerfmonQueryService perfmon,
    final GaugeService gauges,
    final AnnotationMBeanExporter exporter) throws Win32Exception, JMException {
    super();

    for(final String instance : perfmon.getInstances(PROCESS)) {
      final ObjectName objectName = new ObjectName(format(OBJECT_NAME, PROCESS, quote(instance)));
      final WindowsProcessMetrics metric = new PdhProcessMetrics(perfmon, gauges, instance);
      exporter.registerManagedResource(metric, objectName);
    }
  }
}

@@ -222,16 +222,82 @@
 etrics;%0A
+import com.octoperf.metrics.windows.pdh.api.WindowsSystemMetrics;%0A
 import l
@@ -1145,16 +1145,55 @@
 gauges,%0A
+    final WindowsSystemMetrics system,%0A
     fina
@@ -1286,16 +1286,17 @@
 %0A    for
+ 
 (final S
@@ -1534,16 +1534,24 @@
 instance
+, system
 );%0A     

fix compilation issue