github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/cli/docs/extend/plugins_metrics.md (about)

     1  ---
     2  description: "Metrics plugins."
     3  keywords: "Examples, Usage, plugins, docker, documentation, user guide, metrics"
     4  ---
     5  
     6  <!-- This file is maintained within the docker/cli GitHub
     7       repository at https://github.com/docker/cli/. Make all
     8       pull requests against that repo. If you see this file in
     9       another repository, consider it read-only there, as it will
    10       periodically be overwritten by the definitive file. Pull
    11       requests which include edits to this file in other repositories
    12       will be rejected.
    13  -->
    14  
    15  # Docker metrics collector plugins
    16  
    17  Docker exposes internal metrics based on the prometheus format. Metrics plugins
    18  enable accessing these metrics in a consistent way by providing a Unix
    19  socket at a predefined path where the plugin can scrape the metrics.
    20  
    21  > **Note**
    22  >
    23  > While the plugin interface for metrics is non-experimental, the naming of the
    24  > metrics and metric labels is still considered experimental and may change in a
    25  > future version.
    26  
    27  ## Creating a metrics plugin
    28  
    29  You must currently set `PropagatedMount` in the plugin `config.json` to
    30  `/run/docker`. This allows the plugin to receive updated mounts
    31  (the bind-mounted socket) from Docker after the plugin is already configured.
    32  
    33  ## MetricsCollector protocol
    34  
    35  Metrics plugins must register as implementing the`MetricsCollector` interface
    36  in `config.json`.
    37  
    38  On Unix platforms, the socket is located at `/run/docker/metrics.sock` in the
    39  plugin's rootfs.
    40  
    41  `MetricsCollector` must implement two endpoints:
    42  
    43  ### `MetricsCollector.StartMetrics`
    44  
    45  Signals to the plugin that the metrics socket is now available for scraping
    46  
    47  **Request**
    48  ```json
    49  {}
    50  ```
    51  
    52  The request has no playload.
    53  
    54  **Response**
    55  ```json
    56  {
    57  	"Err": ""
    58  }
    59  ```
    60  
    61  If an error occurred during this request, add an error message to the `Err` field
    62  in the response. If no error then you can either send an empty response (`{}`)
    63  or an empty value for the `Err` field. Errors will only be logged.
    64  
    65  ### `MetricsCollector.StopMetrics`
    66  
    67  Signals to the plugin that the metrics socket is no longer available.
    68  This may happen when the daemon is shutting down.
    69  
    70  **Request**
    71  ```json
    72  {}
    73  ```
    74  
    75  The request has no playload.
    76  
    77  **Response**
    78  ```json
    79  {
    80  	"Err": ""
    81  }
    82  ```
    83  
    84  If an error occurred during this request, add an error message to the `Err` field
    85  in the response. If no error then you can either send an empty response (`{}`)
    86  or an empty value for the `Err` field. Errors will only be logged.