Contact Free trial Login

CSV Save Stop Script

Simply removing servers from the monitored Tcat server group should be enough for the Start script’s event listener to stop monitoring the metrics on the server that is being removed. But, if you would like to stop monitoring the metrics on all servers in the group, run this Stop script. It removes all monitors for the listed metrics from every server in the monitored Tcat server group. If the CSV save writer script is still running, the metric values it logs no longer contains changing values, but the CSV save writer script continues to log into the CSV files until you reconfigure the scheduler to stop running the CSV save writer script.

import org.mule.galaxy.util.SecurityUtils
import org.mule.galaxy.impl.jcr.JcrUtil

import org.springframework.context.ApplicationContext
import org.springmodules.jcr.JcrCallback
import java.util.concurrent.Executors
import java.util.concurrent.ExecutionException
import java.util.concurrent.Callable
import java.util.concurrent.TimeUnit

// The below variables are for the user to configure, to set what is to
// be monitored on which server group.
def groupId = "401e81bf-b792-49fd-9006-eff59cd29387"
def objectNames = [ "Catalina:type=GlobalRequestProcessor,name=http-8080",
def attributeNames = [ "requestCount", "currentThreadsBusy" ]
def trackDeltas = [ false, false ]
def period = 10

// You probably shouldn't change variables below.

def c = applicationContext
// Copy into a local var, referenced in closure.
def logger = log
def serverManager = c.getBean("serverManager")
def chartService = c.getBean("chartService")
def sf = c.getBean("sessionFactory")

def Callable deleteMonitorsCallable = {
        JcrUtil.doInTransaction(sf, { session ->

            def deleteMonitors = { serverId, charts ->
                // Stop monitoring the JMX attribute in this server's agent.
                try {
                    for (int i = 0; i < objectNames.size(); i++) {
                        def objectName = objectNames[i]
                        def attributeName = attributeNames[i]
                        def trackDelta = trackDeltas[i]
                        def jmxCollectorInfoId = groupId + "|" + period + "|" + serverId + "|" + objectName + "|" + attributeName + "|" + trackDelta
                        charts.each { chart ->
                            if ( == jmxCollectorInfoId) {
                                println "Stopped monitoring ${jmxCollectorInfoId}"
                } catch (Exception e) {
                    println e

            // Delete monitors for all servers in this group.
            def results = serverManager.getServersForGroup(groupId, 0, -1, null)
            def servers = results.getData()

            def charts = chartService.getPortletCharts("csvsave")

            servers.each { server ->
                if (serverManager.isServerUp( {
                    deleteMonitors(, charts)
                } else {
                    println "Server ${} was unreachable."
        } as JcrCallback)
} as Callable
def executor = Executors.newSingleThreadExecutor()
try {
    executor.submit(deleteMonitorsCallable).get(60, TimeUnit.SECONDS)
} catch (ExecutionException e) {
    throw e?.cause?.cause


We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.