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