Support | Forums | Apps | Logscape.com

Collector - JSON

The collector capable of running Logscape apps, and due to this can be used to collect metrics from your JMX Endpoints. Using a simple GroovyScript we will create an app to query a JMX endpoint, and put that data into the Logscape Cloud.

For a guide on how to build your own Logscape apps, you can visit the App Introduction Page.

Querying a JSON endpoint

Thus Groovy script connects to your JSON endpoint, pulls the JSON and then converts it into a Logscape compliant format, in this example, the script will simple query an endpoint which will return the time and date.

import groovy.json.*
 
def propertyMissing(String name) {}
 
def log_kv(map){
        def timestamp = new Date()
        builder=[]
 
        for(def key:map.keySet()){
                def  v = map[key]
                builder.add(key + ":" + v)
        }
 
        message = " "  +  timestamp + " " + builder.join(", ")
        return message
}
 
pout = pout == null ? System.out : pout
perr = perr == null ? System.err : perr
 
def stdOut = pout
def stdErr = perr
 
URL apiUrl = new URL("http://date.jsontest.com/")
 
def mySlurper = new JsonSlurper().parse(apiUrl)
 
pout << log_kv(mySlurper)

After creating a working groovy script, it's time to design the .bundle file, the bundle gives Logscapes jobs to run relating to the app.

The Bundle file

<Bundle name="ProjectSymphonyApp" version="1.0" system="false">
<status>UNINSTALLED</status>
	<owner>info@logscape.com</owner>
	<services>
		<Service>
			<name>YOUR_SERVICE_NAME</name>
			<resourceSelection>YOUR_FILTER</resourceSelection>
			<fork>true</fork>
			<background>true</background>
			<instanceCount>-1</instanceCount>
			<pauseSeconds>YOUR_PAUSE</pauseSeconds>
			<script>YOUR_GROOVY_SCRIPT.groovy</script>
		</Service>
	</services>
</Bundle>

This bundle is a small section of a much larger bundle, but shows how to include your Groovy script.

To finish, simply zip, and deploy your app as shown in the app guide, your collector will now collect stats from your JMX endpoint.