mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Add support for metrics plugins
Allows for a plugin type that can be used to scrape metrics. This is useful because metrics are not neccessarily at a standard location... `--metrics-addr` must be set, and must currently be a TCP socket. Even if metrics are done via a unix socket, there's no guarentee where the socket may be located on the system, making bind-mounting such a socket into a container difficult (and racey, failure-prone on daemon restart). Metrics plugins side-step this issue by always listening on a unix socket and then bind-mounting that into a known path in the plugin container. Note there has been similar work in the past (and ultimately punted at the time) for consistent access to the Docker API from within a container. Why not add metrics to the Docker API and just provide a plugin with access to the Docker API? Certainly this can be useful, but gives a lot of control/access to a plugin that may only need the metrics. We can look at supporting API plugins separately for this reason. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
@@ -3,12 +3,14 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
@@ -455,3 +457,24 @@ func (s *DockerSuite) TestPluginUpgrade(c *check.C) {
|
||||
dockerCmd(c, "volume", "inspect", "bananas")
|
||||
dockerCmd(c, "run", "--rm", "-v", "bananas:/apple", "busybox", "sh", "-c", "ls -lh /apple/core")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPluginMetricsCollector(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, Network, SameHostDaemon, IsAmd64)
|
||||
d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{})
|
||||
d.Start(c)
|
||||
defer d.Stop(c)
|
||||
|
||||
name := "cpuguy83/docker-metrics-plugin-test:latest"
|
||||
r := cli.Docker(cli.Args("plugin", "install", "--grant-all-permissions", name), cli.Daemon(d))
|
||||
c.Assert(r.Error, checker.IsNil, check.Commentf(r.Combined()))
|
||||
|
||||
// plugin lisens on localhost:19393 and proxies the metrics
|
||||
resp, err := http.Get("http://localhost:19393/metrics")
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer resp.Body.Close()
|
||||
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
c.Assert(err, checker.IsNil)
|
||||
// check that a known metric is there... don't epect this metric to change over time.. probably safe
|
||||
c.Assert(string(b), checker.Contains, "container_actions")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user