github.com/hhrutter/nomad@v0.6.0-rc2.0.20170723054333-80c4b03f0705/website/source/api/client.html.md (about)

     1  ---
     2  layout: api
     3  page_title: Client - HTTP API
     4  sidebar_current: api-client
     5  description: |-
     6    The /client endpoints interact with the local Nomad agent to interact with
     7    client members.
     8  ---
     9  
    10  # Client HTTP API
    11  
    12  The `/client` endpoints are used to interact with the Nomad clients. The API
    13  endpoints are hosted by the Nomad client and requests have to be made to the
    14  Client where the particular allocation was placed.
    15  
    16  ## Read Stats
    17  
    18  This endpoint queries the actual resources consumed on a node. The API endpoint
    19  is hosted by the Nomad client and requests have to be made to the nomad client
    20  whose resource usage metrics are of interest.
    21  
    22  | Method | Path                         | Produces                   |
    23  | ------ | ---------------------------- | -------------------------- |
    24  | `GET`  | `/client/stats`              | `application/json`         |
    25  
    26  The table below shows this endpoint's support for
    27  [blocking queries](/api/index.html#blocking-queries) and
    28  [required ACLs](/api/index.html#acls).
    29  
    30  | Blocking Queries | ACL Required |
    31  | ---------------- | ------------ |
    32  | `NO`             | `none`       |
    33  
    34  ### Sample Request
    35  
    36  ```text
    37  $ curl \
    38      https://nomad.rocks/v1/client/stats
    39  ```
    40  
    41  ### Sample Response
    42  
    43  ```json
    44  {
    45    "AllocDirStats": {
    46      "Available": 142943150080,
    47      "Device": "",
    48      "InodesUsedPercent": 0.05312946180421879,
    49      "Mountpoint": "",
    50      "Size": 249783500800,
    51      "Used": 106578206720,
    52      "UsedPercent": 42.668233241448746
    53    },
    54    "CPU": [
    55      {
    56        "CPU": "cpu0",
    57        "Idle": 80,
    58        "System": 11,
    59        "Total": 20,
    60        "User": 9
    61      },
    62      {
    63        "CPU": "cpu1",
    64        "Idle": 99,
    65        "System": 0,
    66        "Total": 1,
    67        "User": 1
    68      },
    69      {
    70        "CPU": "cpu2",
    71        "Idle": 89,
    72        "System": 7.000000000000001,
    73        "Total": 11,
    74        "User": 4
    75      },
    76      {
    77        "CPU": "cpu3",
    78        "Idle": 100,
    79        "System": 0,
    80        "Total": 0,
    81        "User": 0
    82      },
    83      {
    84        "CPU": "cpu4",
    85        "Idle": 92.92929292929293,
    86        "System": 4.040404040404041,
    87        "Total": 7.07070707070707,
    88        "User": 3.0303030303030303
    89      },
    90      {
    91        "CPU": "cpu5",
    92        "Idle": 99,
    93        "System": 1,
    94        "Total": 1,
    95        "User": 0
    96      },
    97      {
    98        "CPU": "cpu6",
    99        "Idle": 92.07920792079209,
   100        "System": 4.9504950495049505,
   101        "Total": 7.920792079207921,
   102        "User": 2.9702970297029703
   103      },
   104      {
   105        "CPU": "cpu7",
   106        "Idle": 99,
   107        "System": 0,
   108        "Total": 1,
   109        "User": 1
   110      }
   111    ],
   112    "CPUTicksConsumed": 1126.8044804480448,
   113    "DiskStats": [
   114      {
   115        "Available": 142943150080,
   116        "Device": "/dev/disk1",
   117        "InodesUsedPercent": 0.05312946180421879,
   118        "Mountpoint": "/",
   119        "Size": 249783500800,
   120        "Used": 106578206720,
   121        "UsedPercent": 42.668233241448746
   122      }
   123    ],
   124    "Memory": {
   125      "Available": 6232244224,
   126      "Free": 470618112,
   127      "Total": 17179869184,
   128      "Used": 10947624960
   129    },
   130    "Timestamp": 1495743032992498200,
   131    "Uptime": 193520
   132  }
   133  ```
   134  
   135  ## Read Allocation
   136  
   137  The client `allocation` endpoint is used to query the actual resources consumed
   138  by an allocation. The API endpoint is hosted by the Nomad client and requests
   139  have to be made to the nomad client whose resource usage metrics are of
   140  interest.
   141  
   142  | Method | Path                                 | Produces                   |
   143  | ------ | ------------------------------------ | -------------------------- |
   144  | `GET`  | `/client/allocation/:alloc_id/stats` | `application/json`         |
   145  
   146  The table below shows this endpoint's support for
   147  [blocking queries](/api/index.html#blocking-queries) and
   148  [required ACLs](/api/index.html#acls).
   149  
   150  | Blocking Queries | ACL Required |
   151  | ---------------- | ------------ |
   152  | `NO`             | `none`       |
   153  
   154  ### Parameters
   155  
   156  - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query.
   157    This is specified as part of the URL. Note, this must be the _full_ allocation
   158    ID, not the short 8-character one. This is specified as part of the path.
   159  
   160  ### Sample Request
   161  
   162  ```text
   163  $ curl \
   164      https://nomad.rocks/v1/client/allocation/5fc98185-17ff-26bc-a802-0c74fa471c99/stats
   165  ```
   166  
   167  ### Sample Response
   168  
   169  ```json
   170  {
   171    "ResourceUsage": {
   172      "CpuStats": {
   173        "Measured": [
   174          "Throttled Periods",
   175          "Throttled Time",
   176          "Percent"
   177        ],
   178        "Percent": 0.14159538847117795,
   179        "SystemMode": 0,
   180        "ThrottledPeriods": 0,
   181        "ThrottledTime": 0,
   182        "TotalTicks": 3.256693934837093,
   183        "UserMode": 0
   184      },
   185      "MemoryStats": {
   186        "Cache": 1744896,
   187        "KernelMaxUsage": 0,
   188        "KernelUsage": 0,
   189        "MaxUsage": 4710400,
   190        "Measured": [
   191          "RSS",
   192          "Cache",
   193          "Swap",
   194          "Max Usage"
   195        ],
   196        "RSS": 1486848,
   197        "Swap": 0
   198      }
   199    },
   200    "Tasks": {
   201      "redis": {
   202        "Pids": null,
   203        "ResourceUsage": {
   204          "CpuStats": {
   205            "Measured": [
   206              "Throttled Periods",
   207              "Throttled Time",
   208              "Percent"
   209            ],
   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": [
   223              "RSS",
   224              "Cache",
   225              "Swap",
   226              "Max Usage"
   227            ],
   228            "RSS": 1486848,
   229            "Swap": 0
   230          }
   231        },
   232        "Timestamp": 1495743243970720000
   233      }
   234    },
   235    "Timestamp": 1495743243970720000
   236  }
   237  ```
   238  
   239  ## Read File
   240  
   241  This endpoint reads the contents of a file in an allocation directory.
   242  
   243  | Method | Path                         | Produces                   |
   244  | ------ | ---------------------------- | -------------------------- |
   245  | `GET`  | `/client/fs/cat/:alloc_id`   | `text/plain`               |
   246  
   247  The table below shows this endpoint's support for
   248  [blocking queries](/api/index.html#blocking-queries) and
   249  [required ACLs](/api/index.html#acls).
   250  
   251  | Blocking Queries | ACL Required |
   252  | ---------------- | ------------ |
   253  | `NO`             | `none`       |
   254  
   255  ### Parameters
   256  
   257  - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query.
   258    This is specified as part of the URL. Note, this must be the _full_ allocation
   259    ID, not the short 8-character one. This is specified as part of the path.
   260  
   261  - `path` `(string: "/")` - Specifies the path of the file to read, relative to
   262    the root of the allocation directory.
   263  
   264  ### Sample Request
   265  
   266  ```text
   267  $ curl \
   268      https://nomad.rocks/v1/client/fs/cat/5fc98185-17ff-26bc-a802-0c74fa471c99
   269  ```
   270  
   271  ```text
   272  $ curl \
   273      https://nomad.rocks/v1/client/fs/cat/5fc98185-17ff-26bc-a802-0c74fa471c99?path=alloc/file.json
   274  ```
   275  
   276  ### Sample Response
   277  
   278  ```text
   279  (whatever was in the file...)
   280  ```
   281  
   282  
   283  ## Read File at Offset
   284  
   285  This endpoint reads the contents of a file in an allocation directory at a
   286  particular offset and limit.
   287  
   288  | Method | Path                          | Produces                   |
   289  | ------ | ----------------------------- | -------------------------- |
   290  | `GET`  | `/client/fs/readat/:alloc_id` | `text/plain`               |
   291  
   292  The table below shows this endpoint's support for
   293  [blocking queries](/api/index.html#blocking-queries) and
   294  [required ACLs](/api/index.html#acls).
   295  
   296  | Blocking Queries | ACL Required |
   297  | ---------------- | ------------ |
   298  | `NO`             | `none`       |
   299  
   300  ### Parameters
   301  
   302  - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query.
   303    This is specified as part of the URL. Note, this must be the _full_ allocation
   304    ID, not the short 8-character one. This is specified as part of the path.
   305  
   306  - `path` `(string: "/")` - Specifies the path of the file to read, relative to
   307    the root of the allocation directory.
   308  
   309  - `offset` `(int: <required>)` - Specifies the byte offset from where content
   310    will be read.
   311  
   312  - `limit` `(int: <required>)` - Specifies the number of bytes to read from the
   313    offset.
   314  
   315  ### Sample Request
   316  
   317  ```text
   318  $ curl \
   319      https://nomad.rocks/v1/client/fs/readat/5fc98185-17ff-26bc-a802-0c74fa471c99?path=/alloc/foo&offset=1323&limit=19303
   320  ```
   321  
   322  ### Sample Response
   323  
   324  ```text
   325  (whatever was in the file, starting from offset, up to limit bytes...)
   326  ```
   327  
   328  ## Stream File
   329  
   330  This endpoint streams the contents of a file in an allocation directory.
   331  
   332  | Method | Path                          | Produces                   |
   333  | ------ | ----------------------------- | -------------------------- |
   334  | `GET`  | `/client/fs/stream/:alloc_id` | `text/plain`               |
   335  
   336  The table below shows this endpoint's support for
   337  [blocking queries](/api/index.html#blocking-queries) and
   338  [required ACLs](/api/index.html#acls).
   339  
   340  | Blocking Queries | ACL Required |
   341  | ---------------- | ------------ |
   342  | `NO`             | `none`       |
   343  
   344  ### Parameters
   345  
   346  - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query.
   347    This is specified as part of the URL. Note, this must be the _full_ allocation
   348    ID, not the short 8-character one. This is specified as part of the path.
   349  
   350  - `path` `(string: "/")` - Specifies the path of the file to read, relative to
   351    the root of the allocation directory.
   352  
   353  - `offset` `(int: <required>)` - Specifies the byte offset from where content
   354    will be read.
   355  
   356  - `origin` `(string: "start|end")` - Applies the relative offset to either the
   357    start or end of the file.
   358  
   359  ### Sample Request
   360  
   361  ```text
   362  $ curl \
   363      https://nomad.rocks/v1/client/fs/stream/5fc98185-17ff-26bc-a802-0c74fa471c99?path=/alloc/logs/redis.log
   364  ```
   365  
   366  ### Sample Response
   367  
   368  ```json
   369  {
   370    "File": "alloc/logs/redis.log",
   371    "Offset": 3604480,
   372    "Data": "NTMxOTMyCjUzMTkzMwo1MzE5MzQKNTMx..."
   373  },
   374  {
   375    "File": "alloc/logs/redis.log",
   376    "FileEvent": "file deleted"
   377  }
   378  ```
   379  
   380  #### Field Reference
   381  
   382  The return value is a stream of frames. These frames contain the following
   383  fields:
   384  
   385  - `Data` - A base64 encoding of the bytes being streamed.
   386  
   387  - `FileEvent` - An event that could cause a change in the streams position. The
   388    possible values are "file deleted" and "file truncated".
   389  
   390  - `Offset` - Offset is the offset into the stream.
   391  
   392  - `File` - The name of the file being streamed.
   393  
   394  ## Stream Logs
   395  
   396  This endpoint streams a task's stderr/stdout logs.
   397  
   398  | Method | Path                         | Produces                   |
   399  | ------ | ---------------------------- | -------------------------- |
   400  | `GET`  | `/client/fs/logs/:alloc_id`  | `text/plain`               |
   401  
   402  The table below shows this endpoint's support for
   403  [blocking queries](/api/index.html#blocking-queries) and
   404  [required ACLs](/api/index.html#acls).
   405  
   406  | Blocking Queries | ACL Required |
   407  | ---------------- | ------------ |
   408  | `NO`             | `none`       |
   409  
   410  ### Parameters
   411  
   412  - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query.
   413    This is specified as part of the URL. Note, this must be the _full_ allocation
   414    ID, not the short 8-character one. This is specified as part of the path.
   415  
   416  - `task` `(string: <required>)` - Specifies the name of the task inside the
   417    allocation to stream logs from.
   418  
   419  - `follow` `(bool: false)`- Specifies whether to tail the logs.
   420  
   421  - `type` `(string: "stderr|stdout")` - Specifies the stream to stream.
   422  
   423  - `offset` `(int: 0)` - Specifies the offset to start streaming from.
   424  
   425  - `origin` `(string: "start|end")` - Specifies either "start" or "end" and
   426    applies the offset relative to either the start or end of the logs
   427    respectively. Defaults to "start".
   428  
   429  - `plain` `(bool: false)` - Return just the plain text without framing. This can
   430    be useful when viewing logs in a browser.
   431  
   432  ### Sample Request
   433  
   434  ```text
   435  $ curl \
   436      https://nomad.rocks/v1/client/fs/logs/5fc98185-17ff-26bc-a802-0c74fa471c99
   437  ```
   438  
   439  ### Sample Response
   440  
   441  ```json
   442  {
   443    "File": "alloc/logs/redis.stdout.0",
   444    "Offset": 3604480,
   445    "Data": "NTMxOTMyCjUzMTkzMwo1MzE5MzQKNTMx..."
   446  },
   447  {
   448    "File": "alloc/logs/redis.stdout.0",
   449    "FileEvent": "file deleted"
   450  }
   451  ```
   452  
   453  #### Field Reference
   454  
   455  The return value is a stream of frames. These frames contain the following
   456  fields:
   457  
   458  - `Data` - A base64 encoding of the bytes being streamed.
   459  
   460  - `FileEvent` - An event that could cause a change in the streams position. The
   461    possible values are "file deleted" and "file truncated".
   462  
   463  - `Offset` - Offset is the offset into the stream.
   464  
   465  - `File` - The name of the file being streamed.
   466  
   467  ## List Files
   468  
   469  This endpoint lists files in an allocation directory.
   470  
   471  | Method | Path                         | Produces                   |
   472  | ------ | ---------------------------- | -------------------------- |
   473  | `GET`  | `/client/fs/ls/:alloc_id`    | `text/plain`               |
   474  
   475  The table below shows this endpoint's support for
   476  [blocking queries](/api/index.html#blocking-queries) and
   477  [required ACLs](/api/index.html#acls).
   478  
   479  | Blocking Queries | ACL Required |
   480  | ---------------- | ------------ |
   481  | `NO`             | `none`       |
   482  
   483  ### Parameters
   484  
   485  - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query.
   486    This is specified as part of the URL. Note, this must be the _full_ allocation
   487    ID, not the short 8-character one. This is specified as part of the path.
   488  
   489  - `path` `(string: "/")` - Specifies the path of the file to read, relative to
   490    the root of the allocation directory.
   491  
   492  ### Sample Request
   493  
   494  ```text
   495  $ curl \
   496      https://nomad.rocks/v1/client/fs/ls/5fc98185-17ff-26bc-a802-0c74fa471c99
   497  ```
   498  
   499  ### Sample Response
   500  
   501  ```json
   502  [
   503    {
   504      "Name": "alloc",
   505      "IsDir": true,
   506      "Size": 4096,
   507      "FileMode": "drwxrwxr-x",
   508      "ModTime": "2016-03-15T15:40:00.414236712-07:00"
   509    },
   510    {
   511      "Name": "redis",
   512      "IsDir": true,
   513      "Size": 4096,
   514      "FileMode": "drwxrwxr-x",
   515      "ModTime": "2016-03-15T15:40:56.810238153-07:00"
   516    }
   517  ]
   518  ```
   519  
   520  ## Stat File
   521  
   522  This endpoint stats a file in an allocation.
   523  
   524  | Method | Path                         | Produces                   |
   525  | ------ | ---------------------------- | -------------------------- |
   526  | `GET`  | `/client/fs/stat/:alloc_id`  | `text/plain`               |
   527  
   528  The table below shows this endpoint's support for
   529  [blocking queries](/api/index.html#blocking-queries) and
   530  [required ACLs](/api/index.html#acls).
   531  
   532  | Blocking Queries | ACL Required |
   533  | ---------------- | ------------ |
   534  | `NO`             | `none`       |
   535  
   536  ### Parameters
   537  
   538  - `:alloc_id` `(string: <required>)` - Specifies the allocation ID to query.
   539    This is specified as part of the URL. Note, this must be the _full_ allocation
   540    ID, not the short 8-character one. This is specified as part of the path.
   541  
   542  - `path` `(string: "/")` - Specifies the path of the file to read, relative to
   543    the root of the allocation directory.
   544  
   545  ### Sample Request
   546  
   547  ```text
   548  $ curl \
   549      https://nomad.rocks/v1/client/fs/stat/5fc98185-17ff-26bc-a802-0c74fa471c99
   550  ```
   551  
   552  ### Sample Response
   553  
   554  ```json
   555  {
   556    "Name": "redis-syslog-collector.out",
   557    "IsDir": false,
   558    "Size": 96,
   559    "FileMode": "-rw-rw-r--",
   560    "ModTime": "2016-03-15T15:40:56.822238153-07:00"
   561  }
   562  ```