github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/website/pages/api-docs/agent.mdx (about) 1 --- 2 layout: api 3 page_title: Agent - HTTP API 4 sidebar_title: Agent 5 description: |- 6 The /agent endpoints interact with the local Nomad agent to interact with 7 members and servers. 8 --- 9 10 # Agent HTTP API 11 12 The `/agent` endpoints are used to interact with the local Nomad agent. 13 14 ## List Members 15 16 This endpoint queries the agent for the known peers in the gossip pool. This 17 endpoint is only applicable to servers. Due to the nature of gossip, this is 18 eventually consistent. 19 20 | Method | Path | Produces | 21 | ------ | ---------------- | ------------------ | 22 | `GET` | `/agent/members` | `application/json` | 23 24 The table below shows this endpoint's support for 25 [blocking queries](/api-docs#blocking-queries) and 26 [required ACLs](/api-docs#acls). 27 28 | Blocking Queries | ACL Required | 29 | ---------------- | ------------ | 30 | `NO` | `node:read` | 31 32 ### Sample Request 33 34 ```shell-session-session 35 $ curl \ 36 https://localhost:4646/v1/agent/members 37 ``` 38 39 ### Sample Response 40 41 ```json 42 { 43 "ServerName": "bacon-mac", 44 "ServerRegion": "global", 45 "ServerDC": "dc1", 46 "Members": [ 47 { 48 "Name": "bacon-mac.global", 49 "Addr": "127.0.0.1", 50 "Port": 4648, 51 "Tags": { 52 "mvn": "1", 53 "build": "0.5.5dev", 54 "port": "4647", 55 "bootstrap": "1", 56 "role": "nomad", 57 "region": "global", 58 "dc": "dc1", 59 "vsn": "1" 60 }, 61 "Status": "alive", 62 "ProtocolMin": 1, 63 "ProtocolMax": 5, 64 "ProtocolCur": 2, 65 "DelegateMin": 2, 66 "DelegateMax": 4, 67 "DelegateCur": 4 68 } 69 ] 70 } 71 ``` 72 73 ## List Servers 74 75 This endpoint lists the known server nodes. The `servers` endpoint is used to 76 query an agent in client mode for its list of known servers. Client nodes 77 register themselves with these server addresses so that they may dequeue work. 78 The servers endpoint can be used to keep this configuration up to date if there 79 are changes in the cluster. 80 81 | Method | Path | Produces | 82 | ------ | ---------------- | ------------------ | 83 | `GET` | `/agent/servers` | `application/json` | 84 85 The table below shows this endpoint's support for 86 [blocking queries](/api-docs#blocking-queries) and 87 [required ACLs](/api-docs#acls). 88 89 | Blocking Queries | ACL Required | 90 | ---------------- | ------------ | 91 | `NO` | `agent:read` | 92 93 ### Sample Request 94 95 ```shell-session 96 $ curl \ 97 https://localhost:4646/v1/agent/servers 98 ``` 99 100 ### Sample Response 101 102 ```json 103 ["127.0.0.1:4647"] 104 ``` 105 106 ## Update Servers 107 108 This endpoint updates the list of known servers to the provided list. This 109 **replaces** all previous server addresses with the new list. 110 111 | Method | Path | Produces | 112 | ------ | ---------------- | -------------- | 113 | `POST` | `/agent/servers` | `(empty body)` | 114 115 The table below shows this endpoint's support for 116 [blocking queries](/api-docs#blocking-queries) and 117 [required ACLs](/api-docs#acls). 118 119 | Blocking Queries | ACL Required | 120 | ---------------- | ------------- | 121 | `NO` | `agent:write` | 122 123 ### Parameters 124 125 - `address` `(string: <required>)` - Specifies the list of addresses in the 126 format `ip:port`. This is specified as a query string! 127 128 ### Sample Request 129 130 ```shell-session 131 $ curl \ 132 --request POST \ 133 https://localhost:4646/v1/agent/servers?address=1.2.3.4:4647&address=5.6.7.8:4647 134 ``` 135 136 ## Query Self 137 138 This endpoint queries the state of the target agent (self). 139 140 | Method | Path | Produces | 141 | ------ | ------------- | ------------------ | 142 | `GET` | `/agent/self` | `application/json` | 143 144 The table below shows this endpoint's support for 145 [blocking queries](/api-docs#blocking-queries) and 146 [required ACLs](/api-docs#acls). 147 148 | Blocking Queries | ACL Required | 149 | ---------------- | ------------ | 150 | `NO` | `agent:read` | 151 152 ### Sample Request 153 154 ```shell-session 155 $ curl \ 156 https://localhost:4646/v1/agent/self 157 ``` 158 159 ### Sample Response 160 161 ```json 162 { 163 "config": { 164 "Addresses": { 165 "HTTP": "127.0.0.1", 166 "RPC": "127.0.0.1", 167 "Serf": "127.0.0.1" 168 }, 169 "AdvertiseAddrs": { 170 "HTTP": "127.0.0.1:4646", 171 "RPC": "127.0.0.1:4647", 172 "Serf": "127.0.0.1:4648" 173 }, 174 "BindAddr": "127.0.0.1", 175 "Client": { 176 "AllocDir": "", 177 "ChrootEnv": {}, 178 "ClientMaxPort": 14512, 179 "ClientMinPort": 14000, 180 "DisableRemoteExec": false, 181 "Enabled": true, 182 "GCDiskUsageThreshold": 99, 183 "GCInodeUsageThreshold": 99, 184 "GCInterval": 600000000000, 185 "MaxKillTimeout": "30s", 186 "Meta": {}, 187 "NetworkInterface": "lo0", 188 "NetworkSpeed": 0, 189 "NodeClass": "", 190 "Options": { 191 "driver.docker.volumes": "true" 192 }, 193 "Reserved": { 194 "CPU": 0, 195 "DiskMB": 0, 196 "MemoryMB": 0, 197 "ParsedReservedPorts": null, 198 "ReservedPorts": "" 199 }, 200 "Servers": null, 201 "StateDir": "" 202 }, 203 "Consul": { 204 "Addr": "", 205 "Auth": "", 206 "AutoAdvertise": true, 207 "CAFile": "", 208 "CertFile": "", 209 "ChecksUseAdvertise": false, 210 "ClientAutoJoin": true, 211 "ClientServiceName": "nomad-client", 212 "EnableSSL": false, 213 "KeyFile": "", 214 "ServerAutoJoin": true, 215 "ServerServiceName": "nomad", 216 "Timeout": 5000000000, 217 "Token": "", 218 "VerifySSL": false 219 }, 220 "DataDir": "", 221 "Datacenter": "dc1", 222 "DevMode": true, 223 "DisableAnonymousSignature": true, 224 "DisableUpdateCheck": false, 225 "EnableDebug": true, 226 "EnableSyslog": false, 227 "Files": null, 228 "HTTPAPIResponseHeaders": {}, 229 "LeaveOnInt": false, 230 "LeaveOnTerm": false, 231 "LogLevel": "DEBUG", 232 "NodeName": "", 233 "Ports": { 234 "HTTP": 4646, 235 "RPC": 4647, 236 "Serf": 4648 237 }, 238 "Region": "global", 239 "Revision": "f551dcb83e3ac144c9dbb90583b6e82d234662e9", 240 "Server": { 241 "BootstrapExpect": 0, 242 "DataDir": "", 243 "Enabled": true, 244 "EnabledSchedulers": null, 245 "HeartbeatGrace": "", 246 "NodeGCThreshold": "", 247 "NumSchedulers": 0, 248 "ProtocolVersion": 0, 249 "RejoinAfterLeave": false, 250 "RetryInterval": "30s", 251 "RetryJoin": [], 252 "RetryMaxAttempts": 0, 253 "StartJoin": [] 254 }, 255 "SyslogFacility": "LOCAL0", 256 "TLSConfig": { 257 "CAFile": "", 258 "CertFile": "", 259 "EnableHTTP": false, 260 "EnableRPC": false, 261 "KeyFile": "", 262 "VerifyServerHostname": false 263 }, 264 "Telemetry": { 265 "CirconusAPIApp": "", 266 "CirconusAPIToken": "", 267 "CirconusAPIURL": "", 268 "CirconusBrokerID": "", 269 "CirconusBrokerSelectTag": "", 270 "CirconusCheckDisplayName": "", 271 "CirconusCheckForceMetricActivation": "", 272 "CirconusCheckID": "", 273 "CirconusCheckInstanceID": "", 274 "CirconusCheckSearchTag": "", 275 "CirconusCheckSubmissionURL": "", 276 "CirconusCheckTags": "", 277 "CirconusSubmissionInterval": "", 278 "CollectionInterval": "1s", 279 "DataDogAddr": "", 280 "DataDogTags": [], 281 "DisableHostname": false, 282 "PublishAllocationMetrics": false, 283 "PublishNodeMetrics": false, 284 "StatsdAddr": "", 285 "StatsiteAddr": "", 286 "UseNodeName": false 287 }, 288 "Vault": { 289 "Addr": "https://vault.service.consul:8200", 290 "AllowUnauthenticated": true, 291 "ConnectionRetryIntv": 30000000000, 292 "Enabled": null, 293 "Role": "", 294 "TLSCaFile": "", 295 "TLSCaPath": "", 296 "TLSCertFile": "", 297 "TLSKeyFile": "", 298 "TLSServerName": "", 299 "TLSSkipVerify": null, 300 "TaskTokenTTL": "", 301 "Token": "root" 302 }, 303 "Version": "0.5.5", 304 "VersionPrerelease": "dev" 305 }, 306 "member": { 307 "Addr": "127.0.0.1", 308 "DelegateCur": 4, 309 "DelegateMax": 4, 310 "DelegateMin": 2, 311 "Name": "bacon-mac.global", 312 "Port": 4648, 313 "ProtocolCur": 2, 314 "ProtocolMax": 5, 315 "ProtocolMin": 1, 316 "Status": "alive", 317 "Tags": { 318 "role": "nomad", 319 "region": "global", 320 "dc": "dc1", 321 "vsn": "1", 322 "mvn": "1", 323 "build": "0.5.5dev", 324 "port": "4647", 325 "bootstrap": "1" 326 } 327 }, 328 "stats": { 329 "runtime": { 330 "cpu_count": "8", 331 "kernel.name": "darwin", 332 "arch": "amd64", 333 "version": "go1.8", 334 "max_procs": "7", 335 "goroutines": "79" 336 }, 337 "nomad": { 338 "server": "true", 339 "leader": "true", 340 "leader_addr": "127.0.0.1:4647", 341 "bootstrap": "false", 342 "known_regions": "1" 343 }, 344 "raft": { 345 "num_peers": "0", 346 "fsm_pending": "0", 347 "last_snapshot_index": "0", 348 "last_log_term": "2", 349 "commit_index": "144", 350 "term": "2", 351 "last_log_index": "144", 352 "protocol_version_max": "3", 353 "snapshot_version_max": "1", 354 "latest_configuration_index": "1", 355 "latest_configuration": "[{Suffrage:Voter ID:127.0.0.1:4647 Address:127.0.0.1:4647}]", 356 "last_contact": "never", 357 "applied_index": "144", 358 "protocol_version": "1", 359 "protocol_version_min": "0", 360 "snapshot_version_min": "0", 361 "state": "Leader", 362 "last_snapshot_term": "0" 363 }, 364 "client": { 365 "heartbeat_ttl": "17.79568937s", 366 "node_id": "fb2170a8-257d-3c64-b14d-bc06cc94e34c", 367 "known_servers": "127.0.0.1:4647", 368 "num_allocations": "0", 369 "last_heartbeat": "10.107423052s" 370 }, 371 "serf": { 372 "event_time": "1", 373 "event_queue": "0", 374 "encrypted": "false", 375 "member_time": "1", 376 "query_time": "1", 377 "intent_queue": "0", 378 "query_queue": "0", 379 "members": "1", 380 "failed": "0", 381 "left": "0", 382 "health_score": "0" 383 } 384 } 385 } 386 ``` 387 388 ## Join Agent 389 390 This endpoint introduces a new member to the gossip pool. This endpoint is only 391 eligible for servers. 392 393 | Method | Path | Produces | 394 | ------ | ------------- | ------------------ | 395 | `POST` | `/agent/join` | `application/json` | 396 397 The table below shows this endpoint's support for 398 [blocking queries](/api-docs#blocking-queries) and 399 [required ACLs](/api-docs#acls). 400 401 | Blocking Queries | ACL Required | 402 | ---------------- | ------------ | 403 | `NO` | `none` | 404 405 ### Parameters 406 407 - `address` `(string: <required>)` - Specifies the address to join in the 408 `ip:port` format. This is provided as a query parameter and may be specified 409 multiple times to join multiple servers. 410 411 ### Sample Request 412 413 ```shell-session 414 $ curl \ 415 --request POST \ 416 https://localhost:4646/v1/agent/join?address=1.2.3.4&address=5.6.7.8 417 ``` 418 419 ### Sample Response 420 421 ```json 422 { 423 "error": "", 424 "num_joined": 2 425 } 426 ``` 427 428 ## Force Leave Agent 429 430 This endpoint forces a member of the gossip pool from the `"failed"` state to 431 the `"left"` state. This allows the consensus protocol to remove the peer and 432 stop attempting replication. This is only applicable for servers. 433 434 | Method | Path | Produces | 435 | ------ | -------------------- | ------------------ | 436 | `POST` | `/agent/force-leave` | `application/json` | 437 438 The table below shows this endpoint's support for 439 [blocking queries](/api-docs#blocking-queries) and 440 [required ACLs](/api-docs#acls). 441 442 | Blocking Queries | ACL Required | 443 | ---------------- | ------------- | 444 | `NO` | `agent:write` | 445 446 ### Parameters 447 448 - `node` `(string: <required>)` - Specifies the name of the node to force leave. 449 450 ### Sample Request 451 452 ```shell-session 453 $ curl \ 454 --request POST \ 455 https://localhost:4646/v1/agent/force-leave?node=client-ab2e23dc 456 ``` 457 458 ## Health 459 460 This endpoint returns whether or not the agent is healthy. When using Consul it 461 is the endpoint Nomad will register for its own health checks. 462 463 When the agent is unhealthy 500 will be returned along with JSON response 464 containing an error message. 465 466 | Method | Path | Produces | 467 | ------ | --------------- | ------------------ | 468 | `GET` | `/agent/health` | `application/json` | 469 470 The table below shows this endpoint's support for 471 [blocking queries](/api-docs#blocking-queries) and 472 [required ACLs](/api-docs#acls). 473 474 | Blocking Queries | ACL Required | 475 | ---------------- | ------------ | 476 | `NO` | `none` | 477 478 ### Sample Request 479 480 ```shell-session 481 $ curl \ 482 https://localhost:4646/v1/agent/health 483 ``` 484 485 ### Sample Response 486 487 ```json 488 { 489 "client": { 490 "message": "ok", 491 "ok": true 492 }, 493 "server": { 494 "message": "ok", 495 "ok": true 496 } 497 } 498 ``` 499 500 ## Stream Logs 501 502 This endpoint streams logs from the local agent until the connection is closed 503 504 | Method | Path | Produces | 505 | ------ | ---------------- | ------------------ | 506 | `GET` | `/agent/monitor` | `application/json` | 507 508 The table below shows this endpoint's support for 509 [blocking queries](/api-docs#blocking-queries) and 510 [required ACLs](/api-docs#acls). 511 512 | Blocking Queries | ACL Required | 513 | ---------------- | ------------ | 514 | `NO` | `agent:read` | 515 516 ### Parameters 517 518 - `log_level` `(string: "info")` - Specifies a text string containing a log level 519 to filter on, such as `info`. Possible values include `trace`, `debug`, 520 `info`, `warn`, `error` 521 522 - `log_json` `(bool: false)` - Specifies if the log format for streamed logs 523 should be JSON. 524 525 - `node_id` `(string: "a57b2adb-1a30-2dda-8df0-25abb0881952")` - Specifies a text 526 string containing a node-id to target for streaming. 527 528 - `server_id` `(string: "server1.global")` - Specifies a text 529 string containing a server name or "leader" to target a specific remote server 530 or leader for streaming. 531 532 - `plain` `(bool: false)` - Specifies if the response should be JSON or 533 plaintext 534 535 ### Sample Request 536 537 ```shell-session 538 $ curl \ 539 https://localhost:4646/v1/agent/monitor?log_level=debug&server_id=leader 540 541 $ curl \ 542 https://localhost:4646/v1/agent/monitor?log_level=debug&node_id=a57b2adb-1a30-2dda-8df0-25abb0881952 543 ``` 544 545 ### Sample Response 546 547 ```json 548 { 549 "Offset": 0, 550 "Data": "NTMxOTMyCjUzMTkzMwo1MzE5MzQKNTMx..." 551 "FileEvent": "log" 552 } 553 ``` 554 555 #### Field Reference 556 557 The return value is a stream of frames. These frames contain the following 558 fields: 559 560 - `Data` - A base64 encoding of the bytes being streamed. 561 562 - `FileEvent` - An event that could cause a change in the streams position. The 563 possible value for this endpoint is "log". 564 565 - `Offset` - Offset is the offset into the stream. 566 567 ## Agent Runtime Profiles 568 569 This endpoint is the equivalent of Go's /debug/pprof endpoint but is protected 570 by ACLs and supports remote forwarding to a client node or server. See the 571 [Golang documentation](https://golang.org/pkg/runtime/pprof/#Profile) for a list of available profiles. 572 573 | Method | Path | Produces | 574 | ------ | ------------------------------ | -------------------------- | 575 | `GET` | `/agent/pprof/cmdline` | `text/plain` | 576 | `GET` | `/agent/pprof/profile` | `application/octet-stream` | 577 | `GET` | `/agent/pprof/trace` | `application/octet-stream` | 578 | `GET` | `/agent/pprof/<pprof profile>` | `application/octet-stream` | 579 580 The table below shows this endpoint's support for 581 [blocking queries](/api-docs#blocking-queries) and 582 [required ACLs](/api-docs#acls). 583 584 | Blocking Queries | ACL Required | 585 | ---------------- | ------------- | 586 | `NO` | `agent:write` | 587 588 ### Default Behavior 589 590 This endpoint is enabled whenever ACLs are enabled. Due to the potentially 591 sensitive nature of data contained in profiles, as well as their significant 592 performance impact, the agent/pprof endpoint is protected by a high level ACL: 593 `agent:write`. For these reasons its recommended to leave [`enable_debug`](/docs/configuration#enable_debug) 594 unset and only use the ACL-protected endpoints. 595 596 The following table explains when each endpoint is available: 597 598 | Endpoint | `enable_debug` | ACLs | **Available?** | 599 | --------------- | -------------- | ---- | -------------- | 600 | /v1/agent/pprof | unset | n/a | no | 601 | /v1/agent/pprof | `true` | n/a | yes | 602 | /v1/agent/pprof | `false` | n/a | no | 603 | /v1/agent/pprof | unset | off | no | 604 | /v1/agent/pprof | unset | on | **yes** | 605 | /v1/agent/pprof | `true` | off | yes | 606 | /v1/agent/pprof | `false` | on | **yes** | 607 608 ### Parameters 609 610 - `node_id` `(string: "a57b2adb-1a30-2dda-8df0-25abb0881952")` - Specifies a text 611 string containing a Node ID to target for profiling. 612 613 - `server_id` `(string: "server1.global")` - Specifies a text 614 string containing a Server ID, name, or `leader` to target a specific remote 615 server or leader for profiling. 616 617 - `seconds` `(int: 3)` - Specifies the amount of time to run a profile or trace 618 request for. 619 620 - `debug` `(int: 1)` - Specifies if a given pprof profile should be returned as 621 human readable plain text instead of the pprof binary format. Defaults to 0, 622 setting to 1 enables human readable plain text. 623 624 ### Sample Request 625 626 ```shell-session 627 $ curl -O -J \ 628 --header "X-Nomad-Token: 8176afd3-772d-0b71-8f85-7fa5d903e9d4" \ 629 https://localhost:4646/v1/agent/pprof/goroutine?server_id=leader 630 631 $ go tool pprof goroutine 632 633 $ curl -O -J \ 634 --header "X-Nomad-Token: 8176afd3-772d-0b71-8f85-7fa5d903e9d4" \ 635 https://localhost:4646/v1/agent/profile?seconds=5&node_id=a57b2adb-1a30-2dda-8df0-25abb0881952 636 637 $ go tool pprof profile 638 639 $ curl -O -J \ 640 --header "X-Nomad-Token: 8176afd3-772d-0b71-8f85-7fa5d903e9d4" \ 641 https://localhost:4646/v1/agent/trace?&seconds=5&server_id=server1.global 642 643 go tool trace trace 644 ```