github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/website/pages/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 "DiskStats": [ 129 { 130 "Available": 142943150080, 131 "Device": "/dev/disk1", 132 "InodesUsedPercent": 0.05312946180421879, 133 "Mountpoint": "/", 134 "Size": 249783500800, 135 "Used": 106578206720, 136 "UsedPercent": 42.668233241448746 137 } 138 ], 139 "Memory": { 140 "Available": 6232244224, 141 "Free": 470618112, 142 "Total": 17179869184, 143 "Used": 10947624960 144 }, 145 "Timestamp": 1495743032992498200, 146 "Uptime": 193520 147 } 148 ``` 149 150 ## Read Allocation Statistics 151 152 The client `allocation` endpoint is used to query the actual resources consumed 153 by an allocation. 154 155 | Method | Path | Produces | 156 | ------ | ------------------------------------ | ------------------ | 157 | `GET` | `/client/allocation/:alloc_id/stats` | `application/json` | 158 159 The table below shows this endpoint's support for 160 [blocking queries](/api-docs#blocking-queries) and 161 [required ACLs](/api-docs#acls). 162 163 | Blocking Queries | ACL Required | 164 | ---------------- | -------------------- | 165 | `NO` | `namespace:read-job` | 166 167 ### Parameters 168 169 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 170 This is specified as part of the URL. Note, this must be the _full_ allocation 171 ID, not the short 8-character one. This is specified as part of the path. 172 173 ### Sample Request 174 175 ```shell-session 176 $ curl \ 177 https://localhost:4646/v1/client/allocation/5fc98185-17ff-26bc-a802-0c74fa471c99/stats 178 ``` 179 180 ### Sample Response 181 182 ```json 183 { 184 "ResourceUsage": { 185 "CpuStats": { 186 "Measured": ["Throttled Periods", "Throttled Time", "Percent"], 187 "Percent": 0.14159538847117795, 188 "SystemMode": 0, 189 "ThrottledPeriods": 0, 190 "ThrottledTime": 0, 191 "TotalTicks": 3.256693934837093, 192 "UserMode": 0 193 }, 194 "MemoryStats": { 195 "Cache": 1744896, 196 "KernelMaxUsage": 0, 197 "KernelUsage": 0, 198 "MaxUsage": 4710400, 199 "Measured": ["RSS", "Cache", "Swap", "Max Usage"], 200 "RSS": 1486848, 201 "Swap": 0 202 } 203 }, 204 "Tasks": { 205 "redis": { 206 "Pids": null, 207 "ResourceUsage": { 208 "CpuStats": { 209 "Measured": ["Throttled Periods", "Throttled Time", "Percent"], 210 "Percent": 0.14159538847117795, 211 "SystemMode": 0, 212 "ThrottledPeriods": 0, 213 "ThrottledTime": 0, 214 "TotalTicks": 3.256693934837093, 215 "UserMode": 0 216 }, 217 "MemoryStats": { 218 "Cache": 1744896, 219 "KernelMaxUsage": 0, 220 "KernelUsage": 0, 221 "MaxUsage": 4710400, 222 "Measured": ["RSS", "Cache", "Swap", "Max Usage"], 223 "RSS": 1486848, 224 "Swap": 0 225 } 226 }, 227 "Timestamp": 1495743243970720000 228 } 229 }, 230 "Timestamp": 1495743243970720000 231 } 232 ``` 233 234 ## Read File 235 236 This endpoint reads the contents of a file in an allocation directory. 237 238 | Method | Path | Produces | 239 | ------ | -------------------------- | ------------ | 240 | `GET` | `/client/fs/cat/:alloc_id` | `text/plain` | 241 242 The table below shows this endpoint's support for 243 [blocking queries](/api-docs#blocking-queries) and 244 [required ACLs](/api-docs#acls). 245 246 | Blocking Queries | ACL Required | 247 | ---------------- | ------------------- | 248 | `NO` | `namespace:read-fs` | 249 250 ### Parameters 251 252 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 253 This is specified as part of the URL. Note, this must be the _full_ allocation 254 ID, not the short 8-character one. This is specified as part of the path. 255 256 - `path` `(string: "/")` - Specifies the path of the file to read, relative to 257 the root of the allocation directory. 258 259 ### Sample Request 260 261 ```shell-session 262 $ curl \ 263 https://localhost:4646/v1/client/fs/cat/5fc98185-17ff-26bc-a802-0c74fa471c99 264 ``` 265 266 ```shell-session 267 $ curl \ 268 https://localhost:4646/v1/client/fs/cat/5fc98185-17ff-26bc-a802-0c74fa471c99?path=alloc/file.json 269 ``` 270 271 ### Sample Response 272 273 ```text 274 (whatever was in the file...) 275 ``` 276 277 ## Read File at Offset 278 279 This endpoint reads the contents of a file in an allocation directory at a 280 particular offset and limit. 281 282 | Method | Path | Produces | 283 | ------ | ----------------------------- | ------------ | 284 | `GET` | `/client/fs/readat/:alloc_id` | `text/plain` | 285 286 The table below shows this endpoint's support for 287 [blocking queries](/api-docs#blocking-queries) and 288 [required ACLs](/api-docs#acls). 289 290 | Blocking Queries | ACL Required | 291 | ---------------- | ------------------- | 292 | `NO` | `namespace:read-fs` | 293 294 ### Parameters 295 296 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 297 This is specified as part of the URL. Note, this must be the _full_ allocation 298 ID, not the short 8-character one. This is specified as part of the path. 299 300 - `path` `(string: "/")` - Specifies the path of the file to read, relative to 301 the root of the allocation directory. 302 303 - `offset` `(int: <required>)` - Specifies the byte offset from where content 304 will be read. 305 306 - `limit` `(int: <required>)` - Specifies the number of bytes to read from the 307 offset. 308 309 ### Sample Request 310 311 ```shell-session 312 $ curl \ 313 https://localhost:4646/v1/client/fs/readat/5fc98185-17ff-26bc-a802-0c74fa471c99?path=/alloc/foo&offset=1323&limit=19303 314 ``` 315 316 ### Sample Response 317 318 ```text 319 (whatever was in the file, starting from offset, up to limit bytes...) 320 ``` 321 322 ## Stream File 323 324 This endpoint streams the contents of a file in an allocation directory. 325 326 | Method | Path | Produces | 327 | ------ | ----------------------------- | ------------ | 328 | `GET` | `/client/fs/stream/:alloc_id` | `text/plain` | 329 330 The table below shows this endpoint's support for 331 [blocking queries](/api-docs#blocking-queries) and 332 [required ACLs](/api-docs#acls). 333 334 | Blocking Queries | ACL Required | 335 | ---------------- | ------------------- | 336 | `NO` | `namespace:read-fs` | 337 338 ### Parameters 339 340 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 341 This is specified as part of the URL. Note, this must be the _full_ allocation 342 ID, not the short 8-character one. This is specified as part of the path. 343 344 - `path` `(string: "/")` - Specifies the path of the file to read, relative to 345 the root of the allocation directory. 346 347 - `follow` `(bool: true)`- Specifies whether to tail the file. 348 349 - `offset` `(int: <required>)` - Specifies the byte offset from where content 350 will be read. 351 352 - `origin` `(string: "start|end")` - Applies the relative offset to either the 353 start or end of the file. 354 355 ### Sample Request 356 357 ```shell-session 358 $ curl \ 359 https://localhost:4646/v1/client/fs/stream/5fc98185-17ff-26bc-a802-0c74fa471c99?path=/alloc/logs/redis.log 360 ``` 361 362 ### Sample Response 363 364 ```json 365 ({ 366 "File": "alloc/logs/redis.log", 367 "Offset": 3604480, 368 "Data": "NTMxOTMyCjUzMTkzMwo1MzE5MzQKNTMx..." 369 }, 370 { 371 "File": "alloc/logs/redis.log", 372 "FileEvent": "file deleted" 373 }) 374 ``` 375 376 #### Field Reference 377 378 The return value is a stream of frames. These frames contain the following 379 fields: 380 381 - `Data` - A base64 encoding of the bytes being streamed. 382 383 - `FileEvent` - An event that could cause a change in the streams position. The 384 possible values are "file deleted" and "file truncated". 385 386 - `Offset` - Offset is the offset into the stream. 387 388 - `File` - The name of the file being streamed. 389 390 ## Stream Logs 391 392 This endpoint streams a task's stderr/stdout logs. 393 394 | Method | Path | Produces | 395 | ------ | --------------------------- | ------------ | 396 | `GET` | `/client/fs/logs/:alloc_id` | `text/plain` | 397 398 The table below shows this endpoint's support for 399 [blocking queries](/api-docs#blocking-queries) and 400 [required ACLs](/api-docs#acls). 401 402 | Blocking Queries | ACL Required | 403 | ---------------- | -------------------------------------------- | 404 | `NO` | `namespace:read-logs` or `namespace:read-fs` | 405 406 ### Parameters 407 408 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 409 This is specified as part of the URL. Note, this must be the _full_ allocation 410 ID, not the short 8-character one. This is specified as part of the path. 411 412 - `task` `(string: <required>)` - Specifies the name of the task inside the 413 allocation to stream logs from. 414 415 - `follow` `(bool: false)`- Specifies whether to tail the logs. 416 417 - `type` `(string: "stderr|stdout")` - Specifies the stream to stream. 418 419 - `offset` `(int: 0)` - Specifies the offset to start streaming from. 420 421 - `origin` `(string: "start|end")` - Specifies either "start" or "end" and 422 applies the offset relative to either the start or end of the logs 423 respectively. Defaults to "start". 424 425 - `plain` `(bool: false)` - Return just the plain text without framing. This can 426 be useful when viewing logs in a browser. 427 428 ### Sample Request 429 430 ```shell-session 431 $ curl \ 432 https://localhost:4646/v1/client/fs/logs/5fc98185-17ff-26bc-a802-0c74fa471c99 433 ``` 434 435 ### Sample Response 436 437 ```json 438 ({ 439 "File": "alloc/logs/redis.stdout.0", 440 "Offset": 3604480, 441 "Data": "NTMxOTMyCjUzMTkzMwo1MzE5MzQKNTMx..." 442 }, 443 { 444 "File": "alloc/logs/redis.stdout.0", 445 "FileEvent": "file deleted" 446 }) 447 ``` 448 449 #### Field Reference 450 451 The return value is a stream of frames. These frames contain the following 452 fields: 453 454 - `Data` - A base64 encoding of the bytes being streamed. 455 456 - `FileEvent` - An event that could cause a change in the streams position. The 457 possible values are "file deleted" and "file truncated". 458 459 - `Offset` - Offset is the offset into the stream. 460 461 - `File` - The name of the file being streamed. 462 463 ## List Files 464 465 This endpoint lists files in an allocation directory. 466 467 | Method | Path | Produces | 468 | ------ | ------------------------- | ------------ | 469 | `GET` | `/client/fs/ls/:alloc_id` | `text/plain` | 470 471 The table below shows this endpoint's support for 472 [blocking queries](/api-docs#blocking-queries) and 473 [required ACLs](/api-docs#acls). 474 475 | Blocking Queries | ACL Required | 476 | ---------------- | ------------------- | 477 | `NO` | `namespace:read-fs` | 478 479 ### Parameters 480 481 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 482 This is specified as part of the URL. Note, this must be the _full_ allocation 483 ID, not the short 8-character one. This is specified as part of the path. 484 485 - `path` `(string: "/")` - Specifies the path of the file to read, relative to 486 the root of the allocation directory. 487 488 ### Sample Request 489 490 ```shell-session 491 $ curl \ 492 https://localhost:4646/v1/client/fs/ls/5fc98185-17ff-26bc-a802-0c74fa471c99 493 ``` 494 495 ### Sample Response 496 497 ```json 498 [ 499 { 500 "Name": "alloc", 501 "IsDir": true, 502 "Size": 4096, 503 "FileMode": "drwxrwxr-x", 504 "ModTime": "2016-03-15T15:40:00.414236712-07:00" 505 }, 506 { 507 "Name": "redis", 508 "IsDir": true, 509 "Size": 4096, 510 "FileMode": "drwxrwxr-x", 511 "ModTime": "2016-03-15T15:40:56.810238153-07:00" 512 } 513 ] 514 ``` 515 516 ## Stat File 517 518 This endpoint stats a file in an allocation. 519 520 | Method | Path | Produces | 521 | ------ | --------------------------- | ------------ | 522 | `GET` | `/client/fs/stat/:alloc_id` | `text/plain` | 523 524 The table below shows this endpoint's support for 525 [blocking queries](/api-docs#blocking-queries) and 526 [required ACLs](/api-docs#acls). 527 528 | Blocking Queries | ACL Required | 529 | ---------------- | ------------------- | 530 | `NO` | `namespace:read-fs` | 531 532 ### Parameters 533 534 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 535 This is specified as part of the URL. Note, this must be the _full_ allocation 536 ID, not the short 8-character one. This is specified as part of the path. 537 538 - `path` `(string: "/")` - Specifies the path of the file to read, relative to 539 the root of the allocation directory. 540 541 ### Sample Request 542 543 ```shell-session 544 $ curl \ 545 https://localhost:4646/v1/client/fs/stat/5fc98185-17ff-26bc-a802-0c74fa471c99 546 ``` 547 548 ### Sample Response 549 550 ```json 551 { 552 "Name": "redis-syslog-collector.out", 553 "IsDir": false, 554 "Size": 96, 555 "FileMode": "-rw-rw-r--", 556 "ModTime": "2016-03-15T15:40:56.822238153-07:00" 557 } 558 ``` 559 560 ## GC Allocation 561 562 This endpoint forces a garbage collection of a particular, stopped allocation 563 on a node. 564 565 | Method | Path | Produces | 566 | ------ | --------------------------------- | ------------------ | 567 | `GET` | `/client/allocation/:alloc_id/gc` | `application/json` | 568 569 The table below shows this endpoint's support for 570 [blocking queries](/api-docs#blocking-queries) and 571 [required ACLs](/api-docs#acls). 572 573 | Blocking Queries | ACL Required | 574 | ---------------- | ---------------------- | 575 | `NO` | `namespace:submit-job` | 576 577 ### Parameters 578 579 - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query. 580 This is specified as part of the URL. Note, this must be the _full_ allocation 581 ID, not the short 8-character one. This is specified as part of the path. 582 583 ### Sample Request 584 585 ```shell-session 586 $ curl \ 587 https://nomad.rocks/v1/client/allocation/5fc98185-17ff-26bc-a802-0c74fa471c99/gc 588 ``` 589 590 ## GC All Allocation 591 592 This endpoint forces a garbage collection of all stopped allocations on a node. 593 594 | Method | Path | Produces | 595 | ------ | ------------ | ------------ | 596 | `GET` | `/client/gc` | `text/plain` | 597 598 The table below shows this endpoint's support for 599 [blocking queries](/api-docs#blocking-queries) and 600 [required ACLs](/api-docs#acls). 601 602 | Blocking Queries | ACL Required | 603 | ---------------- | ------------ | 604 | `NO` | `node:write` | 605 606 ### Parameters 607 608 - `node_id` `(string: <optional>)` - Specifies the node to target. This is 609 required when the endpoint is being accessed via a server. This is specified as 610 part of the URL. Note, this must be the _full_ node ID, not the short 611 8-character one. This is specified as part of the path. 612 613 ### Sample Request 614 615 ```shell-session 616 $ curl \ 617 https://localhost:4646/v1/client/gc 618 ```