github.com/jiasir/docker@v1.3.3-0.20170609024000-252e610103e7/docs/extend/plugins_metrics.md (about)

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