Last active
August 29, 2015 14:11
-
-
Save mikecroft/a7bccf0fa5d90757f6a8 to your computer and use it in GitHub Desktop.
A script to log the number of HTTP connections in a Tomcat server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
* | |
* Copyright (c) 2014 C2B2 Consulting Limited. All rights reserved. | |
* | |
* The contents of this file are subject to the terms of the Common Development | |
* and Distribution License("CDDL") (collectively, the "License"). You | |
* may not use this file except in compliance with the License. You can | |
* obtain a copy of the License at | |
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
* | |
* When distributing the software, include this License Header Notice in each | |
* file and include the License file at packager/legal/LICENSE.txt. | |
* | |
* | |
* Owner: C2B2 | |
* Author: Mike Croft | |
* Date: 04/10/2013 | |
* | |
*/ | |
import groovy.jmx.builder.JmxBuilder | |
def port = 8090 | |
def host = '192.168.150.154' | |
def fileName = 'HTTPMbean.txt' | |
def connection = new JmxBuilder().client(port: port, host: host) | |
connection.connect() | |
// Get the MBeanServer. | |
def mbeans = connection.MBeanServerConnection | |
//Create GroovyMBean. | |
def mbean = new GroovyMBean(mbeans, 'Catalina:type=ThreadPool,name="http-nio-8080"') | |
def i = 0 | |
def logFile = new File(fileName) | |
while (i<10){ | |
// Print to console what's going in the file | |
print Calendar.getInstance().time | |
println " - $mbean.connectionCount" | |
logFile.append(Calendar.getInstance().time.toString() + " - $mbean.connectionCount\r\n") | |
sleep 1000 | |
i = i + 1 | |
} | |
println 'done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment