Additional JMX Metrics
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.data.document.mongodb.monitor;
|
||||
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.jmx.support.MetricType;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.Mongo;
|
||||
|
||||
/**
|
||||
* JMX Metrics for assertions
|
||||
*
|
||||
* @author Mark Pollack
|
||||
*
|
||||
*/
|
||||
@ManagedResource(description="Assertion Metrics")
|
||||
public class AssertMetrics extends AbstractMonitor {
|
||||
|
||||
public AssertMetrics(Mongo mongo) {
|
||||
this.mongo = mongo;
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Regular")
|
||||
public int getRegular() {
|
||||
return getBtree("regular");
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Warning")
|
||||
public int getWarning() {
|
||||
return getBtree("hits");
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Msg")
|
||||
public int getMsg() {
|
||||
return getBtree("msg");
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "User")
|
||||
public int getUser() {
|
||||
return getBtree("user");
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Rollovers")
|
||||
public int getRollovers() {
|
||||
return getBtree("rollovers");
|
||||
}
|
||||
|
||||
private int getBtree(String key) {
|
||||
DBObject asserts = (DBObject) getServerStatus().get("asserts");
|
||||
//Class c = btree.get(key).getClass();
|
||||
return (Integer) asserts.get(key);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.data.document.mongodb.monitor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.jmx.support.MetricType;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.Mongo;
|
||||
|
||||
/**
|
||||
* JMX Metrics for Background Flushing
|
||||
*
|
||||
* @author Mark Pollack
|
||||
*
|
||||
*/
|
||||
@ManagedResource(description="Background Flushing Metrics")
|
||||
public class BackgroundFlushingMetrics extends AbstractMonitor {
|
||||
|
||||
|
||||
public BackgroundFlushingMetrics(Mongo mongo) {
|
||||
this.mongo = mongo;
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Flushes")
|
||||
public int getFlushes() {
|
||||
return getFlushingData("flushes", java.lang.Integer.class);
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Total ms", unit="ms")
|
||||
public int getTotalMs() {
|
||||
return getFlushingData("total_ms", java.lang.Integer.class);
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Average ms", unit="ms")
|
||||
public double getAverageMs() {
|
||||
return getFlushingData("average_ms", java.lang.Double.class);
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Last Ms", unit="ms")
|
||||
public int getLastMs() {
|
||||
return getFlushingData("last_ms", java.lang.Integer.class);
|
||||
}
|
||||
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Last finished")
|
||||
public Date getLastFinished() {
|
||||
return getLast();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T getFlushingData(String key, Class<T> targetClass) {
|
||||
DBObject mem = (DBObject) getServerStatus().get("backgroundFlushing");
|
||||
return (T) mem.get(key);
|
||||
}
|
||||
|
||||
private Date getLast() {
|
||||
DBObject bgFlush = (DBObject) getServerStatus().get("backgroundFlushing");
|
||||
Date lastFinished = (Date)bgFlush.get("last_finished");
|
||||
return lastFinished;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.data.document.mongodb.monitor;
|
||||
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.jmx.support.MetricType;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.Mongo;
|
||||
|
||||
/**
|
||||
* JMX Metrics for B-tree index counters
|
||||
*
|
||||
* @author Mark Pollack
|
||||
*
|
||||
*/
|
||||
@ManagedResource(description="Btree Metrics")
|
||||
public class BtreeIndexCounters extends AbstractMonitor {
|
||||
|
||||
public BtreeIndexCounters(Mongo mongo) {
|
||||
this.mongo = mongo;
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Accesses")
|
||||
public int getAccesses() {
|
||||
return getBtree("accesses");
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Hits")
|
||||
public int getHits() {
|
||||
return getBtree("hits");
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Misses")
|
||||
public int getMisses() {
|
||||
return getBtree("misses");
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Resets")
|
||||
public int getResets() {
|
||||
return getBtree("resets");
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Miss Ratio")
|
||||
public int getMissRatio() {
|
||||
return getBtree("missRatio");
|
||||
}
|
||||
|
||||
private int getBtree(String key) {
|
||||
DBObject indexCounters = (DBObject) getServerStatus().get("indexCounters");
|
||||
if (indexCounters.get("note") != null) {
|
||||
String message = (String) indexCounters.get("note");
|
||||
if (message.contains("not supported")) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
DBObject btree = (DBObject) indexCounters.get("btree");
|
||||
//Class c = btree.get(key).getClass();
|
||||
return (Integer) btree.get(key);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.data.document.mongodb.monitor;
|
||||
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.jmx.support.MetricType;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.Mongo;
|
||||
|
||||
/**
|
||||
* JMX Metrics for Connections
|
||||
*
|
||||
* @author Mark Pollack
|
||||
*
|
||||
*/
|
||||
@ManagedResource(description="Connection metrics")
|
||||
public class ConnectionMetrics extends AbstractMonitor {
|
||||
|
||||
public ConnectionMetrics(Mongo mongo) {
|
||||
this.mongo = mongo;
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Current Connections")
|
||||
public int getCurrent() {
|
||||
return getConnectionData("current", java.lang.Integer.class);
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Available Connections")
|
||||
public int getAvailable() {
|
||||
return getConnectionData("available", java.lang.Integer.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T getConnectionData(String key, Class<T> targetClass) {
|
||||
DBObject mem = (DBObject) getServerStatus().get("connections");
|
||||
//Class c = mem.get(key).getClass();
|
||||
return (T) mem.get(key);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.data.document.mongodb.monitor;
|
||||
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.jmx.support.MetricType;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.Mongo;
|
||||
|
||||
/**
|
||||
* JMX Metrics for Memory
|
||||
* @author Mark Pollack
|
||||
*
|
||||
*/
|
||||
@ManagedResource(description="Memory Metrics")
|
||||
public class MemoryMetrics extends AbstractMonitor {
|
||||
|
||||
|
||||
public MemoryMetrics(Mongo mongo) {
|
||||
this.mongo = mongo;
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Memory address size")
|
||||
public int getBits() {
|
||||
return getMemData("bits", java.lang.Integer.class);
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Resident in Physical Memory", unit="MB")
|
||||
public int getResidentSpace() {
|
||||
return getMemData("resident", java.lang.Integer.class);
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Virtual Address Space", unit="MB")
|
||||
public int getVirtualAddressSpace() {
|
||||
return getMemData("virtual", java.lang.Integer.class);
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Is memory info supported on this platform")
|
||||
public boolean getMemoryInfoSupported() {
|
||||
return getMemData("supported", java.lang.Boolean.class);
|
||||
}
|
||||
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Memory Mapped Space", unit="MB")
|
||||
public int getMemoryMappedSpace() {
|
||||
return getMemData("mapped", java.lang.Integer.class);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T getMemData(String key, Class<T> targetClass) {
|
||||
DBObject mem = (DBObject) getServerStatus().get("mem");
|
||||
//Class c = mem.get(key).getClass();
|
||||
return (T) mem.get(key);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user