55 |
56 | Welcome to Grails
57 |
58 |
59 | Congratulations, you have successfully started your first Grails application! At the moment
60 | this is the default page, feel free to modify it to either redirect to a controller or display
61 | whatever content you may choose. Below is a list of controllers that are currently deployed in
62 | this application, click on each to execute its default action:
63 |
64 |
65 |
66 |
Available Controllers:
67 |
68 |
69 | -
70 | ${c.fullName}
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/src/main/groovy/grails/plugin/dropwizard/reporters/ScheduledReporterFactory.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package grails.plugin.dropwizard.reporters
17 |
18 | import com.codahale.metrics.ConsoleReporter
19 | import com.codahale.metrics.CsvReporter
20 | import com.codahale.metrics.MetricRegistry
21 | import com.codahale.metrics.Slf4jReporter
22 | import groovy.util.logging.Slf4j
23 | import org.slf4j.LoggerFactory
24 | import org.springframework.beans.factory.annotation.Autowired
25 | import org.springframework.beans.factory.annotation.Value
26 | import org.springframework.context.ApplicationContext
27 |
28 | import java.util.concurrent.TimeUnit
29 |
30 | @Slf4j
31 | class ScheduledReporterFactory {
32 |
33 | @Autowired
34 | MetricRegistry metricRegistry
35 |
36 | @Autowired
37 | ApplicationContext applicationContext
38 |
39 | @Value('${grails.dropwizard.metrics.reporterFrequency:0}')
40 | Integer reporterFrequency
41 |
42 | @Value('${grails.dropwizard.metrics.csv-reporter.output-dir:./}')
43 | String csvOutputDir
44 |
45 | /**
46 | * Instantiates a ConsoleReporter to be registered as a Spring bean named dropwizardConsoleReporter
47 | * @return A ConsoleReporter
48 | */
49 | ConsoleReporter consoleReporter() {
50 | ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry)
51 | .convertRatesTo(TimeUnit.SECONDS)
52 | .convertDurationsTo(TimeUnit.MILLISECONDS)
53 | .build()
54 |
55 | consoleReporter.start reporterFrequency, TimeUnit.SECONDS
56 | log.info 'consoleReporter started'
57 |
58 | consoleReporter
59 | }
60 |
61 | /**
62 | * Instantiates a CsvReporter to be registered as a Spring bean named dropwizardCsvReporter
63 | * @return A CsvReporter
64 | */
65 | CsvReporter csvReporter() {
66 | File outputDir = new File(csvOutputDir)
67 | if(outputDir.exists()) {
68 | CsvReporter csvReporter = CsvReporter.forRegistry(metricRegistry)
69 | .convertRatesTo(TimeUnit.SECONDS)
70 | .convertDurationsTo(TimeUnit.MILLISECONDS)
71 | .build(outputDir)
72 |
73 | csvReporter.start reporterFrequency, TimeUnit.SECONDS
74 | log.info 'csvReporter started'
75 |
76 | return csvReporter
77 | } else {
78 | log.warn "CSV Reporter output directory ${csvOutputDir} does not exist"
79 | return null
80 | }
81 | }
82 |
83 | /**
84 | * Instantiates a Slf4jReporter to be registered as a Spring bean named dropwizardSlf4jReporter
85 | * @return A Slf4jReporter
86 | */
87 | Slf4jReporter slf4jReporter() {
88 | Slf4jReporter slf4jReporter = Slf4jReporter.forRegistry(metricRegistry)
89 | .convertRatesTo(TimeUnit.SECONDS)
90 | .convertDurationsTo(TimeUnit.MILLISECONDS)
91 | .outputTo(LoggerFactory.getLogger(Slf4jReporter))
92 | .build()
93 |
94 | slf4jReporter.start reporterFrequency, TimeUnit.SECONDS
95 | log.info 'slf4jReporter started'
96 |
97 | slf4jReporter
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/grailsw:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Grails start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRAILS_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS='"-XX:+TieredCompilation" "-XX:TieredStopAtLevel=1" "-XX:CICompilerCount=3"'
11 |
12 |
13 | # Use the maximum available, or set MAX_FD != -1 to use that value.
14 | MAX_FD="maximum"
15 |
16 | warn ( ) {
17 | echo "$*"
18 | }
19 |
20 | die ( ) {
21 | echo
22 | echo "$*"
23 | echo
24 | exit 1
25 | }
26 |
27 | # OS specific support (must be 'true' or 'false').
28 | cygwin=false
29 | msys=false
30 | darwin=false
31 | case "`uname`" in
32 | CYGWIN* )
33 | cygwin=true
34 | ;;
35 | Darwin* )
36 | darwin=true
37 | ;;
38 | MINGW* )
39 | msys=true
40 | ;;
41 | esac
42 |
43 | # Attempt to set APP_HOME
44 | # Resolve links: $0 may be a link
45 | PRG="$0"
46 | # Need this for relative symlinks.
47 | while [ -h "$PRG" ] ; do
48 | ls=`ls -ld "$PRG"`
49 | link=`expr "$ls" : '.*-> \(.*\)$'`
50 | if expr "$link" : '/.*' > /dev/null; then
51 | PRG="$link"
52 | else
53 | PRG=`dirname "$PRG"`"/$link"
54 | fi
55 | done
56 | SAVED="`pwd`"
57 | cd "`dirname \"$PRG\"`/" >/dev/null
58 | APP_HOME="`pwd -P`"
59 | cd "$SAVED" >/dev/null
60 |
61 | JAR_PATH=$APP_HOME/grails-wrapper.jar
62 |
63 | # Determine the Java command to use to start the JVM.
64 | if [ -n "$JAVA_HOME" ] ; then
65 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
66 | # IBM's JDK on AIX uses strange locations for the executables
67 | JAVACMD="$JAVA_HOME/jre/sh/java"
68 | else
69 | JAVACMD="$JAVA_HOME/bin/java"
70 | fi
71 | if [ ! -x "$JAVACMD" ] ; then
72 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
73 |
74 | Please set the JAVA_HOME variable in your environment to match the
75 | location of your Java installation."
76 | fi
77 | else
78 | JAVACMD="java"
79 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 |
85 | # Increase the maximum file descriptors if we can.
86 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
87 | MAX_FD_LIMIT=`ulimit -H -n`
88 | if [ $? -eq 0 ] ; then
89 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
90 | MAX_FD="$MAX_FD_LIMIT"
91 | fi
92 | ulimit -n $MAX_FD
93 | if [ $? -ne 0 ] ; then
94 | warn "Could not set maximum file descriptor limit: $MAX_FD"
95 | fi
96 | else
97 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
98 | fi
99 | fi
100 |
101 | # For Cygwin, switch paths to Windows format before running java
102 | if $cygwin ; then
103 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
104 | JAVACMD=`cygpath --unix "$JAVACMD"`
105 |
106 | # We build the pattern for arguments to be converted via cygpath
107 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
108 | SEP=""
109 | for dir in $ROOTDIRSRAW ; do
110 | ROOTDIRS="$ROOTDIRS$SEP$dir"
111 | SEP="|"
112 | done
113 | OURCYGPATTERN="(^($ROOTDIRS))"
114 | # Add a user-defined pattern to the cygpath arguments
115 | if [ "$GRAILS_CYGPATTERN" != "" ] ; then
116 | OURCYGPATTERN="$OURCYGPATTERN|($GRAILS_CYGPATTERN)"
117 | fi
118 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
119 | i=0
120 | for arg in "$@" ; do
121 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
122 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
123 |
124 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
125 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
126 | else
127 | eval `echo args$i`="\"$arg\""
128 | fi
129 | i=$((i+1))
130 | done
131 | case $i in
132 | (0) set -- ;;
133 | (1) set -- "$args0" ;;
134 | (2) set -- "$args0" "$args1" ;;
135 | (3) set -- "$args0" "$args1" "$args2" ;;
136 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
137 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
138 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
139 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
140 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
141 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
142 | esac
143 | fi
144 |
145 | # Split up the JVM_OPTS And GRAILS_OPTS values into an array, following the shell quoting and substitution rules
146 | function splitJvmOpts() {
147 | JVM_OPTS=("$@")
148 | }
149 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRAILS_OPTS
150 |
151 | exec "$JAVACMD" -jar "${JVM_OPTS[@]}" "$JAR_PATH" "$@"
152 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS='"-Xmx64m"'
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/src/docs/asciidoc/reporting.ad:
--------------------------------------------------------------------------------
1 | The plugin provides support for automatically reporting metrics at a scheduled interval using one or more built-in
2 | Dropwizard ScheduledReporters: `Slf4jReporter`, `ConsoleReporter`, or `CsvReporter`.
3 |
4 | A separate plug-in, `dropwizard-metrics-graphite` is available for doing scheduled reporting using
5 | the `GraphiteReporter`. It can also serve as an example of one approach for adding your own reporter.
6 |
7 | The reporters are enabled and configured under the confuration key `grails.dropwizard.metrics`.
8 |
9 | To enable scheduled reporting of metrics, first assign a value to the config property named
10 | `reporterFrequency` to indicate how often the reporting should occur. The value represents the
11 | reporting interval *in seconds*.
12 |
13 | ```
14 | grails:
15 | dropwizard:
16 | metrics:
17 | reporterFrequency: 30 # report every 30 seconds
18 | ```
19 | If `reporterFrequency` is missing or has a value of zero, metric reporting will not occur.
20 |
21 | For reference as we discuss the various reporters, a SimpleService was created with a `@Metered`
22 | method:
23 | ```
24 | package demo.dropwizard
25 |
26 | import grails.gorm.transactions.Transactional
27 | import grails.plugin.dropwizard.metrics.meters.Metered
28 |
29 | @Transactional(readOnly = true)
30 | class SimpleService {
31 |
32 | @Metered('sayHello meter')
33 | String sayHello(String name) {
34 | name ? "Hello ${name}!" : 'Hello Stranger!'
35 | }
36 | }
37 | ```
38 |
39 | === Slf4jReporter
40 |
41 | The Slf4jReporter reports metrics via a Slf4j logger named `com.codahale.metrics.Slf4jReporter` at
42 | the `INFO` level. You may want to configure the level for that logger in `grails-app/conf/logback.groovy`
43 | as shown below.
44 |
45 | ```
46 | logger 'com.codahale.metrics.Slf4jReporter', INFO, ['STDOUT'], false
47 | ```
48 |
49 | For backward compatibility, this reporter is active by default. However, adding `slf4j-reporter.active` configuration
50 | will explicitly enable or disable the Slf4j reporter:
51 |
52 | ```
53 | grails:
54 | dropwizard:
55 | metrics:
56 | reporterFrequency: 10 # report every 10 seconds
57 | slf4j-reporter.active: false
58 | ```
59 | When active, the Slf4jReporter metric reporting to the configured logger looks like this:
60 | ```
61 | 2017-10-07 11:06:30.820 INFO --- [rter-1-thread-1] com.codahale.metrics.Slf4jReporter : type=GAUGE, name=gauge.response.metrics, value=2.0
62 | 2017-10-07 11:06:30.820 INFO --- [rter-1-thread-1] com.codahale.metrics.Slf4jReporter : type=GAUGE, name=gauge.response.sayHello.Fred, value=3.0
63 | 2017-10-07 11:06:30.820 INFO --- [rter-1-thread-1] com.codahale.metrics.Slf4jReporter : type=COUNTER, name=counter.status.200.metrics, count=2
64 | 2017-10-07 11:06:30.820 INFO --- [rter-1-thread-1] com.codahale.metrics.Slf4jReporter : type=COUNTER, name=counter.status.200.sayHello.Fred, count=10
65 | 2017-10-07 11:06:30.820 INFO --- [rter-1-thread-1] com.codahale.metrics.Slf4jReporter : type=METER, name=sayHello meter, count=10, mean_rate=0.010176484138111742, m1=1.7528496438887441E-7, m5=0.077548415663444, m15=0.6769308502134816, rate_unit=events/second
66 | ```
67 |
68 | === ConsoleReporter
69 |
70 | The ConsoleReporter reports metrics directly to the console, making it a convenient reporter for
71 | use in development and environments where console output is required instead of logging.
72 |
73 | To configure it, simply declare `grails.dropwizard.metrics.console-reporter.active: true` in configuration.
74 | Below we see that the slf4j-reporter is configured as inactive and the console-reporter is active.
75 |
76 | ```
77 | grails:
78 | dropwizard:
79 | metrics:
80 | reporterFrequency: 10 # report every 10 seconds
81 | slf4j-reporter.active: false
82 | console-reporter.active: true
83 | ```
84 | However, both could be enabled as `active`. Recall, the slf4j-reporter is active by default for
85 | backward compatibility, so you must explicitly configure it as inactive if that's what you want.
86 |
87 | Here's what the console logging output looks like:
88 | ```
89 | 10/7/17 11:14:29 AM ============================================================
90 |
91 | -- Gauges ----------------------------------------------------------------------
92 | gauge.response.sayHello.Fred
93 | value = 3.0
94 |
95 | -- Counters --------------------------------------------------------------------
96 | counter.status.200.sayHello.Fred
97 | count = 14
98 |
99 | -- Meters ----------------------------------------------------------------------
100 | sayHello meter
101 | count = 14
102 | mean rate = 3.53 events/second
103 | 1-minute rate = 0.00 events/second
104 | 5-minute rate = 0.00 events/second
105 | 15-minute rate = 0.00 events/second
106 | ```
107 |
108 | === CsvReporter
109 |
110 | The CsvReporter is used to report metrics to a CSV (comma-separated values) file.
111 |
112 | To configure it, declare `grails.dropwizard.metrics.csv-reporter.active: true` in configuration and specify
113 | the output directory of the CSV file. Of course, the directory specified must have permissions set
114 | to allow the application to write to it. If not specified, the `csv-reporter.output-dir` will
115 | default to the directory from which the app is running; i.e. `./`
116 |
117 | Below we see that csv-reporter is configured as active. Since we didn't explicitly declare the
118 | `slf4j-reporter.active: false`, the metrics would also be logged as well as written to the CSV
119 | file.
120 |
121 | ```
122 | grails:
123 | dropwizard:
124 | metrics:
125 | reporterFrequency: 10 # report every 10 seconds
126 | csv-reporter:
127 | active: true
128 | output-dir: /tmp
129 | ```
130 | Multiple files are output from the CsvReporter, one for each meter, guage and counter that had
131 | data reported. For instance, when the `sayHello` method was invoked with the name *Fred*, a `sayHello meter.csv` file
132 | was written into the `/tmp` directory with the following contents:
133 | ```
134 | t,count,mean_rate,m1_rate,m5_rate,m15_rate,rate_unit
135 | 1507412611,7,4.546009,0.000000,0.000000,0.000000,events/second
136 | 1507412616,7,1.070702,1.400000,1.400000,1.400000,events/second
137 | 1507412621,7,0.606700,1.288062,1.376860,1.392244,events/second
138 | 1507412626,7,0.423267,1.185074,1.354103,1.384531,events/second
139 | 1507412631,7,0.325009,1.090321,1.331721,1.376860,events/second
140 | 1507412636,7,0.263756,1.003144,1.309710,1.369232,events/second
141 | 1507412641,7,0.221956,0.922937,1.288062,1.361646,events/second
142 | ```
143 | Likewise, a `/tmp/gauge.response.sayHello.Fred.csv` file was written:
144 | ```
145 | t,value
146 | 1507412611,4.0
147 | 1507412616,4.0
148 | 1507412621,4.0
149 | 1507412626,4.0
150 | 1507412631,4.0
151 | 1507412636,4.0
152 | 1507412641,4.0
153 | ```
154 | as well as a `/tmp/counter.status.200.sayHello.Fred.csv` file:
155 | ```
156 | t,count
157 | 1507412611,7
158 | 1507412616,7
159 | 1507412621,7
160 | 1507412626,7
161 | 1507412631,7
162 | 1507412636,7
163 | 1507412641,7
164 | ```
165 |
166 | === For more information
167 | For details on Dropwizard metrics and these reporters see
168 | http://metrics.dropwizard.io/3.1.0/manual/core/
--------------------------------------------------------------------------------
/src/docs/asciidoc/metrics.ad:
--------------------------------------------------------------------------------
1 | === PublicMetric Beans
2 |
3 | The plugin will discover all of the `org.springframework.boot.actuate.endpoint.PublicMetrics`
4 | instances that are found in the Spring application context and active them. An application may provide
5 | any number of `PublicMetrics` beans.
6 |
7 | === Marking Meters
8 |
9 | [quote, The Dropwizard Metrics Documentation]
10 | A meter measures the rate of events over time (e.g., “requests per second”). In addition to the mean rate, meters also
11 | track 1-, 5-, and 15-minute moving averages.
12 |
13 | The link:api/grails/plugin/dropwizard/metrics/meters/Meterable.html[Meterable] trait provides a `markMeter(String)` method which makes it easy
14 | to access and increment a `Meter`. Any class may implement the trait and take advantage of this method.
15 |
16 | [source,groovy]
17 | ----
18 | include::{projectdir}/src/test/groovy/grails/plugin/dropwizard/metrics/meters/MeterableSpec.groovy[tags=sample_class,indent=0]
19 | ----
20 |
21 | The plugin provides the link:api/grails/plugin/dropwizard/metrics/meters/Metered.html[Metered] annotation which may be applied to any method.
22 | If a method is marked with `@Metered`, every time the method is invoked, the meter with the specified name will
23 | automatically be incremented.
24 |
25 | [source,groovy]
26 | ----
27 | include::{projectdir}/src/test/groovy/grails/plugin/dropwizard/metrics/meters/MeteredAnnotationSpec.groovy[tags=sample_class,indent=0]
28 | ----
29 |
30 | The `@Metered` annotation supports an optional `useClassPrefix` attribute which when set to `true` will cause the name
31 | of the associated meter to be prefixed with the fully qualified name of the class which defines the annotated method.
32 |
33 |
34 |
35 | === Timers
36 |
37 | [quote, The Dropwizard Metrics Documentation]
38 | A timer is basically a histogram of the duration of a type of event and a meter of the rate of its occurrence.
39 |
40 | The plugin provides the link:api/grails/plugin/dropwizard/metrics/timers/Timed.html[Timed] annotation which may be applied to any method.
41 | If a method is marked with `@Timed`, every time the method is invoked, the timer with the specified name will
42 | automatically be started.
43 |
44 | [source,groovy]
45 | ----
46 | include::{projectdir}/src/test/groovy/grails/plugin/dropwizard/metrics/timers/TimedAnnotationSpec.groovy[tags=sample_class,indent=0]
47 | ----
48 |
49 | The `@Timed` annotation supports an optional `useClassPrefix` attribute which when set to `true` will cause the name
50 | of the associated timer to be prefixed with the fully qualified name of the class which defines the annotated method.
51 |
52 | === Unit Testing
53 |
54 | When unit testing code which uses any of the plugin's code generation techniques (`@Timed`, `@Metered`, etc...) a bean named `metricsRegistry` will
55 | need to be registed in the Spring application context. Below are examples of how to do that.
56 |
57 | [source,groovy]
58 | ----
59 | include::{projectdir}/src/test/groovy/grails/plugin/dropwizard/metrics/meters/MeterableSpec.groovy[tags=test_class,indent=0]
60 | ----
61 |
62 | [source,groovy]
63 | ----
64 | include::{projectdir}/src/test/groovy/grails/plugin/dropwizard/metrics/meters/MeteredAnnotationSpec.groovy[tags=test_class,indent=0]
65 | ----
66 |
67 | === Exposing Metrics Data
68 |
69 | The plugin supports exposing access to metrics data through a URI in the web application. By default metrics are
70 | available at `/metrics`. A request to `/metrics` will be responded to with JSON provided by all
71 | of the `MetricRegistry` instances that are active in the application as shown below.
72 |
73 | ```
74 | {"version":"3.0.0","gauges":{"grails.dropwizard.dropwizardGarbageCollectorMetricSet.PS-MarkSweep.count":{"value":0},"grails.dropwizard.dropwizardGarbageCollectorMetricSet.PS-MarkSweep.time":{"value":0},"grails.dropwizard.dropwizardGarbageCollectorMetricSet.PS-Scavenge.count":{"value":9},"grails.dropwizard.dropwizardGarbageCollectorMetricSet.PS-Scavenge.time":{"value":468},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.heap.committed":{"value":738197504},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.heap.init":{"value":268435456},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.heap.max":{"value":3817865216},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.heap.usage":{"value":0.14876779767387158},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.heap.used":{"value":567975400},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.non-heap.committed":{"value":64880640},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.non-heap.init":{"value":24576000},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.non-heap.max":{"value":136314880},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.non-heap.usage":{"value":0.47363680326021634},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.non-heap.used":{"value":64563744},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.Code-Cache.committed":{"value":6160384},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.Code-Cache.init":{"value":2555904},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.Code-Cache.max":{"value":50331648},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.Code-Cache.usage":{"value":0.11999003092447917},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.Code-Cache.used":{"value":6039296},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Eden-Space.committed":{"value":525336576},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Eden-Space.init":{"value":67633152},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Eden-Space.max":{"value":1354760192},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Eden-Space.usage":{"value":0.3691370819375242},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Eden-Space.used":{"value":500092224},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Old-Gen.committed":{"value":178782208},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Old-Gen.init":{"value":178782208},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Old-Gen.max":{"value":2863136768},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Old-Gen.usage":{"value":0.011815351742218974},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Old-Gen.used":{"value":33828968},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Perm-Gen.committed":{"value":58720256},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Perm-Gen.init":{"value":22020096},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Perm-Gen.max":{"value":85983232},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Perm-Gen.usage":{"value":0.6806495480421113},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Perm-Gen.used":{"value":58524448},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Survivor-Space.committed":{"value":34078720},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Survivor-Space.init":{"value":11010048},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Survivor-Space.max":{"value":34078720},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Survivor-Space.usage":{"value":0.9992807241586539},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.pools.PS-Survivor-Space.used":{"value":34054208},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.total.committed":{"value":803078144},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.total.init":{"value":293011456},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.total.max":{"value":3954180096},"grails.dropwizard.dropwizardMemoryUsageGaugeSet.total.used":{"value":632539312},"grails.dropwizard.dropwizardThreadStatesGaugeSet.blocked.count":{"value":0},"grails.dropwizard.dropwizardThreadStatesGaugeSet.count":{"value":23},"grails.dropwizard.dropwizardThreadStatesGaugeSet.daemon.count":{"value":20},"grails.dropwizard.dropwizardThreadStatesGaugeSet.deadlock.count":{"value":0},"grails.dropwizard.dropwizardThreadStatesGaugeSet.deadlocks":{"value":[]},"grails.dropwizard.dropwizardThreadStatesGaugeSet.new.count":{"value":0},"grails.dropwizard.dropwizardThreadStatesGaugeSet.runnable.count":{"value":9},"grails.dropwizard.dropwizardThreadStatesGaugeSet.terminated.count":{"value":0},"grails.dropwizard.dropwizardThreadStatesGaugeSet.timed_waiting.count":{"value":9},"grails.dropwizard.dropwizardThreadStatesGaugeSet.waiting.count":{"value":5}},"counters":{},"histograms":{},"meters":{},"timers":{}}
75 | ```
76 |
77 | NOTE: TBD - notes on configuring the endpoint.
78 |
79 |
80 | Metrics may also be exposed as JMX MBeans. To enable JMX support assign the value `true` to the
81 | `grails.dropwizard.jmx.enabled` config setting.
82 |
83 | ```
84 | ---
85 | grails:
86 | dropwizard:
87 | jmx:
88 | enabled: true
89 | ```
90 |
--------------------------------------------------------------------------------