github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/api-docs/client.mdx (about) 1 --- 2 layout: api 3 page_title: Client - HTTP API 4 description: |- 5 The /client endpoints are used to access client statistics and inspect 6 allocations running on a particular client. 7 --- 8 9 # Client HTTP API 10 11 The `/client` endpoints are used to interact with the Nomad clients. 12 13 Since Nomad 0.8.0, both a client and server can handle client endpoints. This is 14 particularly useful for when a direct connection to a client is not possible due 15 to the network configuration. For high volume access to the client endpoints, 16 particularly endpoints streaming file contents, direct access to the node should 17 be preferred as it avoids adding additional load to the servers. 18 19 When accessing the endpoints via the server, if the desired node is ambiguous 20 based on the URL, an additional `?node_id` query parameter must be provided to 21 disambiguate. 22 23 ## Read Stats 24 25 This endpoint queries the actual resources consumed on a node. The API endpoint 26 is hosted by the Nomad client and requests have to be made to the nomad client 27 whose resource usage metrics are of interest. 28 29 | Method | Path | Produces | 30 | ------ | --------------- | ------------------ | 31 | `GET` | `/client/stats` | `application/json` | 32 33 The table below shows this endpoint's support for 34 [blocking queries](/api-docs#blocking-queries) and 35 [required ACLs](/api-docs#acls). 36 37 | Blocking Queries | ACL Required | 38 | ---------------- | ------------ | 39 | `NO` | `node:read` | 40 41 ### Parameters 42 43 - `node_id` `(string: <optional>)` - Specifies the node to query. This is 44 required when the endpoint is being accessed via a server. This is specified as 45 part of the URL. Note, this must be the _full_ node ID, not the short 46 8-character one. This is specified as part of the path. 47 48 ### Sample Request 49 50 ```shell-session 51 $ curl \ 52 https://localhost:4646/v1/client/stats 53 ``` 54 55 ### Sample Response 56 57 ```json 58 { 59 "AllocDirStats": { 60 "Available": 142943150080, 61 "Device": "", 62 "InodesUsedPercent": 0.05312946180421879, 63 "Mountpoint": "", 64 "Size": 249783500800, 65 "Used": 106578206720, 66 "UsedPercent": 42.668233241448746 67 }, 68 "CPU": [ 69 { 70 "CPU": "cpu0", 71 "Idle": 80, 72 "System": 11, 73 "Total": 20, 74 "User": 9 75 }, 76 { 77 "CPU": "cpu1", 78 "Idle": 99, 79 "System": 0, 80 "Total": 1, 81 "User": 1 82 }, 83 { 84 "CPU": "cpu2", 85 "Idle": 89, 86 "System": 7.000000000000001, 87 "Total": 11, 88 "User": 4 89 }, 90 { 91 "CPU": "cpu3", 92 "Idle": 100, 93 "System": 0, 94 "Total": 0, 95 "User": 0 96 }, 97 { 98 "CPU": "cpu4", 99 "Idle": 92.92929292929293, 100 "System": 4.040404040404041, 101 "Total": 7.07070707070707, 102 "User": 3.0303030303030303 103 }, 104 { 105 "CPU": "cpu5", 106 "Idle": 99, 107 "System": 1, 108 "Total": 1, 109 "User": 0 110 }, 111 { 112 "CPU": "cpu6", 113 "Idle": 92.07920792079209, 114 "System": 4.9504950495049505, 115 "Total": 7.920792079207921, 116 "User": 2.9702970297029703 117 }, 118 { 119 "CPU": "cpu7", 120 "Idle": 99, 121 "System": 0, 122 "Total": 1, 123 "User": 1 124 } 125 ], 126 "CPUTicksConsumed": 1126.8044804480448, 127 "DeviceStats": [ 128 { 129 "InstanceStats": { 130 "6a61929e-d572-092d-5921-156a913f8e56": { 131 "Stats": { 132 "Attributes": { 133 "Used Memory": { 134 "Desc": "Memory in use by the device", 135 "IntNumeratorVal": 128, 136 "Unit": "MiB" 137 } 138 }, 139 "Nested": {} 140 }, 141 "Summary": { 142 "Desc": "Memory in use by the device", 143 "IntNumeratorVal": 128, 144 "Unit": "MiB" 145 }, 146 "Timestamp": "2020-12-18T17:15:08.949806Z" 147 } 148 }, 149 "Name": "modelA", 150 "Type": "skeleton", 151 "Vendor": "hashicorp" 152 }, 153 { 154 "InstanceStats": { 155 "73af5d3e-00f9-0786-9bc1-8f5ffa953f15": { 156 "Stats": { 157 "Attributes": { 158 "Used Memory": { 159 "Desc": "Memory in use by the device", 160 "IntNumeratorVal": 128, 161 "Unit": "MiB" 162 } 163 }, 164 "Nested": {} 165 }, 166 "Summary": { 167 "Desc": "Memory in use by the device", 168 "IntNumeratorVal": 128, 169 "Unit": "MiB" 170 }, 171 "Timestamp": "2020-12-18T17:15:08.949806Z" 172 } 173 }, 174 "Name": "modelB", 175 "Type": "skeleton", 176 "Vendor": "hashicorp" 177 } 178 ], 179 "DiskStats": [ 180 { 181 "Available": 142943150080, 182 "Device": "/dev/disk1", 183 "InodesUsedPercent": 0.05312946180421879, 184 "Mountpoint": "/", 185 "Size": 249783500800, 186 "Used": 106578206720, 187 "UsedPercent": 42.668233241448746 188 } 189 ], 190 "Memory": { 191 "Available": 6232244224, 192 "Free": 470618112, 193 "Total": 17179869184, 194 "Used": 10947624960 195 }, 196 "Timestamp": 1495743032992498200, 197 "Uptime": 193520 198 } 199 ``` 200 201 ## Read Allocation Statistics 202 203 The client `allocation` endpoint is used to query the actual resources consumed 204 by an allocation. 205 206 | Method | Path | Produces | 207 | ------ | ------------------------------------ | ------------------ | 208 | `GET` | `/client/allocation/:alloc_id/stats` | `application/json` | 209 210 The table below shows this endpoint's support for 211 [blocking queries](/api-docs#blocking-queries) and 212 [required ACLs](/api-docs#acls). 213 214 | Blocking Queries | ACL Required | 215 | ---------------- | -------------------- | 216 | `NO` | `namespace:read-job` | 217 218 ### Parameters 219 220 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 221 This is specified as part of the URL. Note, this must be the _full_ allocation 222 ID, not the short 8-character one. This is specified as part of the path. 223 224 ### Sample Request 225 226 ```shell-session 227 $ curl \ 228 https://localhost:4646/v1/client/allocation/5fc98185-17ff-26bc-a802-0c74fa471c99/stats 229 ``` 230 231 ### Sample Response 232 233 ```json 234 { 235 "ResourceUsage": { 236 "CpuStats": { 237 "Measured": ["Throttled Periods", "Throttled Time", "Percent"], 238 "Percent": 0.14159538847117795, 239 "SystemMode": 0, 240 "ThrottledPeriods": 0, 241 "ThrottledTime": 0, 242 "TotalTicks": 3.256693934837093, 243 "UserMode": 0 244 }, 245 "MemoryStats": { 246 "Cache": 1744896, 247 "KernelMaxUsage": 0, 248 "KernelUsage": 0, 249 "MaxUsage": 4710400, 250 "Measured": ["RSS", "Cache", "Swap", "Max Usage"], 251 "RSS": 1486848, 252 "Swap": 0 253 } 254 }, 255 "Tasks": { 256 "redis": { 257 "Pids": null, 258 "ResourceUsage": { 259 "CpuStats": { 260 "Measured": ["Throttled Periods", "Throttled Time", "Percent"], 261 "Percent": 0.14159538847117795, 262 "SystemMode": 0, 263 "ThrottledPeriods": 0, 264 "ThrottledTime": 0, 265 "TotalTicks": 3.256693934837093, 266 "UserMode": 0 267 }, 268 "MemoryStats": { 269 "Cache": 1744896, 270 "KernelMaxUsage": 0, 271 "KernelUsage": 0, 272 "MaxUsage": 4710400, 273 "Measured": ["RSS", "Cache", "Swap", "Max Usage"], 274 "RSS": 1486848, 275 "Swap": 0 276 } 277 }, 278 "Timestamp": 1495743243970720000 279 } 280 }, 281 "Timestamp": 1495743243970720000 282 } 283 ``` 284 285 ## Read File 286 287 This endpoint reads the contents of a file in an allocation directory. 288 289 | Method | Path | Produces | 290 | ------ | -------------------------- | ------------ | 291 | `GET` | `/client/fs/cat/:alloc_id` | `text/plain` | 292 293 The table below shows this endpoint's support for 294 [blocking queries](/api-docs#blocking-queries) and 295 [required ACLs](/api-docs#acls). 296 297 | Blocking Queries | ACL Required | 298 | ---------------- | ------------------- | 299 | `NO` | `namespace:read-fs` | 300 301 ### Parameters 302 303 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 304 This is specified as part of the URL. Note, this must be the _full_ allocation 305 ID, not the short 8-character one. This is specified as part of the path. 306 307 - `path` `(string: "/")` - Specifies the path of the file to read, relative to 308 the root of the allocation directory. 309 310 ### Sample Request 311 312 ```shell-session 313 $ curl \ 314 https://localhost:4646/v1/client/fs/cat/5fc98185-17ff-26bc-a802-0c74fa471c99 315 ``` 316 317 ```shell-session 318 $ curl \ 319 https://localhost:4646/v1/client/fs/cat/5fc98185-17ff-26bc-a802-0c74fa471c99?path=alloc/file.json 320 ``` 321 322 ### Sample Response 323 324 ```text 325 (whatever was in the file...) 326 ``` 327 328 ## Read File at Offset 329 330 This endpoint reads the contents of a file in an allocation directory at a 331 particular offset and limit. 332 333 | Method | Path | Produces | 334 | ------ | ----------------------------- | ------------ | 335 | `GET` | `/client/fs/readat/:alloc_id` | `text/plain` | 336 337 The table below shows this endpoint's support for 338 [blocking queries](/api-docs#blocking-queries) and 339 [required ACLs](/api-docs#acls). 340 341 | Blocking Queries | ACL Required | 342 | ---------------- | ------------------- | 343 | `NO` | `namespace:read-fs` | 344 345 ### Parameters 346 347 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 348 This is specified as part of the URL. Note, this must be the _full_ allocation 349 ID, not the short 8-character one. This is specified as part of the path. 350 351 - `path` `(string: "/")` - Specifies the path of the file to read, relative to 352 the root of the allocation directory. 353 354 - `offset` `(int: <required>)` - Specifies the byte offset from where content 355 will be read. 356 357 - `limit` `(int: <required>)` - Specifies the number of bytes to read from the 358 offset. 359 360 ### Sample Request 361 362 ```shell-session 363 $ curl \ 364 https://localhost:4646/v1/client/fs/readat/5fc98185-17ff-26bc-a802-0c74fa471c99?path=/alloc/foo&offset=1323&limit=19303 365 ``` 366 367 ### Sample Response 368 369 ```text 370 (whatever was in the file, starting from offset, up to limit bytes...) 371 ``` 372 373 ## Stream File 374 375 This endpoint streams the contents of a file in an allocation directory. 376 377 | Method | Path | Produces | 378 | ------ | ----------------------------- | ------------ | 379 | `GET` | `/client/fs/stream/:alloc_id` | `text/plain` | 380 381 The table below shows this endpoint's support for 382 [blocking queries](/api-docs#blocking-queries) and 383 [required ACLs](/api-docs#acls). 384 385 | Blocking Queries | ACL Required | 386 | ---------------- | ------------------- | 387 | `NO` | `namespace:read-fs` | 388 389 ### Parameters 390 391 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 392 This is specified as part of the URL. Note, this must be the _full_ allocation 393 ID, not the short 8-character one. This is specified as part of the path. 394 395 - `path` `(string: "/")` - Specifies the path of the file to read, relative to 396 the root of the allocation directory. 397 398 - `follow` `(bool: true)`- Specifies whether to tail the file. 399 400 - `offset` `(int: <required>)` - Specifies the byte offset from where content 401 will be read. 402 403 - `origin` `(string: "start|end")` - Applies the relative offset to either the 404 start or end of the file. 405 406 ### Sample Request 407 408 ```shell-session 409 $ curl \ 410 https://localhost:4646/v1/client/fs/stream/5fc98185-17ff-26bc-a802-0c74fa471c99?path=/alloc/logs/redis.log 411 ``` 412 413 ### Sample Response 414 415 ```json 416 ({ 417 "File": "alloc/logs/redis.log", 418 "Offset": 3604480, 419 "Data": "NTMxOTMyCjUzMTkzMwo1MzE5MzQKNTMx..." 420 }, 421 { 422 "File": "alloc/logs/redis.log", 423 "FileEvent": "file deleted" 424 }) 425 ``` 426 427 #### Field Reference 428 429 The return value is a stream of frames. These frames contain the following 430 fields: 431 432 - `Data` - A base64 encoding of the bytes being streamed. 433 434 - `FileEvent` - An event that could cause a change in the streams position. The 435 possible values are "file deleted" and "file truncated". 436 437 - `Offset` - Offset is the offset into the stream. 438 439 - `File` - The name of the file being streamed. 440 441 ## Stream Logs 442 443 This endpoint streams a task's stderr/stdout logs. 444 445 | Method | Path | Produces | 446 | ------ | --------------------------- | ------------ | 447 | `GET` | `/client/fs/logs/:alloc_id` | `text/plain` | 448 449 The table below shows this endpoint's support for 450 [blocking queries](/api-docs#blocking-queries) and 451 [required ACLs](/api-docs#acls). 452 453 | Blocking Queries | ACL Required | 454 | ---------------- | -------------------------------------------- | 455 | `NO` | `namespace:read-logs` or `namespace:read-fs` | 456 457 ### Parameters 458 459 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 460 This is specified as part of the URL. Note, this must be the _full_ allocation 461 ID, not the short 8-character one. This is specified as part of the path. 462 463 - `task` `(string: <required>)` - Specifies the name of the task inside the 464 allocation to stream logs from. 465 466 - `follow` `(bool: false)`- Specifies whether to tail the logs. 467 468 - `type` `(string: "stderr|stdout")` - Specifies the stream to stream. 469 470 - `offset` `(int: 0)` - Specifies the offset to start streaming from. 471 472 - `origin` `(string: "start|end")` - Specifies either "start" or "end" and 473 applies the offset relative to either the start or end of the logs 474 respectively. Defaults to "start". 475 476 - `plain` `(bool: false)` - Return just the plain text without framing. This can 477 be useful when viewing logs in a browser. 478 479 ### Sample Request 480 481 ```shell-session 482 $ curl \ 483 https://localhost:4646/v1/client/fs/logs/5fc98185-17ff-26bc-a802-0c74fa471c99 484 ``` 485 486 ### Sample Response 487 488 ```json 489 ({ 490 "File": "alloc/logs/redis.stdout.0", 491 "Offset": 3604480, 492 "Data": "NTMxOTMyCjUzMTkzMwo1MzE5MzQKNTMx..." 493 }, 494 { 495 "File": "alloc/logs/redis.stdout.0", 496 "FileEvent": "file deleted" 497 }) 498 ``` 499 500 #### Field Reference 501 502 The return value is a stream of frames. These frames contain the following 503 fields: 504 505 - `Data` - A base64 encoding of the bytes being streamed. 506 507 - `FileEvent` - An event that could cause a change in the streams position. The 508 possible values are "file deleted" and "file truncated". 509 510 - `Offset` - Offset is the offset into the stream. 511 512 - `File` - The name of the file being streamed. 513 514 ## List Files 515 516 This endpoint lists files in an allocation directory. 517 518 | Method | Path | Produces | 519 | ------ | ------------------------- | ------------ | 520 | `GET` | `/client/fs/ls/:alloc_id` | `text/plain` | 521 522 The table below shows this endpoint's support for 523 [blocking queries](/api-docs#blocking-queries) and 524 [required ACLs](/api-docs#acls). 525 526 | Blocking Queries | ACL Required | 527 | ---------------- | ------------------- | 528 | `NO` | `namespace:read-fs` | 529 530 ### Parameters 531 532 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 533 This is specified as part of the URL. Note, this must be the _full_ allocation 534 ID, not the short 8-character one. This is specified as part of the path. 535 536 - `path` `(string: "/")` - Specifies the path of the file to read, relative to 537 the root of the allocation directory. 538 539 ### Sample Request 540 541 ```shell-session 542 $ curl \ 543 https://localhost:4646/v1/client/fs/ls/5fc98185-17ff-26bc-a802-0c74fa471c99 544 ``` 545 546 ### Sample Response 547 548 ```json 549 [ 550 { 551 "Name": "alloc", 552 "IsDir": true, 553 "Size": 4096, 554 "FileMode": "drwxrwxr-x", 555 "ModTime": "2016-03-15T15:40:00.414236712-07:00" 556 }, 557 { 558 "Name": "redis", 559 "IsDir": true, 560 "Size": 4096, 561 "FileMode": "drwxrwxr-x", 562 "ModTime": "2016-03-15T15:40:56.810238153-07:00" 563 } 564 ] 565 ``` 566 567 ## Stat File 568 569 This endpoint stats a file in an allocation. 570 571 | Method | Path | Produces | 572 | ------ | --------------------------- | ------------ | 573 | `GET` | `/client/fs/stat/:alloc_id` | `text/plain` | 574 575 The table below shows this endpoint's support for 576 [blocking queries](/api-docs#blocking-queries) and 577 [required ACLs](/api-docs#acls). 578 579 | Blocking Queries | ACL Required | 580 | ---------------- | ------------------- | 581 | `NO` | `namespace:read-fs` | 582 583 ### Parameters 584 585 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 586 This is specified as part of the URL. Note, this must be the _full_ allocation 587 ID, not the short 8-character one. This is specified as part of the path. 588 589 - `path` `(string: "/")` - Specifies the path of the file to read, relative to 590 the root of the allocation directory. 591 592 ### Sample Request 593 594 ```shell-session 595 $ curl \ 596 https://localhost:4646/v1/client/fs/stat/5fc98185-17ff-26bc-a802-0c74fa471c99 597 ``` 598 599 ### Sample Response 600 601 ```json 602 { 603 "Name": "redis-syslog-collector.out", 604 "IsDir": false, 605 "Size": 96, 606 "FileMode": "-rw-rw-r--", 607 "ModTime": "2016-03-15T15:40:56.822238153-07:00" 608 } 609 ``` 610 611 ## GC Allocation 612 613 This endpoint forces a garbage collection of a particular, stopped allocation 614 on a node. Note that the allocation will still exist on the server and appear 615 in server responses. 616 617 | Method | Path | Produces | 618 | ------ | --------------------------------- | ------------------ | 619 | `GET` | `/client/allocation/:alloc_id/gc` | `application/json` | 620 621 The table below shows this endpoint's support for 622 [blocking queries](/api-docs#blocking-queries) and 623 [required ACLs](/api-docs#acls). 624 625 | Blocking Queries | ACL Required | 626 | ---------------- | ---------------------- | 627 | `NO` | `namespace:submit-job` | 628 629 ### Parameters 630 631 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 632 This is specified as part of the URL. Note, this must be the _full_ allocation 633 ID, not the short 8-character one. This is specified as part of the path. 634 635 ### Sample Request 636 637 ```shell-session 638 $ curl \ 639 https://nomad.rocks/v1/client/allocation/5fc98185-17ff-26bc-a802-0c74fa471c99/gc 640 ``` 641 642 ## GC All Allocation 643 644 This endpoint forces a garbage collection of all stopped allocations on a node. 645 646 | Method | Path | Produces | 647 | ------ | ------------ | ------------ | 648 | `GET` | `/client/gc` | `text/plain` | 649 650 The table below shows this endpoint's support for 651 [blocking queries](/api-docs#blocking-queries) and 652 [required ACLs](/api-docs#acls). 653 654 | Blocking Queries | ACL Required | 655 | ---------------- | ------------ | 656 | `NO` | `node:write` | 657 658 ### Parameters 659 660 - `node_id` `(string: <optional>)` - Specifies the node to target. This is 661 required when the endpoint is being accessed via a server. This is specified as 662 part of the URL. Note, this must be the _full_ node ID, not the short 663 8-character one. This is specified as part of the path. 664 665 ### Sample Request 666 667 ```shell-session 668 $ curl \ 669 https://localhost:4646/v1/client/gc 670 ```