Skip to content
Permalink
Browse files

Initial commit of Tehuti, the stats lib extracted out of Kafka.

  • Loading branch information...
FelixGV committed Jul 29, 2014
1 parent 48249c3 commit 9cb8fd92da65e90d19b60eb5295180df2e706a47
Showing with 822 additions and 80 deletions.
  1. +19 −0 build.gradle
  2. BIN gradle/wrapper/gradle-wrapper.jar
  3. +6 −0 gradle/wrapper/gradle-wrapper.properties
  4. +164 −0 gradlew
  5. +31 −0 src/main/java/org/tehuti/Configurable.java
  6. +42 −0 src/main/java/org/tehuti/KafkaException.java
  7. +1 −1 src/main/java/org/{apache/kafka/common → tehuti}/Metric.java
  8. +1 −1 src/main/java/org/{apache/kafka/common → tehuti}/metrics/CompoundStat.java
  9. +2 −2 src/main/java/org/{apache/kafka/common → tehuti}/metrics/JmxReporter.java
  10. +3 −3 src/main/java/org/{apache/kafka/common → tehuti}/metrics/KafkaMetric.java
  11. +1 −1 src/main/java/org/{apache/kafka/common → tehuti}/metrics/Measurable.java
  12. +3 −3 src/main/java/org/{apache/kafka/common → tehuti}/metrics/MeasurableStat.java
  13. +1 −1 src/main/java/org/{apache/kafka/common → tehuti}/metrics/MetricConfig.java
  14. +5 −5 src/main/java/org/{apache/kafka/common → tehuti}/metrics/Metrics.java
  15. +2 −2 src/main/java/org/{apache/kafka/common → tehuti}/metrics/MetricsReporter.java
  16. +1 −1 src/main/java/org/{apache/kafka/common → tehuti}/metrics/Quota.java
  17. +2 −2 src/main/java/org/{apache/kafka/common → tehuti}/metrics/QuotaViolationException.java
  18. +4 −4 src/main/java/org/{apache/kafka/common → tehuti}/metrics/Sensor.java
  19. +1 −1 src/main/java/org/{apache/kafka/common → tehuti}/metrics/Stat.java
  20. +2 −2 src/main/java/org/{apache/kafka/common → tehuti}/metrics/stats/Avg.java
  21. +2 −2 src/main/java/org/{apache/kafka/common → tehuti}/metrics/stats/Count.java
  22. +1 −1 src/main/java/org/{apache/kafka/common → tehuti}/metrics/stats/Histogram.java
  23. +2 −2 src/main/java/org/{apache/kafka/common → tehuti}/metrics/stats/Max.java
  24. +2 −2 src/main/java/org/{apache/kafka/common → tehuti}/metrics/stats/Min.java
  25. +1 −1 src/main/java/org/{apache/kafka/common → tehuti}/metrics/stats/Percentile.java
  26. +8 −11 src/main/java/org/{apache/kafka/common → tehuti}/metrics/stats/Percentiles.java
  27. +3 −3 src/main/java/org/{apache/kafka/common → tehuti}/metrics/stats/Rate.java
  28. +3 −3 src/main/java/org/{apache/kafka/common → tehuti}/metrics/stats/SampledStat.java
  29. +3 −3 src/main/java/org/{apache/kafka/common → tehuti}/metrics/stats/Total.java
  30. +142 −0 src/main/java/org/tehuti/utils/CopyOnWriteMap.java
  31. +43 −0 src/main/java/org/tehuti/utils/SystemTime.java
  32. +39 −0 src/main/java/org/tehuti/utils/Time.java
  33. +220 −0 src/main/java/org/tehuti/utils/Utils.java
  34. +3 −6 src/test/java/org/{apache/kafka/common → tehuti}/metrics/JmxReporterTest.java
  35. +12 −12 src/test/java/org/{apache/kafka/common → tehuti}/metrics/MetricsTest.java
  36. +4 −5 src/test/java/org/{apache/kafka/common → tehuti}/metrics/stats/HistogramTest.java
  37. +43 −0 src/test/java/org/tehuti/utils/MockTime.java
