Mesos REST API

Issue

  • How does the Mesos REST API work?
  • I would like to understand what is behind cje run support-mesos.

Environment

Resolution

Mesos provides a list HTTP Endpoints and for Masters and Agents.

IMPORTANT: This endpoints are used by cje run support-mesos (see [How to use cje command line tools]) to extract relevant information about the Mesos component in your CJE cluster .

Following some examples of the Mesos API REST for master and slaves (Note: cje run support-mesos is the recommendation) as the scope of this article is understanding the API

Master

  • System:

curl -u $MESOS_USER:$MESOS_PASSWORD -X GET http://mesos.$CLUSTER_FQDN/system/stats.json

  • Slaves:

curl -u $MESOS_USER:$MESOS_PASSWORD -X GET http://mesos.$CLUSTER_FQDN/slaves

Slave

  • System:

curl -u $MESOS_USER:$MESOS_PASSWORD -X GET http://$SLAVE_HOST_NAME:$SLAVE_PORT/system/stats.json

where:

  • $CLUSTER_FQDN is the domain name of palace in your cluster:
  • $MESOS_USER is the palace username
  • $MESOS_PASSWORD is the palace password
  • $SLAVE_HOST_NAME is one mesos slave hostname
  • $SLAVE_PORT is one mesos slave port

Concrete example

From the root of the CJE project, you can retrieve the different variables:

export MESOS_USER=$(cje run echo-secrets mesos_web_ui_username)
export MESOS_PASSWORD=$(cje run echo-secrets mesos_web_ui_password)
export CLUSTER_FQDN=$(awk '/domain_name/ {print $3}' .dna/project.config)
  • Master | System
curl -u $MESOS_USER:$MESOS_PASSWORD -X GET http://mesos.$CLUSTER_FQDN/system/stats.json
{
avg_load_15min: 0.09,
avg_load_1min: 0.14,
avg_load_5min: 0.13,
cpus_total: 2,
mem_free_bytes: 4752334848,
mem_total_bytes: 8371818496
}
  • Master | Slave
$ curl -u $MESOS_USER:$MESOS_PASSWORD -X GET http://mesos.$CLUSTER_FQDN/slaves
{
slaves: [
{
id: "400c68cb-827b-4c9d-a0f0-6bdad1e94053-S3",
pid: "slave(1)@10.16.7.253:5051",
hostname: "example.slave.com",
registered_time: 1513079996.53669,
resources: {
cpus: 4,
disk: 45140,
mem: 15023,
ports: "[31000-32000]"
},
used_resources: {
cpus: 1.1,
disk: 0,
mem: 14080,
ports: "[31080-31080, 31090-31090, 31092-31092, 31164-31166, 31693-31695, 31840-31842, 31844-31846, 31860-31862]"
},
offered_resources: {
cpus: 0,
disk: 0,
mem: 0
},
reserved_resources: { },
unreserved_resources: {
cpus: 4,
disk: 45140,
mem: 15023,
ports: "[31000-32000]"
},
attributes: {
availability_zone: "us-east-1d",
jce_cjoc: "true",
jce_masters: "true"
},
active: true,
version: "0.28.2",
reserved_resources_full: { },
used_resources_full: [
{
name: "cpus",
type: "SCALAR",
scalar: {
value: 1.1
},
role: "*"
},
{
name: "mem",
type: "SCALAR",
scalar: {
value: 14080
},
role: "*"
},
{
name: "ports",
type: "RANGES",
ranges: {
range: [
{
begin: 31080,
end: 31080
},
{
begin: 31090,
end: 31090
},
{
begin: 31092,
end: 31092
},
{
begin: 31164,
end: 31166
},
{
begin: 31693,
end: 31695
},
{
begin: 31840,
end: 31842
},
{
begin: 31844,
end: 31846
},
{
begin: 31860,
end: 31862
}
]
},
role: "*"
}
],
offered_resources_full: [ ]
}, ... 
  • Slave | System

From one of the listed slaves from the command above we selected get the $PORT from pid and the
hostname then:

$ curl -u $MESOS_USER:$MESOS_PASSWORD -X GET http://$example.slave.com:5051/system/stats.json
{
avg_load_15min: 1.56,
avg_load_1min: 2.14,
avg_load_5min: 1.86,
cpus_total: 4,
mem_free_bytes: 158203904,
mem_total_bytes: 16827531264
}

Tested product/plugin versions

The latest update of this article has been tested with:

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.