Permalink
Browse files

extract attributes from config,

filtering should be aware of enumerable expansions,
all lower case values,
keep track date of cache
  • Loading branch information...
1 parent 9b879f9 commit 2fdb38593fa32918d16652228b8d6f4f5410acf8 @tcurdt committed Apr 8, 2011
@@ -1,3 +1,3 @@
graph_title Number of Nodes in Cluster
-graph_vlabel org_apache_cassandra_db_StorageService_LiveNodes_size
-org_apache_cassandra_db_StorageService_LiveNodes_size.label number of nodes
+graph_vlabel org_apache_cassandra_db_storageservice_livenodes_size
+org_apache_cassandra_db_storageservice_livenodes_size.label number of nodes
View
@@ -1,11 +1,7 @@
#!/bin/bash
-# [cassandra_nodes]
-# env.config = cassandra/nodes_in_cluster
-# env.query = org.apache.cassandra.*:*
-
-MUNIN_LIBDIR=/Users/tcurdt/Projects
-config="nodes_in_cluster"
-query="org.apache.cassandra.*:*"
+# [cassandra_nodes_in_cluster]
+# env.config cassandra/nodes_in_cluster
+# env.query org.apache.cassandra.*:*
if [ -z "$MUNIN_LIBDIR" ]; then
MUNIN_LIBDIR="`dirname $(dirname "$0")`"
@@ -30,7 +26,7 @@ if [ -z "$config" -o -z "$query" -o -z "$url" ]; then
exit 1
fi
-JMX2MUNIN_DIR="$MUNIN_LIBDIR/jmx2munin"
+JMX2MUNIN_DIR="$MUNIN_LIBDIR/plugins"
CONFIG="$JMX2MUNIN_DIR/jmx2munin.cfg/$config"
if [ "$1" = "config" ]; then
@@ -41,11 +37,17 @@ fi
JAR="$JMX2MUNIN_DIR/jmx2munin.jar"
CACHED="/tmp/jmx2munin"
-if test `find "$CACHED" -mmin +2`; then
+if test ! -f $CACHED || test `find "$CACHED" -mmin +2`; then
+
+ ATTRIBUTES=`awk '/\.label/ { gsub(/\.label/,""); printf "-attribute %s ", $1 }' $CONFIG`
+
java -jar "$JAR" \
-url "$url" \
-query "$query" \
+ $ATTRIBUTES \
> $CACHED
+
+ echo "cached.value `date +%s`" >> $CACHED
fi
cat $CACHED
@@ -27,15 +27,15 @@
@Parameter(names = "-enums", description = "file string to enum config")
private String enumsPath;
- @Parameter(names = "-attribute", description = "attribute to return")
+ @Parameter(names = "-attribute", description = "attributes to return")
private List<String> attributes = new ArrayList<String>();
private void run() throws Exception {
final Filter filter;
- if (attributes != null) {
- filter = new MuninAttributesFilter(attributes);
- } else {
+ if (attributes == null || attributes.isEmpty()) {
filter = new NoFilter();
+ } else {
+ filter = new MuninAttributesFilter(attributes);
}
final Enums enums = new Enums();
@@ -9,10 +9,12 @@
public final class MuninAttributesFilter implements Filter {
- private final HashSet<String> attributes;
+ private final HashSet<String> attributes = new HashSet<String>();
public MuninAttributesFilter(List<String> pAttributes) {
- attributes = new HashSet<String>(pAttributes);
+ for (String attribute : pAttributes) {
+ attributes.add(attribute.trim().replaceAll("_size$", ""));
+ }
}
public boolean include(ObjectName bean, String attribute) {
@@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Hashtable;
+import java.util.Locale;
import javax.management.ObjectName;
@@ -24,7 +25,7 @@ public static String attributeName(ObjectName bean, String attribute) {
sb.append(fieldname(beanString(bean)));
sb.append('_');
sb.append(fieldname(attribute));
- return sb.toString();
+ return sb.toString().toLowerCase(Locale.US);
}
private static String fieldname(String s) {

0 comments on commit 2fdb385

Please sign in to comment.