Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double registration of process threads #117

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2017-2019 Michael Weirauch (michael.weirauch@gmail.com)
* Copyright © 2017-2021 Michael Weirauch (michael.weirauch@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@ public class ProcessMemoryMetrics implements MeterBinder {
private final ProcfsStatus status;

public ProcessMemoryMetrics() {
this.status = ProcfsStatus.getInstance();
this(ProcfsStatus.getInstance());
}

/* default */ ProcessMemoryMetrics(ProcfsStatus status) {
Expand All @@ -38,10 +38,11 @@ public ProcessMemoryMetrics() {

@Override
public void bindTo(MeterRegistry registry) {
for (final KEY key : KEY.values()) {
final KEY[] keys = { KEY.VSS, KEY.RSS, KEY.SWAP };
for (final KEY key : keys) {
final String name = "process.memory." + key.name().toLowerCase(Locale.ENGLISH);
Gauge.builder(name, status, statusRef -> value(key))//
.baseUnit("bytes")//
Gauge.builder(name, status, statusRef -> value(key)) //
.baseUnit("bytes") //
.register(registry);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2017-2019 Michael Weirauch (michael.weirauch@gmail.com)
* Copyright © 2017-2021 Michael Weirauch (michael.weirauch@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,7 @@ public class ProcessThreadMetrics implements MeterBinder {
private final ProcfsStatus status;

public ProcessThreadMetrics() {
this.status = ProcfsStatus.getInstance();
this(ProcfsStatus.getInstance());
}

/* default */ ProcessThreadMetrics(ProcfsStatus status) {
Expand All @@ -37,8 +37,8 @@ public ProcessThreadMetrics() {

@Override
public void bindTo(MeterRegistry registry) {
Gauge.builder("process.threads", status, statusRef -> value(KEY.THREADS))//
.description("The number of process threads")//
Gauge.builder("process.threads", status, statusRef -> value(KEY.THREADS)) //
.description("The number of process threads") //
.register(registry);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2017-2019 Michael Weirauch (michael.weirauch@gmail.com)
* Copyright © 2017-2021 Michael Weirauch (michael.weirauch@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -81,6 +81,8 @@ public void testGetMetrics() throws Exception {

verify(status, times(3)).get(any(KEY.class));
verifyNoMoreInteractions(status);

assertEquals(3, registry.getMeters().size());
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2017 Michael Weirauch (michael.weirauch@gmail.com)
* Copyright © 2017-2021 Michael Weirauch (michael.weirauch@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,6 +59,8 @@ public void testGetMetrics() throws Exception {
uut.bindTo(registry);

assertEquals(7D, registry.get("process.threads").gauge().value(), 0.0);

assertEquals(1, registry.getMeters().size());
}

}