github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/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 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 ## Host 501 502 This endpoint returns data about the agent's host environment from the 503 perspective of the agent. It is included in the archive produced by 504 nomad operator debug. Known sensitive environment variables are shown as 505 `<redacted>`, but the response may still contain sensitive 506 information. 507 508 | Method | Path | Produces | 509 | ------ | ------------- | ------------------ | 510 | `GET` | `/agent/host` | `application/json` | 511 512 The table below shows this endpoint's support for 513 [blocking queries](/api-docs#blocking-queries) and 514 [required ACLs](/api-docs#acls). 515 516 | Blocking Queries | ACL Required | 517 | ---------------- | ------------ | 518 | `NO` | `agent:read` | 519 520 ### Parameters 521 522 - `server_id` `(string: <optional>)` - Specify the server name for 523 targeting. 524 525 - `node_id` `(string: <optional>)` - Specify the client node id for 526 targeting. 527 528 ### Sample Request 529 530 ```shell-session 531 $ curl \ 532 https://localhost:4646/v1/agent/host?node_id=4bb9aca7-d43b-43fc-d604-3a271ef0a6c0 533 ``` 534 535 ### Sample Response 536 537 ```json 538 { 539 "AgentID": "4bb9aca7-d43b-43fc-d604-3a271ef0a6c0", 540 "HostData": { 541 "OS": "x86_64 ip-172-31-92-147 4.15.0-1007-aws Linux #7-Ubuntu SMP Tue Apr 24 10:56:17 UTC 2018", 542 "Network": [ 543 { 544 "DialPacket": "\"udp4\" \"\"", 545 "DialStream": "\"tcp4\" \"\"", 546 "ListenPacket": "\"udp4\" \"\"", 547 "ListenStream": "\"tcp4\" \"\"", 548 "address": "127.0.0.1", 549 "binary": "01111111000000000000000000000001", 550 "broadcast": "127.255.255.255", 551 "first_usable": "127.0.0.1", 552 "hex": "7f000001", 553 "host": "127.0.0.1", 554 "last_usable": "127.255.255.254", 555 "mask_bits": "8", 556 "netmask": "255.0.0.0", 557 "network": "127.0.0.0", 558 "octets": "127 0 0 1", 559 "port": "0", 560 "size": "16777216", 561 "string": "127.0.0.1/8", 562 "type": "IPv4", 563 "uint32": "2130706433" 564 } 565 ], 566 "ResolvConf": "nameserver 172.17.0.1\nnameserver 8.8.8.8\n", 567 "Hosts": "127.0.0.1 localhost\n\n# The following lines are desirable for IPv6 capable hosts\n::1 ip6-localhost ip6-loopback\nfe00::0 ip6-localnet\nff00::0 ip6-mcastprefix\nff02::1 ip6-allnodes\nff02::2 ip6-allrouters\nff02::3 ip6-allhosts\n127.0.0.1 ip-172-31-71-163\n127.0.0.1 ip-172-31-92-147\n", 568 "Environment": { 569 "INVOCATION_ID": "b106b6ac67764c9b9f85c5cc5c3357e5", 570 "JOURNAL_STREAM": "9:109527", 571 "LANG": "C.UTF-8", 572 "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 573 }, 574 "Disk": { 575 "/": { 576 "DiskMB": 7876, 577 "UsedMB": 4287 578 } 579 } 580 } 581 } 582 ``` 583 584 ## Stream Logs 585 586 This endpoint streams logs from the local agent until the connection is closed 587 588 | Method | Path | Produces | 589 | ------ | ---------------- | ------------------ | 590 | `GET` | `/agent/monitor` | `application/json` | 591 592 The table below shows this endpoint's support for 593 [blocking queries](/api-docs#blocking-queries) and 594 [required ACLs](/api-docs#acls). 595 596 | Blocking Queries | ACL Required | 597 | ---------------- | ------------ | 598 | `NO` | `agent:read` | 599 600 ### Parameters 601 602 - `log_level` `(string: "info")` - Specifies a text string containing a log level 603 to filter on, such as `info`. Possible values include `trace`, `debug`, 604 `info`, `warn`, `error` 605 606 - `log_json` `(bool: false)` - Specifies if the log format for streamed logs 607 should be JSON. 608 609 - `node_id` `(string: "a57b2adb-1a30-2dda-8df0-25abb0881952")` - Specifies a text 610 string containing a node-id to target for streaming. 611 612 - `server_id` `(string: "server1.global")` - Specifies a text 613 string containing a server name or "leader" to target a specific remote server 614 or leader for streaming. 615 616 - `plain` `(bool: false)` - Specifies if the response should be JSON or 617 plaintext 618 619 ### Sample Request 620 621 ```shell-session 622 $ curl \ 623 https://localhost:4646/v1/agent/monitor?log_level=debug&server_id=leader 624 625 $ curl \ 626 https://localhost:4646/v1/agent/monitor?log_level=debug&node_id=a57b2adb-1a30-2dda-8df0-25abb0881952 627 ``` 628 629 ### Sample Response 630 631 ```json 632 { 633 "Offset": 0, 634 "Data": "NTMxOTMyCjUzMTkzMwo1MzE5MzQKNTMx..." 635 "FileEvent": "log" 636 } 637 ``` 638 639 #### Field Reference 640 641 The return value is a stream of frames. These frames contain the following 642 fields: 643 644 - `Data` - A base64 encoding of the bytes being streamed. 645 646 - `FileEvent` - An event that could cause a change in the streams position. The 647 possible value for this endpoint is "log". 648 649 - `Offset` - Offset is the offset into the stream. 650 651 ## Agent Runtime Profiles 652 653 This endpoint is the equivalent of Go's /debug/pprof endpoint but is protected 654 by ACLs and supports remote forwarding to a client node or server. See the 655 [Golang documentation](https://golang.org/pkg/runtime/pprof/#Profile) for a list of available profiles. 656 657 | Method | Path | Produces | 658 | ------ | ------------------------------ | -------------------------- | 659 | `GET` | `/agent/pprof/cmdline` | `text/plain` | 660 | `GET` | `/agent/pprof/profile` | `application/octet-stream` | 661 | `GET` | `/agent/pprof/trace` | `application/octet-stream` | 662 | `GET` | `/agent/pprof/<pprof profile>` | `application/octet-stream` | 663 664 The table below shows this endpoint's support for 665 [blocking queries](/api-docs#blocking-queries) and 666 [required ACLs](/api-docs#acls). 667 668 | Blocking Queries | ACL Required | 669 | ---------------- | ------------- | 670 | `NO` | `agent:write` | 671 672 ### Default Behavior 673 674 This endpoint is enabled whenever ACLs are enabled. Due to the potentially 675 sensitive nature of data contained in profiles, as well as their significant 676 performance impact, the agent/pprof endpoint is protected by a high level ACL: 677 `agent:write`. For these reasons its recommended to leave [`enable_debug`](/docs/configuration#enable_debug) 678 unset and only use the ACL-protected endpoints. 679 680 The following table explains when each endpoint is available: 681 682 | Endpoint | `enable_debug` | ACLs | **Available?** | 683 | --------------- | -------------- | ---- | -------------- | 684 | /v1/agent/pprof | unset | n/a | no | 685 | /v1/agent/pprof | `true` | n/a | yes | 686 | /v1/agent/pprof | `false` | n/a | no | 687 | /v1/agent/pprof | unset | off | no | 688 | /v1/agent/pprof | unset | on | **yes** | 689 | /v1/agent/pprof | `true` | off | yes | 690 | /v1/agent/pprof | `false` | on | **yes** | 691 692 ### Parameters 693 694 - `node_id` `(string: "a57b2adb-1a30-2dda-8df0-25abb0881952")` - Specifies a text 695 string containing a Node ID to target for profiling. 696 697 - `server_id` `(string: "server1.global")` - Specifies a text 698 string containing a Server ID, name, or `leader` to target a specific remote 699 server or leader for profiling. 700 701 - `seconds` `(int: 3)` - Specifies the amount of time to run a profile or trace 702 request for. 703 704 - `debug` `(int: 1)` - Specifies if a given pprof profile should be returned as 705 human readable plain text instead of the pprof binary format. Defaults to 0, 706 setting to 1 enables human readable plain text. 707 708 ### Sample Request 709 710 ```shell-session 711 $ curl -O -J \ 712 --header "X-Nomad-Token: 8176afd3-772d-0b71-8f85-7fa5d903e9d4" \ 713 https://localhost:4646/v1/agent/pprof/goroutine?server_id=leader 714 715 $ go tool pprof goroutine 716 717 $ curl -O -J \ 718 --header "X-Nomad-Token: 8176afd3-772d-0b71-8f85-7fa5d903e9d4" \ 719 https://localhost:4646/v1/agent/profile?seconds=5&node_id=a57b2adb-1a30-2dda-8df0-25abb0881952 720 721 $ go tool pprof profile 722 723 $ curl -O -J \ 724 --header "X-Nomad-Token: 8176afd3-772d-0b71-8f85-7fa5d903e9d4" \ 725 https://localhost:4646/v1/agent/trace?&seconds=5&server_id=server1.global 726 727 go tool trace trace 728 ```