@@ -0,0 +1,19 @@
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'

repositories {
mavenCentral()
}

dependencies {
compile "org.slf4j:slf4j-api:1.7.6"
testCompile 'com.novocode:junit-interface:0.9'
}

idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
Binary file not shown.
@@ -0,0 +1,6 @@
#Fri May 30 13:08:12 PDT 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip
164 gradlew
@@ -0,0 +1,164 @@
#!/usr/bin/env bash

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
echo "$*"
}

die ( ) {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
@@ -0,0 +1,31 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.tehuti;

import java.util.Map;

/**
* A Mix-in style interface for classes that are instantiated by reflection and need to take configuration parameters
*/
public interface Configurable {

/**
* Configure this class with the given key-value pairs
*/
public void configure(Map<String, ?> configs);

}
@@ -0,0 +1,42 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.tehuti;

/**
* The base class of all other Kafka exceptions
*/
public class KafkaException extends RuntimeException {

private final static long serialVersionUID = 1L;

public KafkaException(String message, Throwable cause) {
super(message, cause);
}

public KafkaException(String message) {
super(message);
}

public KafkaException(Throwable cause) {
super(cause);
}

public KafkaException() {
super();
}

}
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kafka.common;
package org.tehuti;

/**
* A numerical metric tracked for monitoring purposes
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kafka.common.metrics;
package org.tehuti.metrics;

import java.util.List;

@@ -10,7 +10,7 @@
* 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.apache.kafka.common.metrics;
package org.tehuti.metrics;

import java.lang.management.ManagementFactory;
import java.util.HashMap;
@@ -31,7 +31,7 @@
import javax.management.ObjectName;
import javax.management.ReflectionException;

import org.apache.kafka.common.KafkaException;
import org.tehuti.KafkaException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -14,10 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kafka.common.metrics;
package org.tehuti.metrics;

import org.apache.kafka.common.Metric;
import org.apache.kafka.common.utils.Time;
import org.tehuti.Metric;
import org.tehuti.utils.Time;

public final class KafkaMetric implements Metric {

@@ -10,7 +10,7 @@
* 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.apache.kafka.common.metrics;
package org.tehuti.metrics;

/**
* A measurable quantity that can be registered as a metric
@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kafka.common.metrics;
package org.tehuti.metrics;

/**
* A MeasurableStat is a {@link Stat} that is also {@link Measurable} (i.e. can produce a single floating point value).
* This is the interface used for most of the simple statistics such as {@link org.apache.kafka.common.metrics.stats.Avg},
* {@link org.apache.kafka.common.metrics.stats.Max}, {@link org.apache.kafka.common.metrics.stats.Count}, etc.
* This is the interface used for most of the simple statistics such as {@link org.tehuti.metrics.stats.Avg},
* {@link org.tehuti.metrics.stats.Max}, {@link org.tehuti.metrics.stats.Count}, etc.
*/
public interface MeasurableStat extends Stat, Measurable {

@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kafka.common.metrics;
package org.tehuti.metrics;

import java.util.concurrent.TimeUnit;

@@ -10,17 +10,17 @@
* 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.apache.kafka.common.metrics;
package org.tehuti.metrics;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;

import org.apache.kafka.common.utils.CopyOnWriteMap;
import org.apache.kafka.common.utils.SystemTime;
import org.apache.kafka.common.utils.Time;
import org.apache.kafka.common.utils.Utils;
import org.tehuti.utils.CopyOnWriteMap;
import org.tehuti.utils.SystemTime;
import org.tehuti.utils.Time;
import org.tehuti.utils.Utils;

/**
* A registry of sensors and metrics.
@@ -10,11 +10,11 @@
* 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.apache.kafka.common.metrics;
package org.tehuti.metrics;

import java.util.List;

import org.apache.kafka.common.Configurable;
import org.tehuti.Configurable;

/**
* A plugin interface to allow things to listen as new metrics are created so they can be reported.
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kafka.common.metrics;
package org.tehuti.metrics;

/**
* An upper or lower bound for metrics

0 comments on commit 9cb8fd9

Please sign in to comment.
You can’t perform that action at this time.