1

Is there any way to get the number of instances of application running in marathon ? I am running a basic python webapp of 2 instances in marathon. I want to write a script to increase or decrease the number of instances automatically when the load of the mesos-slave spikes up or down. For that I need to get the applications initial no of instances running. Can someone please help on this ?

2 Answers2

4

Marathon REST API is your friend. Have a look here and here. In pseudo-python, a script you want may look something like this:

def scaleTo(instances, force=False):
  marathon = 'http://localhost:8080'
  url = '{}/v2/apps/<your-app-id>'.format(marathon)
  headers = {
             'Content-Type': 'application/json',
             'Accept': 'application/json'
            }
  params = {'force': 'true' if force else 'false'}
  payload = {'instances': instances}

  r = requests.put(url, headers=headers, params=params, json=payload, verify=False)

  r.raise_for_status()
rukletsov
  • 1,041
  • 5
  • 7
1

I think you are interested in auto scaling applications on Marathon. Take a look at marathon-autoscale repository. Those scripts might be useful although those are just for PoC.

blurblah
  • 64
  • 3