Since we have started to use AppDynamics for our application I’ve installed an extension to monitor urls, to check if they up, check the return status code and so on.

But since AppDynamics supports not only Java extensions but also scripts I wrote this small script which monitors the provided URLs. This way seems to be easier to support and extend comparing to Java, because you don’t need open Java project each time to want to modify something in it or add new metrics.

This script uses Ruby 1.8.

require 'rubygems'
require 'open-uri'
require 'openssl'
require 'net/http'
require 'net/https'

def printMetric(metric, value)
    printf("name=Custom Metrics|Urls|%s, value=%d\n", metric, value)

def getRespCode(url)
  uri = URI.parse(url)

  http =, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  request =

  res = http.request(request)
  #print(res.code) # some other parameters you may use for metrics
  #return res.code

someUrl1 = ''
someUrl2 = 'https://gesundheit.gta/health/'
someUrl2 = ''

printMetric('/example', getRespCode(someUrl1).code)
printMetric('/gta', getRespCode(someUrl2).code)
printMetric('/doom', getRespCode(someUrl3).code)

Shell script

Since the logic is in ruby shell script is just a wrapper for it, so it should just run ruby script:

#!/usr/bin/env bash

ruby ./rest-monitor.rb
exit 0


This file is almost the same for every monitor, it basically tells machine agent how to execute the script. You can find more details in step 7 of original documentation. For my monitor it looks like this:

    <description>Rest call monitoring</description>
            <file os-type="linux"></file>

Now you just need to put these files under monitors folder and restart machine agent. Metrics will be available under Custom Metrics|Urls|<urlName>