Hosts

Registering host information

Registering an agent-running host to Mackerel.

POST /api/v0/hosts

Required permissions for API key

  • Read
  • Write

Input

By designating the role to which a host belongs in the input, the host will be assigned to that role. If a service or role name that does not yet exist is entered, it will be created.

This object holds the following keys:

KEY TYPE DESCRIPTION
name string name of the host
displayName string [optional] host management name
customIdentifier string [optional] a user-specific identifier for the host
meta object host metadata *1
interfaces array[object] [optional] host network interface information*2
roleFullnames array[string] [optional] an array of the full name of the role to which the host belongs*3
checks array[hash[string]] [optional] an array of the check monitoring item that monitors the host*4

Response

Success

{
  "id": <hostId>
}

<hostId> : The host ID that was assigned to this host. With this request the host will be identified by this ID.

Error

STATUS CODE DESCRIPTION
400 when the input is in a format that can’t be accepted.
403 when the API doesn't have the required permissions / when accessing from outside the permitted IP address range

*1 meta

meta contains various information.

KEY TYPE DESCRIPTION
agent-name string agent name e.g. "mackerel-agent/0.27.0 (Revision dfbccea)"
agent-revision string agent revision (Git commit SHA1) e.g. "2f531c6"
agent-version string agent version, e.g. "0.4.2"
block_device hash[object] block device info. object that contains key name, variables like size etc.
cpu array[object] each CPU’s core info. each object holds mhz and model_name
filesystem hash[object] filesystem information. an object that holds “key is a name of filesystem”, kb_available, kb_used, etc.
kernel hash[string] kernel information; can be got with the command uname
memory hash[string] memory information

*2 interfaces

One element of interfaces is an object that holds the following keys.

KEY TYPE DESCRIPTION
name string interface name, e.g. "eth0"
macAddress string [optional] interface MAC address
ipv4Addresses array[string] [optiona] interface IPv4 addresses
ipv6Addresses array[string] [optiona] interface IPv6 addresses
ipAddress string [optional] interface IPv4 address
ipv6Address string [optional] interface IPv6 address

However, if ipAddress and ipv4Addresses or ipv6Address and ipv6Addresses are specified at the same time, then ipv4Addresses and ipv6Addresses will take precedence.

*3 roleFullnames

The full names of roles are in this character string format: <service name>:<role name>

e.g. A role named db-master in a service named Hatena-Bookmark would be Hatena-Bookmark:db-master

Usable characters include /^[A-Za-z0-9][A-Za-z0-9_-]+$/

*4 checks

One element of checks is an object that holds the following keys.

KEY TYPE DESCRIPTION
name string name of the monitor ([a-zA-Z0-9_-]+).
memo string [optional] a memo about the monitor.

Getting host information

GET /api/v0/hosts/<hostId>

Required permissions for API key

  • Read

Response

{
  "host": <host>
}

<host> is an object that holds the following keys:

KEY TYPE DESCRIPTION
createdAt number the host's registration timestamp(in epoch seconds)
id string the host's ID
name string the name of the host
displayName string [optional] the host's management name
customIdentifier string [optional] a user-specific identifier for the host
meta object host metadata
interfaces array[object] host network interface information
type string classification of the host("agent", "container-agent", "cloud" etc.)
status string status of the host("working", "standby" etc.)
memo string notes related to the host; can be edited from the management screen
isRetired boolean whether or not the host is retired
retiredAt number [optional] the host's retirement timestamp(in epoch seconds)
roles hash[array[string]] List of the roles to which the host belongs. The keys are service names, and the values are arrays of role names.

Updating host information

PUT /api/v0/hosts/<hostId>

Required permissions for API key

  • Read
  • Write

Input

Same as Registering host information.

A host remains to belong to the roles which you didn't specify by roleFullnames. If you want to Un-assign roles from a host, please use Updating host roles API.

Response

Success

{
  "id": <hostId>
}

Error

STATUS CODE DESCRIPTION
404 when the host that corresponds to the <hostId> can’t be located
400 when JSON format is incorrect
403 when the API doesn't have the required permissions / when accessing from outside the permitted IP address range

Updating host status

POST /api/v0/hosts/<hostId>/status

Required permissions for API key

  • Read
  • Write

Input

{
  "status": <hostStatus>
}

<hostStatus> is one of these: "standby", "working", "maintenance", or "poweroff"

Response

Success

{
  "success": true
}

Error

STATUS CODE DESCRIPTION
404 when the host that corresponds to the <hostId> can’t be located
400 when JSON format is incorrect
403 when the API doesn't have the required permissions / when accessing from outside the permitted IP address range

Updating host roles

PUT /api/v0/hosts/<hostId>/role-fullnames

Required permissions for API key

  • Write

Input

{
  "roleFullnames": [ <string>, <string>, … ]
}

roleFullnames is the same as roleFullnames object in Registering host information.

Response

Success

{
  "success": true
}

Error

STATUS CODE DESCRIPTION
404 when the host that corresponds to the hostId can’t be located
400 when JSON format is incorrect
400 when the format of roleFullnames is incorrect
403 when the API doesn't have the required permissions / when accessing from outside the permitted IP address range

Retiring hosts

This will retire a registered host.

POST /api/v0/hosts/<hostId>/retire

Required permissions for API key

  • Read
  • Write

Input

This will POST empty JSON.

{}

Response

Success

{
  "success": true
}

Error

STATUS CODE DESCRIPTION
404 when the host that corresponds to the <hostId> can’t be located
400 when JSON format is incorrect
403 when the API doesn't have the required permissions / when accessing from outside the permitted IP address range

list of hosts

GET /api/v0/hosts

/api/v0/hosts.json returns the same contents with the same query parameters.

Required permissions for API key

  • Read

Input (Query parameter)

The following parameter will extract hosts. If nothing has yet been assigned, all hosts will be returned.

PARAM TYPE DESCRIPTION
service string [optional] service name
role string [optional] role names in the service, multiple assignments possible (result will be a unit of the hosts that belong to each role) if service has not been assigned it will be ignored.
name string [optional] host name
status string [optional] extract host status, multiple assignments possible, defaults are working and standby.
customIdentifier string [optional] user-specific identifier for the host (registered at Registering host information or Updating host information API)

Response

{
  "hosts": [ <host>, <host>, …]
}

<host> is the same type as the object that changes in Getting host information


List of metric names

GET /api/v0/hosts/<hostId>/metric-names

Required permissions for API key

  • Read

Response

Success

{
  "names": [<metricName>, <metricName>, ...]
}
KEY TYPE DESCRIPTION
names array[string] The name of the metrics being posted in the Host.

Error

STATUS CODE DESCRIPTION
404 when the Host corresponding to <hostId> can't be found