Skip to content

Commit

Permalink
Add support for collecting metrics on a node
Browse files Browse the repository at this point in the history
This commit adds all the necessary bits to expose REST endpoints to retrieve tpstats, dropped messages and client requests metrics for a specific node.
  • Loading branch information
adejanovski committed Aug 2, 2018
1 parent 13732fb commit 438ed51
Show file tree
Hide file tree
Showing 14 changed files with 1,413 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/server/src/main/java/io/cassandrareaper/AppContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package io.cassandrareaper;

import io.cassandrareaper.jmx.JmxConnectionFactory;
import io.cassandrareaper.service.MetricsGrabber;
import io.cassandrareaper.service.PurgeManager;
import io.cassandrareaper.service.RepairManager;
import io.cassandrareaper.service.SnapshotManager;
Expand Down Expand Up @@ -48,6 +49,7 @@ public final class AppContext {
public MetricRegistry metricRegistry = new MetricRegistry();
public SnapshotManager snapshotManager;
public PurgeManager purgeManager;
public MetricsGrabber metricsGrabber;

private static String initialiseInstanceAddress() {
String reaperInstanceAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.cassandrareaper.jmx.JmxConnectionFactory;
import io.cassandrareaper.jmx.JmxConnectionsInitializer;
import io.cassandrareaper.resources.ClusterResource;
import io.cassandrareaper.resources.NodeStatsResource;
import io.cassandrareaper.resources.PingResource;
import io.cassandrareaper.resources.ReaperHealthCheck;
import io.cassandrareaper.resources.RepairRunResource;
Expand All @@ -27,6 +28,7 @@
import io.cassandrareaper.resources.auth.LoginResource;
import io.cassandrareaper.resources.auth.ShiroExceptionMapper;
import io.cassandrareaper.service.AutoSchedulingManager;
import io.cassandrareaper.service.MetricsGrabber;
import io.cassandrareaper.service.PurgeManager;
import io.cassandrareaper.service.RepairManager;
import io.cassandrareaper.service.SchedulingManager;
Expand Down Expand Up @@ -158,6 +160,9 @@ public void run(ReaperApplicationConfiguration config, Environment environment)
context,
environment.lifecycle().executorService("SnapshotManager").minThreads(5).maxThreads(5).build());

context.snapshotManager = SnapshotManager.create(context);
context.metricsGrabber = MetricsGrabber.create(context);

int repairThreads = config.getRepairRunThreadCount();
LOG.info("initializing runner thread pool with {} threads", repairThreads);

Expand Down Expand Up @@ -235,6 +240,9 @@ public void run(ReaperApplicationConfiguration config, Environment environment)
final SnapshotResource snapshotResource = new SnapshotResource(context);
environment.jersey().register(snapshotResource);

final NodeStatsResource nodeStatsResource = new NodeStatsResource(context);
environment.jersey().register(nodeStatsResource);

if (config.isAccessControlEnabled()) {
SessionHandler sessionHandler = new SessionHandler();
sessionHandler.setMaxInactiveInterval((int) config.getAccessControl().getSessionTimeout().getSeconds());
Expand Down
112 changes: 112 additions & 0 deletions src/server/src/main/java/io/cassandrareaper/core/DroppedMessages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.cassandrareaper.core;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

@JsonDeserialize(builder = DroppedMessages.Builder.class)
public final class DroppedMessages {
private final String name;
private final Integer count;
private final Double oneMinuteRate;
private final Double fiveMinuteRate;
private final Double fifteenMinuteRate;
private final Double meanRate;

private DroppedMessages(Builder builder) {
this.name = builder.name;
this.count = builder.count;
this.oneMinuteRate = builder.oneMinuteRate;
this.fiveMinuteRate = builder.fiveMinuteRate;
this.fifteenMinuteRate = builder.fifteenMinuteRate;
this.meanRate = builder.meanRate;
}

public String getName() {
return name;
}

public Integer getCount() {
return count;
}

public Double getOneMinuteRate() {
return oneMinuteRate;
}

public Double getFiveMinuteRate() {
return fiveMinuteRate;
}

public Double getFifteenMinuteRate() {
return fifteenMinuteRate;
}

public Double getMeanRate() {
return meanRate;
}


public static Builder builder() {
return new Builder();
}

@JsonPOJOBuilder(buildMethodName = "build", withPrefix = "with")
public static final class Builder {
private String name;
private Integer count;
private Double oneMinuteRate;
private Double fiveMinuteRate;
private Double fifteenMinuteRate;
private Double meanRate;

private Builder() {}

public Builder withName(String name) {
this.name = name;
return this;
}

public Builder withCount(Integer count) {
this.count = count;
return this;
}

public Builder withOneMinuteRate(Double oneMinuteRate) {
this.oneMinuteRate = oneMinuteRate;
return this;
}

public Builder withFiveMinuteRate(Double fiveMinuteRate) {
this.fiveMinuteRate = fiveMinuteRate;
return this;
}

public Builder withFifteenMinuteRate(Double fifteenMinuteRate) {
this.fifteenMinuteRate = fifteenMinuteRate;
return this;
}

public Builder withMeanRate(Double meanRate) {
this.meanRate = meanRate;
return this;
}

public DroppedMessages build() {
return new DroppedMessages(this);
}
}
}
93 changes: 93 additions & 0 deletions src/server/src/main/java/io/cassandrareaper/core/JmxStat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.cassandrareaper.core;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

@JsonDeserialize(builder = JmxStat.Builder.class)
public final class JmxStat {
private final String scope;
private final String name;
private final String attribute;
private final Double value;

private JmxStat(Builder builder) {
this.scope = builder.scope;
this.name = builder.name;
this.attribute = builder.attribute;
this.value = builder.value;
}

public String getScope() {
return scope;
}

public String getName() {
return name;
}

public String getAttribute() {
return attribute;
}

public Double getValue() {
return value;
}


@Override
public String toString() {
return scope + "/" + name + "/" + attribute + " = " + value;
}

public static Builder builder() {
return new Builder();
}

@JsonPOJOBuilder(buildMethodName = "build", withPrefix = "with")
public static final class Builder {
private String scope;
private String name;
private String attribute;
private Double value;

private Builder() {}

public Builder withScope(String scope) {
this.scope = scope;
return this;
}

public Builder withName(String name) {
this.name = name;
return this;
}

public Builder withAttribute(String attribute) {
this.attribute = attribute;
return this;
}

public Builder withValue(Double value) {
this.value = value;
return this;
}

public JmxStat build() {
return new JmxStat(this);
}
}
}
Loading

0 comments on commit 438ed51

Please sign in to comment.