-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
66 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright © 2017-2021 Michael Weirauch ([email protected]) | ||
* Copyright © 2017-2022 Michael Weirauch ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -40,6 +40,10 @@ public ProcessMemoryMetrics() { | |
public void bindTo(MeterRegistry registry) { | ||
final KEY[] keys = { KEY.VSS, KEY.RSS, KEY.SWAP }; | ||
for (final KEY key : keys) { | ||
if (status.get(key) == -1D) { | ||
continue; | ||
} | ||
|
||
final String name = "process.memory." + key.name().toLowerCase(Locale.ENGLISH); | ||
Gauge.builder(name, status, statusRef -> value(key)) // | ||
.baseUnit("bytes") // | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright © 2017-2021 Michael Weirauch ([email protected]) | ||
* Copyright © 2017-2022 Michael Weirauch ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -55,7 +55,7 @@ public void testInstantiation() { | |
} | ||
|
||
@Test | ||
public void testGetMetrics() throws Exception { | ||
public void testGetMetrics() { | ||
when(status.get(KEY.VSS)).thenReturn(1D); | ||
when(status.get(KEY.RSS)).thenReturn(2D); | ||
when(status.get(KEY.SWAP)).thenReturn(3D); | ||
|
@@ -79,10 +79,27 @@ public void testGetMetrics() throws Exception { | |
assertEquals(3.0, swap.value(), 0.0); | ||
assertEquals(expectedUnit, swap.getId().getBaseUnit()); | ||
|
||
verify(status, times(3)).get(any(KEY.class)); | ||
assertEquals(3, registry.getMeters().size()); | ||
|
||
verify(status, times(6)).get(any(KEY.class)); | ||
verifyNoMoreInteractions(status); | ||
} | ||
|
||
assertEquals(3, registry.getMeters().size()); | ||
@Test | ||
public void testUnsupported() { | ||
when(status.get(KEY.VSS)).thenReturn(-1D); | ||
when(status.get(KEY.RSS)).thenReturn(-1D); | ||
when(status.get(KEY.SWAP)).thenReturn(-1D); | ||
|
||
final SimpleMeterRegistry registry = new SimpleMeterRegistry(); | ||
final ProcessMemoryMetrics uut = new ProcessMemoryMetrics(status); | ||
|
||
uut.bindTo(registry); | ||
|
||
assertEquals(0, registry.getMeters().size()); | ||
|
||
verify(status, times(3)).get(any(KEY.class)); | ||
verifyNoMoreInteractions(status); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters