If your app is a spring boot app that has the actuator enabled then use this nifty script from Greg Turnquist's Learning Spring Boot book with some changes from me to collect all the metrics in a csv
package learningspringboot
@Grab("groovy-all")
import groovy.json.*
package learningspringboot
@Grab("groovy-all")
import groovy.json.*
@EnableScheduling
class MetricsCollector {
def url = "http://fizzbuzz.cfapps.io/metrics"
def slurper = new JsonSlurper()
def keys = slurper.parse(new URL(url)).keySet()
def header = false;
@Scheduled(fixedRate = 1000L)
void run() {
if (!header) {
println(keys.join(','))
header = true
}
def metrics = slurper.parse(new URL(url))
println(keys.collect{metrics[it]}.join(','))
}
}
How do you run this script ?
To start collecting stats in the CSV:
package learningspringboot
@Grab("groovy-all")
import groovy.json.*
package learningspringboot
@Grab("groovy-all")
import groovy.json.*
@EnableScheduling
class MetricsCollector {
def url = "http://fizzbuzz.cfapps.io/metrics"
def slurper = new JsonSlurper()
def keys = slurper.parse(new URL(url)).keySet()
def header = false;
@Scheduled(fixedRate = 1000L)
void run() {
if (!header) {
println(keys.join(','))
header = true
}
def metrics = slurper.parse(new URL(url))
println(keys.collect{metrics[it]}.join(','))
}
}
How do you run this script ?
To start collecting stats in the CSV:
- First install the spring cli following instructions here - http://docs.spring.io/autorepo/docs/spring-boot/1.1.4.RELEASE/reference/html/getting-started-installing-spring-boot.html#getting-started-installing-the-cli
- Thereafter save the snippet above as metrics.groovy
- On windows Install - wintee Run the script on windows with spring run -q metrics.groovy | wintee metrics.csv
- Run the script on unix with spring run -q metrics.groovy | tee metrics.csv
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.