Skip to content

Commit

Permalink
fix native memory tags, apply correct formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPaul-Perfana committed Jul 8, 2024
1 parent 61dae2c commit 0c99587
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
19 changes: 11 additions & 8 deletions src/main/java/io/perfana/jfr/event/NativeMemoryEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class NativeMemoryEvent implements OnJfrEvent, JfrEventProvider {
public static final String JDK_NATIVE_MEMORY_USAGE = "jdk.NativeMemoryUsage";
public static final String JDK_NATIVE_MEMORY_USAGE_TOTAL = "jdk.NativeMemoryUsageTotal";
public static final String JDK_RESIDENT_SET_SIZE = "jdk.ResidentSetSize";
public static final String FIELD_COMMITTED = "committed";
public static final String FIELD_RESERVED = "reserved";

private final JfrEventProcessor eventProcessor;

Expand Down Expand Up @@ -61,28 +63,29 @@ public void onEvent(RecordedEvent event) {
}

private ProcessedJfrEvent processNativeMemoryUsageTotal(RecordedEvent event) {
long reservedMemory = event.getLong("reserved");
long committedMemory = event.getLong("committed");
long reservedMemory = event.getLong(FIELD_RESERVED);
long committedMemory = event.getLong(FIELD_COMMITTED);

return ProcessedJfrEvent.of(
event.getStartTime(),
"memory-native-total",
"reserved",
FIELD_RESERVED,
reservedMemory,
Map.of("committed", committedMemory));
Map.of(FIELD_COMMITTED, committedMemory));
}

private ProcessedJfrEvent processNativeMemoryUsage(RecordedEvent event) {
long reservedMemory = event.getLong("reserved");
long committedMemory = event.getLong("committed");
long reservedMemory = event.getLong(FIELD_RESERVED);
long committedMemory = event.getLong(FIELD_COMMITTED);
String nmtType = event.getString("type");

return ProcessedJfrEvent.of(
event.getStartTime(),
"memory-native",
"reserved",
Map.of("type", nmtType),
FIELD_RESERVED,
reservedMemory,
Map.of("committed", committedMemory, "type", nmtType));
Map.of(FIELD_COMMITTED, committedMemory));
}

private ProcessedJfrEvent processResidentSetSize(RecordedEvent event) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/perfana/jfr/influx/InfluxWriterNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public void writeMetricPoint(ProcessedJfrEvent event) {

boolean useBuffer = true;


String dataToSend = key + " " + generatedFields + " " + timestampEpochNano;

if (useBuffer) {
Expand All @@ -125,7 +124,7 @@ public void writeMetricPoint(ProcessedJfrEvent event) {
}
else if (origTags.size() == 1) {
Map.Entry<String,String> entry = origTags.entrySet().iterator().next();
return "," + entry.getKey() + "=" + escapeFieldForInflux(entry.getValue());
return "," + entry.getKey() + "=" + escapeTagForInflux(entry.getValue());
}
else {
// tags are sorted alphabetically for better performance in InfluxDB
Expand Down

0 comments on commit 0c99587

Please sign in to comment.