Skip to content

Commit 9aa4797

Browse files
authored
Merge pull request #1374 from microsoft/heya/clean-up-deprecated-perfcounter
Delete WindowsPerformanceCounterData & WindowsPerformanceCounterAsMetric
2 parents b6ec641 + 4f264b8 commit 9aa4797

11 files changed

+22
-564
lines changed

core/src/main/java/com/microsoft/applicationinsights/internal/perfcounter/ProcessBuiltInPerformanceCountersFactory.java

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@
3434
*
3535
* Created by gupele on 3/3/2015.
3636
*/
37-
final class ProcessBuiltInPerformanceCountersFactory implements PerformanceCountersFactory, WindowsPerformanceCountersFactory {
37+
final class ProcessBuiltInPerformanceCountersFactory implements PerformanceCountersFactory {
3838

3939
private static final Logger logger = LoggerFactory.getLogger(ProcessBuiltInPerformanceCountersFactory.class);
4040

41-
private Iterable<WindowsPerformanceCounterData> windowsPCsData;
42-
4341
/**
4442
* Creates the {@link com.microsoft.applicationinsights.internal.perfcounter.PerformanceCounter} that are
4543
* the 'built-in' performance counters of the process.
@@ -61,7 +59,8 @@ public Collection<PerformanceCounter> getPerformanceCounters() {
6159
throw td;
6260
} catch (Throwable t) {
6361
try {
64-
logger.error("Error while creating performance counters: '{}'", t.toString()); } catch (ThreadDeath td) {
62+
logger.error("Error while creating performance counters: '{}'", t.toString());
63+
} catch (ThreadDeath td) {
6564
throw td;
6665
} catch (Throwable t2) {
6766
// chomp
@@ -104,24 +103,6 @@ private Collection<PerformanceCounter> getUnixPerformanceCounters() {
104103
private Collection<PerformanceCounter> getWindowsPerformanceCounters() {
105104
ArrayList<PerformanceCounter> performanceCounters = getMutualPerformanceCounters();
106105

107-
try {
108-
if (windowsPCsData != null) {
109-
WindowsPerformanceCounterAsMetric pcWindowsMetric = new WindowsPerformanceCounterAsMetric(windowsPCsData);
110-
performanceCounters.add(pcWindowsMetric);
111-
windowsPCsData = null;
112-
}
113-
} catch (ThreadDeath td) {
114-
throw td;
115-
} catch (Throwable e) {
116-
try {
117-
logger.error("Failed to create WindowsPerformanceCounterAsMetric: '{}'", e.toString());
118-
} catch (ThreadDeath td) {
119-
throw td;
120-
} catch (Throwable t2) {
121-
// chomp
122-
}
123-
}
124-
125106
try {
126107
WindowsPerformanceCounterAsPC pcWindowsPCs = new WindowsPerformanceCounterAsPC();
127108
performanceCounters.add(pcWindowsPCs);
@@ -139,9 +120,4 @@ private Collection<PerformanceCounter> getWindowsPerformanceCounters() {
139120

140121
return performanceCounters;
141122
}
142-
143-
@Override
144-
public void setWindowsPCs(Iterable<WindowsPerformanceCounterData> windowsPCsData) {
145-
this.windowsPCsData = windowsPCsData;
146-
}
147123
}

core/src/main/java/com/microsoft/applicationinsights/internal/perfcounter/ProcessPerformanceCountersModule.java

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ public ProcessPerformanceCountersModule() throws Exception {
4444

4545
public ProcessPerformanceCountersModule(PerformanceCountersFactory factory) throws Exception {
4646
super(factory);
47-
48-
if (!(factory instanceof WindowsPerformanceCountersFactory)) {
49-
throw new Exception("Factory must implement windows capabilities.");
50-
}
5147
}
5248

5349
/**
@@ -75,34 +71,6 @@ public void addConfigurationData(PerformanceCountersXmlElement configuration) {
7571
return;
7672
}
7773

78-
ArrayList<WindowsPerformanceCounterData> configurationRequests = new ArrayList<WindowsPerformanceCounterData>();
79-
for (WindowsPerformanceCounterXmlElement element : windowsPCs) {
80-
try {
81-
WindowsPerformanceCounterData data =
82-
new WindowsPerformanceCounterData().
83-
setDisplayName(element.getDisplayName()).
84-
setCategoryName(element.getCategoryName()).
85-
setCounterName(element.getCounterName()).
86-
setInstanceName(element.getInstanceName());
87-
88-
configurationRequests.add(data);
89-
} catch (ThreadDeath td) {
90-
throw td;
91-
} catch (Throwable e) {
92-
try {
93-
logger.error("Failed to initialize Windows performance counter '{}'.", e.toString());
94-
} catch (ThreadDeath td) {
95-
throw td;
96-
} catch (Throwable t2) {
97-
// chomp
98-
}
99-
}
100-
}
101-
102-
if (configurationRequests.isEmpty()) {
103-
logger.error("Failed to initialize Windows performance counters: All requested performance counters are not valid.");
104-
} else {
105-
((WindowsPerformanceCountersFactory)factory).setWindowsPCs(configurationRequests);
106-
}
74+
throw new IllegalStateException("Custom performance counter metrics have been disabled for Java 3.0+ Agent.");
10775
}
10876
}

core/src/main/java/com/microsoft/applicationinsights/internal/perfcounter/WindowsPerformanceCounterAsMetric.java

Lines changed: 0 additions & 140 deletions
This file was deleted.

core/src/main/java/com/microsoft/applicationinsights/internal/perfcounter/WindowsPerformanceCounterAsPC.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@
2828
import com.microsoft.applicationinsights.TelemetryClient;
2929
import com.microsoft.applicationinsights.internal.system.SystemInformation;
3030
import com.microsoft.applicationinsights.telemetry.MetricTelemetry;
31-
import com.microsoft.applicationinsights.telemetry.PerformanceCounterTelemetry;
3231

3332
import com.google.common.base.Strings;
3433
import org.slf4j.Logger;
3534
import org.slf4j.LoggerFactory;
3635

3736
/**
38-
* Built-in Windows performance counters that are sent as {@link com.microsoft.applicationinsights.telemetry.PerformanceCounterTelemetry}
37+
* Built-in Windows performance counters that are sent as {@link com.microsoft.applicationinsights.telemetry.MetricTelemetry}
3938
*
4039
* Created by gupele on 3/30/2015.
4140
*/
@@ -45,8 +44,8 @@ public final class WindowsPerformanceCounterAsPC extends AbstractWindowsPerforma
4544

4645
private static final String ID = Constants.PERFORMANCE_COUNTER_PREFIX + "WindowsPerformanceCounterAsPC";
4746

48-
// Performance counter key and its data that is relevant when sending.
49-
private final HashMap<String, WindowsPerformanceCounterData> pcs = new HashMap<String, WindowsPerformanceCounterData>();
47+
// Performance counter key and its metric name that is relevant when sending.
48+
private final HashMap<String, String> pcs = new HashMap<String, String>();
5049

5150
/**
5251
* Registers the 'built-in' Windows performance counters that are not fetched from the JVM JMX.
@@ -69,23 +68,21 @@ public WindowsPerformanceCounterAsPC() throws Throwable {
6968

7069
@Override
7170
public void report(TelemetryClient telemetryClient) {
72-
for (Map.Entry<String, WindowsPerformanceCounterData> entry : pcs.entrySet()) {
71+
for (Map.Entry<String, String> entry : pcs.entrySet()) {
7372
try {
7473
double value = JniPCConnector.getValueOfPerformanceCounter(entry.getKey());
7574
if (value < 0) {
76-
reportError(value, entry.getValue().getDisplayName());
75+
reportError(value, entry.getValue());
7776
} else {
7877
send(telemetryClient, value, entry.getValue());
79-
WindowsPerformanceCounterData pcData = entry.getValue();
80-
logger.trace("Sent performance counter for '{}'({}, {}, {}): '{}'",
81-
pcData.getDisplayName(), pcData.getCategoryName(), pcData.getCounterName(), pcData.getInstanceName(), value);
78+
logger.trace("Sent performance counter for '{}': '{}'", entry.getValue(), value);
8279
}
8380
} catch (ThreadDeath td) {
8481
throw td;
8582
} catch (Throwable e) {
8683
try {
8784
if (logger.isErrorEnabled()) {
88-
logger.error("Failed to send performance counter for '{}'", entry.getValue().getDisplayName(), e);
85+
logger.error("Failed to send performance counter for '{}'", entry.getValue(), e);
8986
}
9087
} catch (ThreadDeath td) {
9188
throw td;
@@ -101,8 +98,8 @@ public String getId() {
10198
return ID;
10299
}
103100

104-
private void send(TelemetryClient telemetryClient, double value, WindowsPerformanceCounterData data) {
105-
MetricTelemetry telemetry = new MetricTelemetry(data.getDisplayName(), value);
101+
private void send(TelemetryClient telemetryClient, double value, String metricName) {
102+
MetricTelemetry telemetry = new MetricTelemetry(metricName, value);
106103
telemetryClient.track(telemetry);
107104
}
108105

@@ -117,12 +114,7 @@ private void register(String category, String counter, String instance, String m
117114
String key = JniPCConnector.addPerformanceCounter(category, counter, instance);
118115
if (!Strings.isNullOrEmpty(key)) {
119116
try {
120-
WindowsPerformanceCounterData data = new WindowsPerformanceCounterData().
121-
setCategoryName(category).
122-
setCounterName(counter).
123-
setInstanceName(instance).
124-
setDisplayName(metricName);
125-
pcs.put(key, data);
117+
pcs.put(key, metricName);
126118
} catch (ThreadDeath td) {
127119
throw td;
128120
} catch (Throwable e) {

0 commit comments

Comments
 (0)