Browse code

Add basic prometheus support

This adds a metrics packages that creates additional metrics. Add the
metrics endpoint to the docker api server under `/metrics`.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Add metrics to daemon package

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

api: use standard way for metrics route

Also add "type" query parameter

Signed-off-by: Alexander Morozov <lk4d4@docker.com>

Convert timers to ms

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Michael Crosby authored on 2016/07/21 08:11:28
Showing 34 changed files
... ...
@@ -248,6 +248,15 @@ func (cli *DaemonCli) start(opts daemonOptions) (err error) {
248 248
 		return fmt.Errorf("Error starting daemon: %v", err)
249 249
 	}
250 250
 
251
+	if cli.Config.MetricsAddress != "" {
252
+		if !d.HasExperimental() {
253
+			return fmt.Errorf("metrics-addr is only supported when experimental is enabled")
254
+		}
255
+		if err := startMetricsServer(cli.Config.MetricsAddress); err != nil {
256
+			return err
257
+		}
258
+	}
259
+
251 260
 	name, _ := os.Hostname()
252 261
 
253 262
 	c, err := cluster.New(cluster.Config{
254 263
new file mode 100644
... ...
@@ -0,0 +1,27 @@
0
+package main
1
+
2
+import (
3
+	"net"
4
+	"net/http"
5
+
6
+	"github.com/Sirupsen/logrus"
7
+	metrics "github.com/docker/go-metrics"
8
+)
9
+
10
+func startMetricsServer(addr string) error {
11
+	if err := allocateDaemonPort(addr); err != nil {
12
+		return err
13
+	}
14
+	l, err := net.Listen("tcp", addr)
15
+	if err != nil {
16
+		return err
17
+	}
18
+	mux := http.NewServeMux()
19
+	mux.Handle("/metrics", metrics.Handler())
20
+	go func() {
21
+		if err := http.Serve(l, mux); err != nil {
22
+			logrus.Errorf("serve metrics api: %s", err)
23
+		}
24
+	}()
25
+	return nil
26
+}
... ...
@@ -1,9 +1,14 @@
1 1
 package daemon
2 2
 
3
-import "github.com/docker/docker/pkg/archive"
3
+import (
4
+	"time"
5
+
6
+	"github.com/docker/docker/pkg/archive"
7
+)
4 8
 
5 9
 // ContainerChanges returns a list of container fs changes
6 10
 func (daemon *Daemon) ContainerChanges(name string) ([]archive.Change, error) {
11
+	start := time.Now()
7 12
 	container, err := daemon.GetContainer(name)
8 13
 	if err != nil {
9 14
 		return nil, err
... ...
@@ -11,5 +16,10 @@ func (daemon *Daemon) ContainerChanges(name string) ([]archive.Change, error) {
11 11
 
12 12
 	container.Lock()
13 13
 	defer container.Unlock()
14
-	return container.RWLayer.Changes()
14
+	c, err := container.RWLayer.Changes()
15
+	if err != nil {
16
+		return nil, err
17
+	}
18
+	containerActions.WithValues("changes").UpdateSince(start)
19
+	return c, nil
15 20
 }
... ...
@@ -120,6 +120,7 @@ func merge(userConf, imageConf *containertypes.Config) error {
120 120
 // Commit creates a new filesystem image from the current state of a container.
121 121
 // The image can optionally be tagged into a repository.
122 122
 func (daemon *Daemon) Commit(name string, c *backend.ContainerCommitConfig) (string, error) {
123
+	start := time.Now()
123 124
 	container, err := daemon.GetContainer(name)
124 125
 	if err != nil {
125 126
 		return "", err
... ...
@@ -244,6 +245,7 @@ func (daemon *Daemon) Commit(name string, c *backend.ContainerCommitConfig) (str
244 244
 		"comment": c.Comment,
245 245
 	}
246 246
 	daemon.LogContainerEventWithAttributes(container, "commit", attributes)
247
+	containerActions.WithValues("commit").UpdateSince(start)
247 248
 	return id.String(), nil
248 249
 }
249 250
 
... ...
@@ -146,6 +146,7 @@ type CommonConfig struct {
146 146
 	// given to the /swarm/init endpoint and no advertise address is
147 147
 	// specified.
148 148
 	SwarmDefaultAdvertiseAddr string `json:"swarm-default-advertise-addr"`
149
+	MetricsAddress            string `json:"metrics-addr"`
149 150
 
150 151
 	LogConfig
151 152
 	bridgeConfig // bridgeConfig holds bridge network specific configuration.
... ...
@@ -191,6 +192,8 @@ func (config *Config) InstallCommonFlags(flags *pflag.FlagSet) {
191 191
 	flags.StringVar(&config.SwarmDefaultAdvertiseAddr, "swarm-default-advertise-addr", "", "Set default address or interface for swarm advertised address")
192 192
 	flags.BoolVar(&config.Experimental, "experimental", false, "Enable experimental features")
193 193
 
194
+	flags.StringVar(&config.MetricsAddress, "metrics-addr", "", "Set default address and port to serve the metrics api on")
195
+
194 196
 	config.MaxConcurrentDownloads = &maxConcurrentDownloads
195 197
 	config.MaxConcurrentUploads = &maxConcurrentUploads
196 198
 }
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"path"
9 9
 	"runtime"
10 10
 	"strings"
11
+	"time"
11 12
 
12 13
 	"github.com/Sirupsen/logrus"
13 14
 	derr "github.com/docker/docker/api/errors"
... ...
@@ -284,8 +285,11 @@ func (daemon *Daemon) updateEndpointNetworkSettings(container *container.Contain
284 284
 // UpdateNetwork is used to update the container's network (e.g. when linked containers
285 285
 // get removed/unlinked).
286 286
 func (daemon *Daemon) updateNetwork(container *container.Container) error {
287
-	ctrl := daemon.netController
288
-	sid := container.NetworkSettings.SandboxID
287
+	var (
288
+		start = time.Now()
289
+		ctrl  = daemon.netController
290
+		sid   = container.NetworkSettings.SandboxID
291
+	)
289 292
 
290 293
 	sb, err := ctrl.SandboxByID(sid)
291 294
 	if err != nil {
... ...
@@ -319,6 +323,8 @@ func (daemon *Daemon) updateNetwork(container *container.Container) error {
319 319
 		return fmt.Errorf("Update network failed: Failure in refresh sandbox %s: %v", sid, err)
320 320
 	}
321 321
 
322
+	networkActions.WithValues("update").UpdateSince(start)
323
+
322 324
 	return nil
323 325
 }
324 326
 
... ...
@@ -452,6 +458,7 @@ func (daemon *Daemon) updateContainerNetworkSettings(container *container.Contai
452 452
 }
453 453
 
454 454
 func (daemon *Daemon) allocateNetwork(container *container.Container) error {
455
+	start := time.Now()
455 456
 	controller := daemon.netController
456 457
 
457 458
 	if daemon.netController == nil {
... ...
@@ -503,7 +510,11 @@ func (daemon *Daemon) allocateNetwork(container *container.Container) error {
503 503
 		}
504 504
 	}
505 505
 
506
-	return container.WriteHostConfig()
506
+	if err := container.WriteHostConfig(); err != nil {
507
+		return err
508
+	}
509
+	networkActions.WithValues("allocate").UpdateSince(start)
510
+	return nil
507 511
 }
508 512
 
509 513
 func (daemon *Daemon) getNetworkSandbox(container *container.Container) libnetwork.Sandbox {
... ...
@@ -613,16 +624,15 @@ func (daemon *Daemon) updateNetworkConfig(container *container.Container, n libn
613 613
 }
614 614
 
615 615
 func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName string, endpointConfig *networktypes.EndpointSettings, updateSettings bool) (err error) {
616
+	start := time.Now()
616 617
 	if container.HostConfig.NetworkMode.IsContainer() {
617 618
 		return runconfig.ErrConflictSharedNetwork
618 619
 	}
619
-
620 620
 	if containertypes.NetworkMode(idOrName).IsBridge() &&
621 621
 		daemon.configStore.DisableBridge {
622 622
 		container.Config.NetworkDisabled = true
623 623
 		return nil
624 624
 	}
625
-
626 625
 	if endpointConfig == nil {
627 626
 		endpointConfig = &networktypes.EndpointSettings{}
628 627
 	}
... ...
@@ -714,6 +724,7 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName
714 714
 	container.NetworkSettings.Ports = getPortMapInfo(sb)
715 715
 
716 716
 	daemon.LogNetworkEventWithAttributes(n, "connect", map[string]string{"container": container.ID})
717
+	networkActions.WithValues("connect").UpdateSince(start)
717 718
 	return nil
718 719
 }
719 720
 
... ...
@@ -835,6 +846,7 @@ func (daemon *Daemon) getNetworkedContainer(containerID, connectedContainerID st
835 835
 }
836 836
 
837 837
 func (daemon *Daemon) releaseNetwork(container *container.Container) {
838
+	start := time.Now()
838 839
 	if daemon.netController == nil {
839 840
 		return
840 841
 	}
... ...
@@ -885,6 +897,7 @@ func (daemon *Daemon) releaseNetwork(container *container.Container) {
885 885
 		}
886 886
 		daemon.LogNetworkEventWithAttributes(nw, "disconnect", attributes)
887 887
 	}
888
+	networkActions.WithValues("release").UpdateSince(start)
888 889
 }
889 890
 
890 891
 func errRemovalContainer(containerID string) error {
... ...
@@ -4,6 +4,7 @@ import (
4 4
 	"fmt"
5 5
 	"net"
6 6
 	"strings"
7
+	"time"
7 8
 
8 9
 	"github.com/Sirupsen/logrus"
9 10
 	"github.com/docker/docker/api/errors"
... ...
@@ -31,6 +32,7 @@ func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig, valida
31 31
 }
32 32
 
33 33
 func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool, validateHostname bool) (types.ContainerCreateResponse, error) {
34
+	start := time.Now()
34 35
 	if params.Config == nil {
35 36
 		return types.ContainerCreateResponse{}, fmt.Errorf("Config cannot be empty in order to create a container")
36 37
 	}
... ...
@@ -57,7 +59,7 @@ func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, manage
57 57
 	if err != nil {
58 58
 		return types.ContainerCreateResponse{Warnings: warnings}, daemon.imageNotExistToErrcode(err)
59 59
 	}
60
-
60
+	containerActions.WithValues("create").UpdateSince(start)
61 61
 	return types.ContainerCreateResponse{ID: container.ID, Warnings: warnings}, nil
62 62
 }
63 63
 
... ...
@@ -28,6 +28,7 @@ import (
28 28
 	"github.com/docker/docker/container"
29 29
 	"github.com/docker/docker/daemon/events"
30 30
 	"github.com/docker/docker/daemon/exec"
31
+	"github.com/docker/docker/dockerversion"
31 32
 	"github.com/docker/libnetwork/cluster"
32 33
 	// register graph drivers
33 34
 	_ "github.com/docker/docker/daemon/graphdriver/register"
... ...
@@ -684,12 +685,25 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot
684 684
 		return nil, err
685 685
 	}
686 686
 
687
+	// FIXME: this method never returns an error
688
+	info, _ := d.SystemInfo()
689
+
690
+	engineVersion.WithValues(
691
+		dockerversion.Version,
692
+		dockerversion.GitCommit,
693
+		info.Architecture,
694
+		info.Driver,
695
+		info.KernelVersion,
696
+		info.OperatingSystem,
697
+	).Set(1)
698
+	engineCpus.Set(float64(info.NCPU))
699
+	engineMemory.Set(float64(info.MemTotal))
700
+
687 701
 	return d, nil
688 702
 }
689 703
 
690 704
 func (daemon *Daemon) shutdownContainer(c *container.Container) error {
691 705
 	stopTimeout := c.StopTimeout()
692
-
693 706
 	// TODO(windows): Handle docker restart with paused containers
694 707
 	if c.IsPaused() {
695 708
 		// To terminate a process in freezer cgroup, we should send
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"os"
6 6
 	"path"
7 7
 	"strings"
8
+	"time"
8 9
 
9 10
 	"github.com/Sirupsen/logrus"
10 11
 	"github.com/docker/docker/api/errors"
... ...
@@ -19,6 +20,7 @@ import (
19 19
 // fails. If the remove succeeds, the container name is released, and
20 20
 // network links are removed.
21 21
 func (daemon *Daemon) ContainerRm(name string, config *types.ContainerRmConfig) error {
22
+	start := time.Now()
22 23
 	container, err := daemon.GetContainer(name)
23 24
 	if err != nil {
24 25
 		return err
... ...
@@ -40,7 +42,10 @@ func (daemon *Daemon) ContainerRm(name string, config *types.ContainerRmConfig)
40 40
 		return daemon.rmLink(container, name)
41 41
 	}
42 42
 
43
-	return daemon.cleanupContainer(container, config.ForceRemove, config.RemoveVolume)
43
+	err = daemon.cleanupContainer(container, config.ForceRemove, config.RemoveVolume)
44
+	containerActions.WithValues("delete").UpdateSince(start)
45
+
46
+	return err
44 47
 }
45 48
 
46 49
 func (daemon *Daemon) rmLink(container *container.Container, name string) error {
... ...
@@ -33,6 +33,7 @@ func New() *Events {
33 33
 // of interface{}, so you need type assertion), and a function to call
34 34
 // to stop the stream of events.
35 35
 func (e *Events) Subscribe() ([]eventtypes.Message, chan interface{}, func()) {
36
+	eventSubscribers.Inc()
36 37
 	e.mu.Lock()
37 38
 	current := make([]eventtypes.Message, len(e.events))
38 39
 	copy(current, e.events)
... ...
@@ -49,6 +50,7 @@ func (e *Events) Subscribe() ([]eventtypes.Message, chan interface{}, func()) {
49 49
 // last events, a channel in which you can expect new events (in form
50 50
 // of interface{}, so you need type assertion).
51 51
 func (e *Events) SubscribeTopic(since, until time.Time, ef *Filter) ([]eventtypes.Message, chan interface{}) {
52
+	eventSubscribers.Inc()
52 53
 	e.mu.Lock()
53 54
 
54 55
 	var topic func(m interface{}) bool
... ...
@@ -72,12 +74,14 @@ func (e *Events) SubscribeTopic(since, until time.Time, ef *Filter) ([]eventtype
72 72
 
73 73
 // Evict evicts listener from pubsub
74 74
 func (e *Events) Evict(l chan interface{}) {
75
+	eventSubscribers.Dec()
75 76
 	e.pub.Evict(l)
76 77
 }
77 78
 
78 79
 // Log broadcasts event to listeners. Each listener has 100 millisecond for
79 80
 // receiving event or it will be skipped.
80 81
 func (e *Events) Log(action, eventType string, actor eventtypes.Actor) {
82
+	eventsCounter.Inc()
81 83
 	now := time.Now().UTC()
82 84
 	jm := eventtypes.Message{
83 85
 		Action:   action,
84 86
new file mode 100644
... ...
@@ -0,0 +1,15 @@
0
+package events
1
+
2
+import "github.com/docker/go-metrics"
3
+
4
+var (
5
+	eventsCounter    metrics.Counter
6
+	eventSubscribers metrics.Gauge
7
+)
8
+
9
+func init() {
10
+	ns := metrics.NewNamespace("engine", "daemon", nil)
11
+	eventsCounter = ns.NewCounter("events", "The number of events logged")
12
+	eventSubscribers = ns.NewGauge("events_subscribers", "The number of current subscribers to events", metrics.Total)
13
+	metrics.Register(ns)
14
+}
... ...
@@ -60,6 +60,7 @@ type cmdProbe struct {
60 60
 // exec the healthcheck command in the container.
61 61
 // Returns the exit code and probe output (if any)
62 62
 func (p *cmdProbe) run(ctx context.Context, d *Daemon, container *container.Container) (*types.HealthcheckResult, error) {
63
+
63 64
 	cmdSlice := strslice.StrSlice(container.Config.Healthcheck.Test)[1:]
64 65
 	if p.shell {
65 66
 		if runtime.GOOS != "windows" {
... ...
@@ -157,8 +158,10 @@ func monitor(d *Daemon, c *container.Container, stop chan struct{}, probe probe)
157 157
 			ctx, cancelProbe := context.WithTimeout(context.Background(), probeTimeout)
158 158
 			results := make(chan *types.HealthcheckResult)
159 159
 			go func() {
160
+				healthChecksCounter.Inc()
160 161
 				result, err := probe.run(ctx, d, c)
161 162
 				if err != nil {
163
+					healthChecksFailedCounter.Inc()
162 164
 					logrus.Warnf("Health check for container %s error: %v", c.ID, err)
163 165
 					results <- &types.HealthcheckResult{
164 166
 						ExitCode: -1,
... ...
@@ -3,6 +3,7 @@ package daemon
3 3
 import (
4 4
 	"fmt"
5 5
 	"strings"
6
+	"time"
6 7
 
7 8
 	"github.com/docker/docker/api/errors"
8 9
 	"github.com/docker/docker/api/types"
... ...
@@ -61,6 +62,7 @@ const (
61 61
 // package. This would require that we no longer need the daemon to determine
62 62
 // whether images are being used by a stopped or running container.
63 63
 func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error) {
64
+	start := time.Now()
64 65
 	records := []types.ImageDelete{}
65 66
 
66 67
 	imgID, err := daemon.GetImageID(imageRef)
... ...
@@ -168,7 +170,13 @@ func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.I
168 168
 		}
169 169
 	}
170 170
 
171
-	return records, daemon.imageDeleteHelper(imgID, &records, force, prune, removedRepositoryRef)
171
+	if err := daemon.imageDeleteHelper(imgID, &records, force, prune, removedRepositoryRef); err != nil {
172
+		return nil, err
173
+	}
174
+
175
+	imageActions.WithValues("delete").UpdateSince(start)
176
+
177
+	return records, nil
172 178
 }
173 179
 
174 180
 // isSingleReference returns true when all references are from one repository
... ...
@@ -2,6 +2,7 @@ package daemon
2 2
 
3 3
 import (
4 4
 	"fmt"
5
+	"time"
5 6
 
6 7
 	"github.com/docker/docker/api/types"
7 8
 	"github.com/docker/docker/layer"
... ...
@@ -11,6 +12,7 @@ import (
11 11
 // ImageHistory returns a slice of ImageHistory structures for the specified image
12 12
 // name by walking the image lineage.
13 13
 func (daemon *Daemon) ImageHistory(name string) ([]*types.ImageHistory, error) {
14
+	start := time.Now()
14 15
 	img, err := daemon.GetImage(name)
15 16
 	if err != nil {
16 17
 		return nil, err
... ...
@@ -77,6 +79,6 @@ func (daemon *Daemon) ImageHistory(name string) ([]*types.ImageHistory, error) {
77 77
 			break
78 78
 		}
79 79
 	}
80
-
80
+	imageActions.WithValues("history").UpdateSince(start)
81 81
 	return history, nil
82 82
 }
... ...
@@ -165,7 +165,9 @@ func (daemon *Daemon) filterByNameIDMatches(ctx *listContext) []*container.Conta
165 165
 
166 166
 // reduceContainers parses the user's filtering options and generates the list of containers to return based on a reducer.
167 167
 func (daemon *Daemon) reduceContainers(config *types.ContainerListOptions, reducer containerReducer) ([]*types.Container, error) {
168
-	containers := []*types.Container{}
168
+	var (
169
+		containers = []*types.Container{}
170
+	)
169 171
 
170 172
 	ctx, err := daemon.foldFilter(config)
171 173
 	if err != nil {
... ...
@@ -190,6 +192,7 @@ func (daemon *Daemon) reduceContainers(config *types.ContainerListOptions, reduc
190 190
 			ctx.idx++
191 191
 		}
192 192
 	}
193
+
193 194
 	return containers, nil
194 195
 }
195 196
 
196 197
new file mode 100644
... ...
@@ -0,0 +1,42 @@
0
+package daemon
1
+
2
+import "github.com/docker/go-metrics"
3
+
4
+var (
5
+	containerActions          metrics.LabeledTimer
6
+	imageActions              metrics.LabeledTimer
7
+	networkActions            metrics.LabeledTimer
8
+	engineVersion             metrics.LabeledGauge
9
+	engineCpus                metrics.Gauge
10
+	engineMemory              metrics.Gauge
11
+	healthChecksCounter       metrics.Counter
12
+	healthChecksFailedCounter metrics.Counter
13
+)
14
+
15
+func init() {
16
+	ns := metrics.NewNamespace("engine", "daemon", nil)
17
+	containerActions = ns.NewLabeledTimer("container_actions", "The number of seconds it takes to process each container action", "action")
18
+	for _, a := range []string{
19
+		"start",
20
+		"changes",
21
+		"commit",
22
+		"create",
23
+		"delete",
24
+	} {
25
+		containerActions.WithValues(a).Update(0)
26
+	}
27
+	networkActions = ns.NewLabeledTimer("network_actions", "The number of seconds it takes to process each network action", "action")
28
+	engineVersion = ns.NewLabeledGauge("engine", "The version and commit information for the engine process", metrics.Unit("info"),
29
+		"version",
30
+		"commit",
31
+		"architecture",
32
+		"graph_driver", "kernel",
33
+		"os",
34
+	)
35
+	engineCpus = ns.NewGauge("engine_cpus", "The number of cpus that the host system of the engine has", metrics.Unit("cpus"))
36
+	engineMemory = ns.NewGauge("engine_memory", "The number of bytes of memory that the host system of the engine has", metrics.Bytes)
37
+	healthChecksCounter = ns.NewCounter("health_checks", "The total number of health checks")
38
+	healthChecksFailedCounter = ns.NewCounter("health_checks_failed", "The total number of failed health checks")
39
+	imageActions = ns.NewLabeledTimer("image_actions", "The number of seconds it takes to process each image action", "action")
40
+	metrics.Register(ns)
41
+}
... ...
@@ -292,6 +292,7 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string
292 292
 	}
293 293
 
294 294
 	daemon.LogNetworkEvent(n, "create")
295
+
295 296
 	return &types.NetworkCreateResponse{
296 297
 		ID:      n.ID(),
297 298
 		Warning: warning,
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"runtime"
7 7
 	"strings"
8 8
 	"syscall"
9
+	"time"
9 10
 
10 11
 	"google.golang.org/grpc"
11 12
 
... ...
@@ -90,6 +91,7 @@ func (daemon *Daemon) Start(container *container.Container) error {
90 90
 // between containers. The container is left waiting for a signal to
91 91
 // begin running.
92 92
 func (daemon *Daemon) containerStart(container *container.Container, checkpoint string, resetRestartManager bool) (err error) {
93
+	start := time.Now()
93 94
 	container.Lock()
94 95
 	defer container.Unlock()
95 96
 
... ...
@@ -177,6 +179,8 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
177 177
 		return fmt.Errorf("%s", errDesc)
178 178
 	}
179 179
 
180
+	containerActions.WithValues("start").UpdateSince(start)
181
+
180 182
 	return nil
181 183
 }
182 184
 
... ...
@@ -175,4 +175,7 @@ clone git github.com/spf13/pflag dabebe21bf790f782ea4c7bbd2efc430de182afd
175 175
 clone git github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
176 176
 clone git github.com/flynn-archive/go-shlex 3f9db97f856818214da2e1057f8ad84803971cff
177 177
 
178
+# metrics
179
+clone git github.com/docker/go-metrics 86138d05f285fd9737a99bee2d9be30866b59d72
180
+
178 181
 clean
... ...
@@ -379,7 +379,7 @@ func (s *DockerExternalGraphdriverSuite) testExternalGraphDriver(name string, ex
379 379
 	c.Assert(s.ec[ext].removals >= 1, check.Equals, true)
380 380
 	c.Assert(s.ec[ext].gets >= 1, check.Equals, true)
381 381
 	c.Assert(s.ec[ext].puts >= 1, check.Equals, true)
382
-	c.Assert(s.ec[ext].stats, check.Equals, 3)
382
+	c.Assert(s.ec[ext].stats, check.Equals, 5)
383 383
 	c.Assert(s.ec[ext].cleanups, check.Equals, 2)
384 384
 	c.Assert(s.ec[ext].applydiff >= 1, check.Equals, true)
385 385
 	c.Assert(s.ec[ext].changes, check.Equals, 1)
386 386
new file mode 100644
... ...
@@ -0,0 +1,55 @@
0
+# Contributing
1
+
2
+## Sign your work
3
+
4
+The sign-off is a simple line at the end of the explanation for the patch. Your
5
+signature certifies that you wrote the patch or otherwise have the right to pass
6
+it on as an open-source patch. The rules are pretty simple: if you can certify
7
+the below (from [developercertificate.org](http://developercertificate.org/)):
8
+
9
+```
10
+Developer Certificate of Origin
11
+Version 1.1
12
+
13
+Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
14
+660 York Street, Suite 102,
15
+San Francisco, CA 94110 USA
16
+
17
+Everyone is permitted to copy and distribute verbatim copies of this
18
+license document, but changing it is not allowed.
19
+
20
+Developer's Certificate of Origin 1.1
21
+
22
+By making a contribution to this project, I certify that:
23
+
24
+(a) The contribution was created in whole or in part by me and I
25
+    have the right to submit it under the open source license
26
+    indicated in the file; or
27
+
28
+(b) The contribution is based upon previous work that, to the best
29
+    of my knowledge, is covered under an appropriate open source
30
+    license and I have the right under that license to submit that
31
+    work with modifications, whether created in whole or in part
32
+    by me, under the same open source license (unless I am
33
+    permitted to submit under a different license), as indicated
34
+    in the file; or
35
+
36
+(c) The contribution was provided directly to me by some other
37
+    person who certified (a), (b) or (c) and I have not modified
38
+    it.
39
+
40
+(d) I understand and agree that this project and the contribution
41
+    are public and that a record of the contribution (including all
42
+    personal information I submit with it, including my sign-off) is
43
+    maintained indefinitely and may be redistributed consistent with
44
+    this project or the open source license(s) involved.
45
+```
46
+
47
+Then you just add a line to every git commit message:
48
+
49
+    Signed-off-by: Joe Smith <joe.smith@email.com>
50
+
51
+Use your real name (sorry, no pseudonyms or anonymous contributions.)
52
+
53
+If you set your `user.name` and `user.email` git configs, you can sign your
54
+commit automatically with `git commit -s`.
0 55
new file mode 100644
... ...
@@ -0,0 +1,191 @@
0
+
1
+                                 Apache License
2
+                           Version 2.0, January 2004
3
+                        https://www.apache.org/licenses/
4
+
5
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+   1. Definitions.
8
+
9
+      "License" shall mean the terms and conditions for use, reproduction,
10
+      and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+      "Licensor" shall mean the copyright owner or entity authorized by
13
+      the copyright owner that is granting the License.
14
+
15
+      "Legal Entity" shall mean the union of the acting entity and all
16
+      other entities that control, are controlled by, or are under common
17
+      control with that entity. For the purposes of this definition,
18
+      "control" means (i) the power, direct or indirect, to cause the
19
+      direction or management of such entity, whether by contract or
20
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+      outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+      "You" (or "Your") shall mean an individual or Legal Entity
24
+      exercising permissions granted by this License.
25
+
26
+      "Source" form shall mean the preferred form for making modifications,
27
+      including but not limited to software source code, documentation
28
+      source, and configuration files.
29
+
30
+      "Object" form shall mean any form resulting from mechanical
31
+      transformation or translation of a Source form, including but
32
+      not limited to compiled object code, generated documentation,
33
+      and conversions to other media types.
34
+
35
+      "Work" shall mean the work of authorship, whether in Source or
36
+      Object form, made available under the License, as indicated by a
37
+      copyright notice that is included in or attached to the work
38
+      (an example is provided in the Appendix below).
39
+
40
+      "Derivative Works" shall mean any work, whether in Source or Object
41
+      form, that is based on (or derived from) the Work and for which the
42
+      editorial revisions, annotations, elaborations, or other modifications
43
+      represent, as a whole, an original work of authorship. For the purposes
44
+      of this License, Derivative Works shall not include works that remain
45
+      separable from, or merely link (or bind by name) to the interfaces of,
46
+      the Work and Derivative Works thereof.
47
+
48
+      "Contribution" shall mean any work of authorship, including
49
+      the original version of the Work and any modifications or additions
50
+      to that Work or Derivative Works thereof, that is intentionally
51
+      submitted to Licensor for inclusion in the Work by the copyright owner
52
+      or by an individual or Legal Entity authorized to submit on behalf of
53
+      the copyright owner. For the purposes of this definition, "submitted"
54
+      means any form of electronic, verbal, or written communication sent
55
+      to the Licensor or its representatives, including but not limited to
56
+      communication on electronic mailing lists, source code control systems,
57
+      and issue tracking systems that are managed by, or on behalf of, the
58
+      Licensor for the purpose of discussing and improving the Work, but
59
+      excluding communication that is conspicuously marked or otherwise
60
+      designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+      "Contributor" shall mean Licensor and any individual or Legal Entity
63
+      on behalf of whom a Contribution has been received by Licensor and
64
+      subsequently incorporated within the Work.
65
+
66
+   2. Grant of Copyright License. Subject to the terms and conditions of
67
+      this License, each Contributor hereby grants to You a perpetual,
68
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+      copyright license to reproduce, prepare Derivative Works of,
70
+      publicly display, publicly perform, sublicense, and distribute the
71
+      Work and such Derivative Works in Source or Object form.
72
+
73
+   3. Grant of Patent License. Subject to the terms and conditions of
74
+      this License, each Contributor hereby grants to You a perpetual,
75
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+      (except as stated in this section) patent license to make, have made,
77
+      use, offer to sell, sell, import, and otherwise transfer the Work,
78
+      where such license applies only to those patent claims licensable
79
+      by such Contributor that are necessarily infringed by their
80
+      Contribution(s) alone or by combination of their Contribution(s)
81
+      with the Work to which such Contribution(s) was submitted. If You
82
+      institute patent litigation against any entity (including a
83
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+      or a Contribution incorporated within the Work constitutes direct
85
+      or contributory patent infringement, then any patent licenses
86
+      granted to You under this License for that Work shall terminate
87
+      as of the date such litigation is filed.
88
+
89
+   4. Redistribution. You may reproduce and distribute copies of the
90
+      Work or Derivative Works thereof in any medium, with or without
91
+      modifications, and in Source or Object form, provided that You
92
+      meet the following conditions:
93
+
94
+      (a) You must give any other recipients of the Work or
95
+          Derivative Works a copy of this License; and
96
+
97
+      (b) You must cause any modified files to carry prominent notices
98
+          stating that You changed the files; and
99
+
100
+      (c) You must retain, in the Source form of any Derivative Works
101
+          that You distribute, all copyright, patent, trademark, and
102
+          attribution notices from the Source form of the Work,
103
+          excluding those notices that do not pertain to any part of
104
+          the Derivative Works; and
105
+
106
+      (d) If the Work includes a "NOTICE" text file as part of its
107
+          distribution, then any Derivative Works that You distribute must
108
+          include a readable copy of the attribution notices contained
109
+          within such NOTICE file, excluding those notices that do not
110
+          pertain to any part of the Derivative Works, in at least one
111
+          of the following places: within a NOTICE text file distributed
112
+          as part of the Derivative Works; within the Source form or
113
+          documentation, if provided along with the Derivative Works; or,
114
+          within a display generated by the Derivative Works, if and
115
+          wherever such third-party notices normally appear. The contents
116
+          of the NOTICE file are for informational purposes only and
117
+          do not modify the License. You may add Your own attribution
118
+          notices within Derivative Works that You distribute, alongside
119
+          or as an addendum to the NOTICE text from the Work, provided
120
+          that such additional attribution notices cannot be construed
121
+          as modifying the License.
122
+
123
+      You may add Your own copyright statement to Your modifications and
124
+      may provide additional or different license terms and conditions
125
+      for use, reproduction, or distribution of Your modifications, or
126
+      for any such Derivative Works as a whole, provided Your use,
127
+      reproduction, and distribution of the Work otherwise complies with
128
+      the conditions stated in this License.
129
+
130
+   5. Submission of Contributions. Unless You explicitly state otherwise,
131
+      any Contribution intentionally submitted for inclusion in the Work
132
+      by You to the Licensor shall be under the terms and conditions of
133
+      this License, without any additional terms or conditions.
134
+      Notwithstanding the above, nothing herein shall supersede or modify
135
+      the terms of any separate license agreement you may have executed
136
+      with Licensor regarding such Contributions.
137
+
138
+   6. Trademarks. This License does not grant permission to use the trade
139
+      names, trademarks, service marks, or product names of the Licensor,
140
+      except as required for reasonable and customary use in describing the
141
+      origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+   7. Disclaimer of Warranty. Unless required by applicable law or
144
+      agreed to in writing, Licensor provides the Work (and each
145
+      Contributor provides its Contributions) on an "AS IS" BASIS,
146
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+      implied, including, without limitation, any warranties or conditions
148
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+      PARTICULAR PURPOSE. You are solely responsible for determining the
150
+      appropriateness of using or redistributing the Work and assume any
151
+      risks associated with Your exercise of permissions under this License.
152
+
153
+   8. Limitation of Liability. In no event and under no legal theory,
154
+      whether in tort (including negligence), contract, or otherwise,
155
+      unless required by applicable law (such as deliberate and grossly
156
+      negligent acts) or agreed to in writing, shall any Contributor be
157
+      liable to You for damages, including any direct, indirect, special,
158
+      incidental, or consequential damages of any character arising as a
159
+      result of this License or out of the use or inability to use the
160
+      Work (including but not limited to damages for loss of goodwill,
161
+      work stoppage, computer failure or malfunction, or any and all
162
+      other commercial damages or losses), even if such Contributor
163
+      has been advised of the possibility of such damages.
164
+
165
+   9. Accepting Warranty or Additional Liability. While redistributing
166
+      the Work or Derivative Works thereof, You may choose to offer,
167
+      and charge a fee for, acceptance of support, warranty, indemnity,
168
+      or other liability obligations and/or rights consistent with this
169
+      License. However, in accepting such obligations, You may act only
170
+      on Your own behalf and on Your sole responsibility, not on behalf
171
+      of any other Contributor, and only if You agree to indemnify,
172
+      defend, and hold each Contributor harmless for any liability
173
+      incurred by, or claims asserted against, such Contributor by reason
174
+      of your accepting any such warranty or additional liability.
175
+
176
+   END OF TERMS AND CONDITIONS
177
+
178
+   Copyright 2013-2016 Docker, Inc.
179
+
180
+   Licensed under the Apache License, Version 2.0 (the "License");
181
+   you may not use this file except in compliance with the License.
182
+   You may obtain a copy of the License at
183
+
184
+       https://www.apache.org/licenses/LICENSE-2.0
185
+
186
+   Unless required by applicable law or agreed to in writing, software
187
+   distributed under the License is distributed on an "AS IS" BASIS,
188
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+   See the License for the specific language governing permissions and
190
+   limitations under the License.
0 191
new file mode 100644
... ...
@@ -0,0 +1,425 @@
0
+Attribution-ShareAlike 4.0 International
1
+
2
+=======================================================================
3
+
4
+Creative Commons Corporation ("Creative Commons") is not a law firm and
5
+does not provide legal services or legal advice. Distribution of
6
+Creative Commons public licenses does not create a lawyer-client or
7
+other relationship. Creative Commons makes its licenses and related
8
+information available on an "as-is" basis. Creative Commons gives no
9
+warranties regarding its licenses, any material licensed under their
10
+terms and conditions, or any related information. Creative Commons
11
+disclaims all liability for damages resulting from their use to the
12
+fullest extent possible.
13
+
14
+Using Creative Commons Public Licenses
15
+
16
+Creative Commons public licenses provide a standard set of terms and
17
+conditions that creators and other rights holders may use to share
18
+original works of authorship and other material subject to copyright
19
+and certain other rights specified in the public license below. The
20
+following considerations are for informational purposes only, are not
21
+exhaustive, and do not form part of our licenses.
22
+
23
+     Considerations for licensors: Our public licenses are
24
+     intended for use by those authorized to give the public
25
+     permission to use material in ways otherwise restricted by
26
+     copyright and certain other rights. Our licenses are
27
+     irrevocable. Licensors should read and understand the terms
28
+     and conditions of the license they choose before applying it.
29
+     Licensors should also secure all rights necessary before
30
+     applying our licenses so that the public can reuse the
31
+     material as expected. Licensors should clearly mark any
32
+     material not subject to the license. This includes other CC-
33
+     licensed material, or material used under an exception or
34
+     limitation to copyright. More considerations for licensors:
35
+	wiki.creativecommons.org/Considerations_for_licensors
36
+
37
+     Considerations for the public: By using one of our public
38
+     licenses, a licensor grants the public permission to use the
39
+     licensed material under specified terms and conditions. If
40
+     the licensor's permission is not necessary for any reason--for
41
+     example, because of any applicable exception or limitation to
42
+     copyright--then that use is not regulated by the license. Our
43
+     licenses grant only permissions under copyright and certain
44
+     other rights that a licensor has authority to grant. Use of
45
+     the licensed material may still be restricted for other
46
+     reasons, including because others have copyright or other
47
+     rights in the material. A licensor may make special requests,
48
+     such as asking that all changes be marked or described.
49
+     Although not required by our licenses, you are encouraged to
50
+     respect those requests where reasonable. More_considerations
51
+     for the public:
52
+	wiki.creativecommons.org/Considerations_for_licensees
53
+
54
+=======================================================================
55
+
56
+Creative Commons Attribution-ShareAlike 4.0 International Public
57
+License
58
+
59
+By exercising the Licensed Rights (defined below), You accept and agree
60
+to be bound by the terms and conditions of this Creative Commons
61
+Attribution-ShareAlike 4.0 International Public License ("Public
62
+License"). To the extent this Public License may be interpreted as a
63
+contract, You are granted the Licensed Rights in consideration of Your
64
+acceptance of these terms and conditions, and the Licensor grants You
65
+such rights in consideration of benefits the Licensor receives from
66
+making the Licensed Material available under these terms and
67
+conditions.
68
+
69
+
70
+Section 1 -- Definitions.
71
+
72
+  a. Adapted Material means material subject to Copyright and Similar
73
+     Rights that is derived from or based upon the Licensed Material
74
+     and in which the Licensed Material is translated, altered,
75
+     arranged, transformed, or otherwise modified in a manner requiring
76
+     permission under the Copyright and Similar Rights held by the
77
+     Licensor. For purposes of this Public License, where the Licensed
78
+     Material is a musical work, performance, or sound recording,
79
+     Adapted Material is always produced where the Licensed Material is
80
+     synched in timed relation with a moving image.
81
+
82
+  b. Adapter's License means the license You apply to Your Copyright
83
+     and Similar Rights in Your contributions to Adapted Material in
84
+     accordance with the terms and conditions of this Public License.
85
+
86
+  c. BY-SA Compatible License means a license listed at
87
+     creativecommons.org/compatiblelicenses, approved by Creative
88
+     Commons as essentially the equivalent of this Public License.
89
+
90
+  d. Copyright and Similar Rights means copyright and/or similar rights
91
+     closely related to copyright including, without limitation,
92
+     performance, broadcast, sound recording, and Sui Generis Database
93
+     Rights, without regard to how the rights are labeled or
94
+     categorized. For purposes of this Public License, the rights
95
+     specified in Section 2(b)(1)-(2) are not Copyright and Similar
96
+     Rights.
97
+
98
+  e. Effective Technological Measures means those measures that, in the
99
+     absence of proper authority, may not be circumvented under laws
100
+     fulfilling obligations under Article 11 of the WIPO Copyright
101
+     Treaty adopted on December 20, 1996, and/or similar international
102
+     agreements.
103
+
104
+  f. Exceptions and Limitations means fair use, fair dealing, and/or
105
+     any other exception or limitation to Copyright and Similar Rights
106
+     that applies to Your use of the Licensed Material.
107
+
108
+  g. License Elements means the license attributes listed in the name
109
+     of a Creative Commons Public License. The License Elements of this
110
+     Public License are Attribution and ShareAlike.
111
+
112
+  h. Licensed Material means the artistic or literary work, database,
113
+     or other material to which the Licensor applied this Public
114
+     License.
115
+
116
+  i. Licensed Rights means the rights granted to You subject to the
117
+     terms and conditions of this Public License, which are limited to
118
+     all Copyright and Similar Rights that apply to Your use of the
119
+     Licensed Material and that the Licensor has authority to license.
120
+
121
+  j. Licensor means the individual(s) or entity(ies) granting rights
122
+     under this Public License.
123
+
124
+  k. Share means to provide material to the public by any means or
125
+     process that requires permission under the Licensed Rights, such
126
+     as reproduction, public display, public performance, distribution,
127
+     dissemination, communication, or importation, and to make material
128
+     available to the public including in ways that members of the
129
+     public may access the material from a place and at a time
130
+     individually chosen by them.
131
+
132
+  l. Sui Generis Database Rights means rights other than copyright
133
+     resulting from Directive 96/9/EC of the European Parliament and of
134
+     the Council of 11 March 1996 on the legal protection of databases,
135
+     as amended and/or succeeded, as well as other essentially
136
+     equivalent rights anywhere in the world.
137
+
138
+  m. You means the individual or entity exercising the Licensed Rights
139
+     under this Public License. Your has a corresponding meaning.
140
+
141
+
142
+Section 2 -- Scope.
143
+
144
+  a. License grant.
145
+
146
+       1. Subject to the terms and conditions of this Public License,
147
+          the Licensor hereby grants You a worldwide, royalty-free,
148
+          non-sublicensable, non-exclusive, irrevocable license to
149
+          exercise the Licensed Rights in the Licensed Material to:
150
+
151
+            a. reproduce and Share the Licensed Material, in whole or
152
+               in part; and
153
+
154
+            b. produce, reproduce, and Share Adapted Material.
155
+
156
+       2. Exceptions and Limitations. For the avoidance of doubt, where
157
+          Exceptions and Limitations apply to Your use, this Public
158
+          License does not apply, and You do not need to comply with
159
+          its terms and conditions.
160
+
161
+       3. Term. The term of this Public License is specified in Section
162
+          6(a).
163
+
164
+       4. Media and formats; technical modifications allowed. The
165
+          Licensor authorizes You to exercise the Licensed Rights in
166
+          all media and formats whether now known or hereafter created,
167
+          and to make technical modifications necessary to do so. The
168
+          Licensor waives and/or agrees not to assert any right or
169
+          authority to forbid You from making technical modifications
170
+          necessary to exercise the Licensed Rights, including
171
+          technical modifications necessary to circumvent Effective
172
+          Technological Measures. For purposes of this Public License,
173
+          simply making modifications authorized by this Section 2(a)
174
+          (4) never produces Adapted Material.
175
+
176
+       5. Downstream recipients.
177
+
178
+            a. Offer from the Licensor -- Licensed Material. Every
179
+               recipient of the Licensed Material automatically
180
+               receives an offer from the Licensor to exercise the
181
+               Licensed Rights under the terms and conditions of this
182
+               Public License.
183
+
184
+            b. Additional offer from the Licensor -- Adapted Material.
185
+               Every recipient of Adapted Material from You
186
+               automatically receives an offer from the Licensor to
187
+               exercise the Licensed Rights in the Adapted Material
188
+               under the conditions of the Adapter's License You apply.
189
+
190
+            c. No downstream restrictions. You may not offer or impose
191
+               any additional or different terms or conditions on, or
192
+               apply any Effective Technological Measures to, the
193
+               Licensed Material if doing so restricts exercise of the
194
+               Licensed Rights by any recipient of the Licensed
195
+               Material.
196
+
197
+       6. No endorsement. Nothing in this Public License constitutes or
198
+          may be construed as permission to assert or imply that You
199
+          are, or that Your use of the Licensed Material is, connected
200
+          with, or sponsored, endorsed, or granted official status by,
201
+          the Licensor or others designated to receive attribution as
202
+          provided in Section 3(a)(1)(A)(i).
203
+
204
+  b. Other rights.
205
+
206
+       1. Moral rights, such as the right of integrity, are not
207
+          licensed under this Public License, nor are publicity,
208
+          privacy, and/or other similar personality rights; however, to
209
+          the extent possible, the Licensor waives and/or agrees not to
210
+          assert any such rights held by the Licensor to the limited
211
+          extent necessary to allow You to exercise the Licensed
212
+          Rights, but not otherwise.
213
+
214
+       2. Patent and trademark rights are not licensed under this
215
+          Public License.
216
+
217
+       3. To the extent possible, the Licensor waives any right to
218
+          collect royalties from You for the exercise of the Licensed
219
+          Rights, whether directly or through a collecting society
220
+          under any voluntary or waivable statutory or compulsory
221
+          licensing scheme. In all other cases the Licensor expressly
222
+          reserves any right to collect such royalties.
223
+
224
+
225
+Section 3 -- License Conditions.
226
+
227
+Your exercise of the Licensed Rights is expressly made subject to the
228
+following conditions.
229
+
230
+  a. Attribution.
231
+
232
+       1. If You Share the Licensed Material (including in modified
233
+          form), You must:
234
+
235
+            a. retain the following if it is supplied by the Licensor
236
+               with the Licensed Material:
237
+
238
+                 i. identification of the creator(s) of the Licensed
239
+                    Material and any others designated to receive
240
+                    attribution, in any reasonable manner requested by
241
+                    the Licensor (including by pseudonym if
242
+                    designated);
243
+
244
+                ii. a copyright notice;
245
+
246
+               iii. a notice that refers to this Public License;
247
+
248
+                iv. a notice that refers to the disclaimer of
249
+                    warranties;
250
+
251
+                 v. a URI or hyperlink to the Licensed Material to the
252
+                    extent reasonably practicable;
253
+
254
+            b. indicate if You modified the Licensed Material and
255
+               retain an indication of any previous modifications; and
256
+
257
+            c. indicate the Licensed Material is licensed under this
258
+               Public License, and include the text of, or the URI or
259
+               hyperlink to, this Public License.
260
+
261
+       2. You may satisfy the conditions in Section 3(a)(1) in any
262
+          reasonable manner based on the medium, means, and context in
263
+          which You Share the Licensed Material. For example, it may be
264
+          reasonable to satisfy the conditions by providing a URI or
265
+          hyperlink to a resource that includes the required
266
+          information.
267
+
268
+       3. If requested by the Licensor, You must remove any of the
269
+          information required by Section 3(a)(1)(A) to the extent
270
+          reasonably practicable.
271
+
272
+  b. ShareAlike.
273
+
274
+     In addition to the conditions in Section 3(a), if You Share
275
+     Adapted Material You produce, the following conditions also apply.
276
+
277
+       1. The Adapter's License You apply must be a Creative Commons
278
+          license with the same License Elements, this version or
279
+          later, or a BY-SA Compatible License.
280
+
281
+       2. You must include the text of, or the URI or hyperlink to, the
282
+          Adapter's License You apply. You may satisfy this condition
283
+          in any reasonable manner based on the medium, means, and
284
+          context in which You Share Adapted Material.
285
+
286
+       3. You may not offer or impose any additional or different terms
287
+          or conditions on, or apply any Effective Technological
288
+          Measures to, Adapted Material that restrict exercise of the
289
+          rights granted under the Adapter's License You apply.
290
+
291
+
292
+Section 4 -- Sui Generis Database Rights.
293
+
294
+Where the Licensed Rights include Sui Generis Database Rights that
295
+apply to Your use of the Licensed Material:
296
+
297
+  a. for the avoidance of doubt, Section 2(a)(1) grants You the right
298
+     to extract, reuse, reproduce, and Share all or a substantial
299
+     portion of the contents of the database;
300
+
301
+  b. if You include all or a substantial portion of the database
302
+     contents in a database in which You have Sui Generis Database
303
+     Rights, then the database in which You have Sui Generis Database
304
+     Rights (but not its individual contents) is Adapted Material,
305
+
306
+     including for purposes of Section 3(b); and
307
+  c. You must comply with the conditions in Section 3(a) if You Share
308
+     all or a substantial portion of the contents of the database.
309
+
310
+For the avoidance of doubt, this Section 4 supplements and does not
311
+replace Your obligations under this Public License where the Licensed
312
+Rights include other Copyright and Similar Rights.
313
+
314
+
315
+Section 5 -- Disclaimer of Warranties and Limitation of Liability.
316
+
317
+  a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
318
+     EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
319
+     AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
320
+     ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
321
+     IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
322
+     WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
323
+     PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
324
+     ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
325
+     KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
326
+     ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
327
+
328
+  b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
329
+     TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
330
+     NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
331
+     INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
332
+     COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
333
+     USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
334
+     ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
335
+     DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
336
+     IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
337
+
338
+  c. The disclaimer of warranties and limitation of liability provided
339
+     above shall be interpreted in a manner that, to the extent
340
+     possible, most closely approximates an absolute disclaimer and
341
+     waiver of all liability.
342
+
343
+
344
+Section 6 -- Term and Termination.
345
+
346
+  a. This Public License applies for the term of the Copyright and
347
+     Similar Rights licensed here. However, if You fail to comply with
348
+     this Public License, then Your rights under this Public License
349
+     terminate automatically.
350
+
351
+  b. Where Your right to use the Licensed Material has terminated under
352
+     Section 6(a), it reinstates:
353
+
354
+       1. automatically as of the date the violation is cured, provided
355
+          it is cured within 30 days of Your discovery of the
356
+          violation; or
357
+
358
+       2. upon express reinstatement by the Licensor.
359
+
360
+     For the avoidance of doubt, this Section 6(b) does not affect any
361
+     right the Licensor may have to seek remedies for Your violations
362
+     of this Public License.
363
+
364
+  c. For the avoidance of doubt, the Licensor may also offer the
365
+     Licensed Material under separate terms or conditions or stop
366
+     distributing the Licensed Material at any time; however, doing so
367
+     will not terminate this Public License.
368
+
369
+  d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
370
+     License.
371
+
372
+
373
+Section 7 -- Other Terms and Conditions.
374
+
375
+  a. The Licensor shall not be bound by any additional or different
376
+     terms or conditions communicated by You unless expressly agreed.
377
+
378
+  b. Any arrangements, understandings, or agreements regarding the
379
+     Licensed Material not stated herein are separate from and
380
+     independent of the terms and conditions of this Public License.
381
+
382
+
383
+Section 8 -- Interpretation.
384
+
385
+  a. For the avoidance of doubt, this Public License does not, and
386
+     shall not be interpreted to, reduce, limit, restrict, or impose
387
+     conditions on any use of the Licensed Material that could lawfully
388
+     be made without permission under this Public License.
389
+
390
+  b. To the extent possible, if any provision of this Public License is
391
+     deemed unenforceable, it shall be automatically reformed to the
392
+     minimum extent necessary to make it enforceable. If the provision
393
+     cannot be reformed, it shall be severed from this Public License
394
+     without affecting the enforceability of the remaining terms and
395
+     conditions.
396
+
397
+  c. No term or condition of this Public License will be waived and no
398
+     failure to comply consented to unless expressly agreed to by the
399
+     Licensor.
400
+
401
+  d. Nothing in this Public License constitutes or may be interpreted
402
+     as a limitation upon, or waiver of, any privileges and immunities
403
+     that apply to the Licensor or You, including from the legal
404
+     processes of any jurisdiction or authority.
405
+
406
+
407
+=======================================================================
408
+
409
+Creative Commons is not a party to its public licenses.
410
+Notwithstanding, Creative Commons may elect to apply one of its public
411
+licenses to material it publishes and in those instances will be
412
+considered the "Licensor." Except for the limited purpose of indicating
413
+that material is shared under a Creative Commons public license or as
414
+otherwise permitted by the Creative Commons policies published at
415
+creativecommons.org/policies, Creative Commons does not authorize the
416
+use of the trademark "Creative Commons" or any other trademark or logo
417
+of Creative Commons without its prior written consent including,
418
+without limitation, in connection with any unauthorized modifications
419
+to any of its public licenses or any other arrangements,
420
+understandings, or agreements concerning use of licensed material. For
421
+the avoidance of doubt, this paragraph does not form part of the public
422
+licenses.
423
+
424
+Creative Commons may be contacted at creativecommons.org.
0 425
new file mode 100644
... ...
@@ -0,0 +1,16 @@
0
+Docker
1
+Copyright 2012-2015 Docker, Inc.
2
+
3
+This product includes software developed at Docker, Inc. (https://www.docker.com).
4
+
5
+The following is courtesy of our legal counsel:
6
+
7
+
8
+Use and transfer of Docker may be subject to certain restrictions by the
9
+United States and other governments.
10
+It is your responsibility to ensure that your use and/or transfer does not
11
+violate applicable laws.
12
+
13
+For more information, please see https://www.bis.doc.gov
14
+
15
+See also https://www.apache.org/dev/crypto.html and/or seek legal counsel.
0 16
new file mode 100644
... ...
@@ -0,0 +1,22 @@
0
+# go-metrics [![GoDoc](https://godoc.org/github.com/docker/go-metrics?status.svg)](https://godoc.org/github.com/docker/go-metrics) ![Badge Badge](http://doyouevenbadge.com/github.com/docker/go-metrics)
1
+
2
+This package is small wrapper around the prometheus go client to help enforce convention and best practices for metrics collection in Docker projects.
3
+
4
+## Status
5
+
6
+This project is a work in progress.
7
+It is under heavy development and not intended to be used.
8
+
9
+## Docs
10
+
11
+Package documentation can be found [here](https://godoc.org/github.com/docker/go-metrics).
12
+
13
+## Additional Metrics
14
+
15
+Additional metrics are also defined here that are not avaliable in the prometheus client.
16
+If you need a custom metrics and it is generic enough to be used by multiple projects, define it here.
17
+
18
+
19
+## Copyright and license
20
+
21
+Copyright © 2016 Docker, Inc. All rights reserved, except as follows. Code is released under the Apache 2.0 license. The README.md file, and files in the "docs" folder are licensed under the Creative Commons Attribution 4.0 International License under the terms and conditions set forth in the file "LICENSE.docs". You may obtain a duplicate copy of the same license, titled CC-BY-SA-4.0, at http://creativecommons.org/licenses/by/4.0/.
0 22
new file mode 100644
... ...
@@ -0,0 +1,52 @@
0
+package metrics
1
+
2
+import "github.com/prometheus/client_golang/prometheus"
3
+
4
+// Counter is a metrics that can only increment its current count
5
+type Counter interface {
6
+	// Inc adds Sum(vs) to the counter. Sum(vs) must be positive.
7
+	//
8
+	// If len(vs) == 0, increments the counter by 1.
9
+	Inc(vs ...float64)
10
+}
11
+
12
+// LabeledCounter is counter that must have labels populated before use.
13
+type LabeledCounter interface {
14
+	WithValues(vs ...string) Counter
15
+}
16
+
17
+type labeledCounter struct {
18
+	pc *prometheus.CounterVec
19
+}
20
+
21
+func (lc *labeledCounter) WithValues(vs ...string) Counter {
22
+	return &counter{pc: lc.pc.WithLabelValues(vs...)}
23
+}
24
+
25
+func (lc *labeledCounter) Describe(ch chan<- *prometheus.Desc) {
26
+	lc.pc.Describe(ch)
27
+}
28
+
29
+func (lc *labeledCounter) Collect(ch chan<- prometheus.Metric) {
30
+	lc.pc.Collect(ch)
31
+}
32
+
33
+type counter struct {
34
+	pc prometheus.Counter
35
+}
36
+
37
+func (c *counter) Inc(vs ...float64) {
38
+	if len(vs) == 0 {
39
+		c.pc.Inc()
40
+	}
41
+
42
+	c.pc.Add(sumFloat64(vs...))
43
+}
44
+
45
+func (c *counter) Describe(ch chan<- *prometheus.Desc) {
46
+	c.pc.Describe(ch)
47
+}
48
+
49
+func (c *counter) Collect(ch chan<- prometheus.Metric) {
50
+	c.pc.Collect(ch)
51
+}
0 52
new file mode 100644
... ...
@@ -0,0 +1,3 @@
0
+// This package is small wrapper around the prometheus go client to help enforce convention and best practices for metrics collection in Docker projects.
1
+
2
+package metrics
0 3
new file mode 100644
... ...
@@ -0,0 +1,72 @@
0
+package metrics
1
+
2
+import "github.com/prometheus/client_golang/prometheus"
3
+
4
+// Gauge is a metric that allows incrementing and decrementing a value
5
+type Gauge interface {
6
+	Inc(...float64)
7
+	Dec(...float64)
8
+
9
+	// Add adds the provided value to the gauge's current value
10
+	Add(float64)
11
+
12
+	// Set replaces the gauge's current value with the provided value
13
+	Set(float64)
14
+}
15
+
16
+// LabeledGauge describes a gauge the must have values populated before use.
17
+type LabeledGauge interface {
18
+	WithValues(labels ...string) Gauge
19
+}
20
+
21
+type labeledGauge struct {
22
+	pg *prometheus.GaugeVec
23
+}
24
+
25
+func (lg *labeledGauge) WithValues(labels ...string) Gauge {
26
+	return &gauge{pg: lg.pg.WithLabelValues(labels...)}
27
+}
28
+
29
+func (lg *labeledGauge) Describe(c chan<- *prometheus.Desc) {
30
+	lg.pg.Describe(c)
31
+}
32
+
33
+func (lg *labeledGauge) Collect(c chan<- prometheus.Metric) {
34
+	lg.pg.Collect(c)
35
+}
36
+
37
+type gauge struct {
38
+	pg prometheus.Gauge
39
+}
40
+
41
+func (g *gauge) Inc(vs ...float64) {
42
+	if len(vs) == 0 {
43
+		g.pg.Inc()
44
+	}
45
+
46
+	g.Add(sumFloat64(vs...))
47
+}
48
+
49
+func (g *gauge) Dec(vs ...float64) {
50
+	if len(vs) == 0 {
51
+		g.pg.Dec()
52
+	}
53
+
54
+	g.Add(-sumFloat64(vs...))
55
+}
56
+
57
+func (g *gauge) Add(v float64) {
58
+	g.pg.Add(v)
59
+}
60
+
61
+func (g *gauge) Set(v float64) {
62
+	g.pg.Set(v)
63
+}
64
+
65
+func (g *gauge) Describe(c chan<- *prometheus.Desc) {
66
+	g.pg.Describe(c)
67
+}
68
+
69
+func (g *gauge) Collect(c chan<- prometheus.Metric) {
70
+	g.pg.Collect(c)
71
+}
0 72
new file mode 100644
... ...
@@ -0,0 +1,13 @@
0
+package metrics
1
+
2
+import (
3
+	"net/http"
4
+
5
+	"github.com/prometheus/client_golang/prometheus"
6
+)
7
+
8
+// Handler returns the global http.Handler that provides the prometheus
9
+// metrics format on GET requests
10
+func Handler() http.Handler {
11
+	return prometheus.Handler()
12
+}
0 13
new file mode 100644
... ...
@@ -0,0 +1,10 @@
0
+package metrics
1
+
2
+func sumFloat64(vs ...float64) float64 {
3
+	var sum float64
4
+	for _, v := range vs {
5
+		sum += v
6
+	}
7
+
8
+	return sum
9
+}
0 10
new file mode 100644
... ...
@@ -0,0 +1,159 @@
0
+package metrics
1
+
2
+import (
3
+	"fmt"
4
+	"sync"
5
+
6
+	"github.com/prometheus/client_golang/prometheus"
7
+)
8
+
9
+type Labels map[string]string
10
+
11
+// NewNamespace returns a namespaces that is responsible for managing a collection of
12
+// metrics for a particual namespace and subsystem
13
+//
14
+// labels allows const labels to be added to all metrics created in this namespace
15
+// and are commonly used for data like application version and git commit
16
+func NewNamespace(name, subsystem string, labels Labels) *Namespace {
17
+	if labels == nil {
18
+		labels = make(map[string]string)
19
+	}
20
+	return &Namespace{
21
+		name:      name,
22
+		subsystem: subsystem,
23
+		labels:    labels,
24
+	}
25
+}
26
+
27
+// Namespace describes a set of metrics that share a namespace and subsystem.
28
+type Namespace struct {
29
+	name      string
30
+	subsystem string
31
+	labels    Labels
32
+	mu        sync.Mutex
33
+	metrics   []prometheus.Collector
34
+}
35
+
36
+// WithConstLabels returns a namespace with the provided set of labels merged
37
+// with the existing constant labels on the namespace.
38
+//
39
+//  Only metrics created with the returned namespace will get the new constant
40
+//  labels.  The returned namespace must be registered separately.
41
+func (n *Namespace) WithConstLabels(labels Labels) *Namespace {
42
+	ns := *n
43
+	ns.metrics = nil // blank this out
44
+	ns.labels = mergeLabels(ns.labels, labels)
45
+	return &ns
46
+}
47
+
48
+func (n *Namespace) NewCounter(name, help string) Counter {
49
+	c := &counter{pc: prometheus.NewCounter(n.newCounterOpts(name, help))}
50
+	n.addMetric(c)
51
+	return c
52
+}
53
+
54
+func (n *Namespace) NewLabeledCounter(name, help string, labels ...string) LabeledCounter {
55
+	c := &labeledCounter{pc: prometheus.NewCounterVec(n.newCounterOpts(name, help), labels)}
56
+	n.addMetric(c)
57
+	return c
58
+}
59
+
60
+func (n *Namespace) newCounterOpts(name, help string) prometheus.CounterOpts {
61
+	return prometheus.CounterOpts{
62
+		Namespace:   n.name,
63
+		Subsystem:   n.subsystem,
64
+		Name:        fmt.Sprintf("%s_%s", name, Total),
65
+		Help:        help,
66
+		ConstLabels: prometheus.Labels(n.labels),
67
+	}
68
+}
69
+
70
+func (n *Namespace) NewTimer(name, help string) Timer {
71
+	t := &timer{
72
+		m: prometheus.NewHistogram(n.newTimerOpts(name, help)),
73
+	}
74
+	n.addMetric(t)
75
+	return t
76
+}
77
+
78
+func (n *Namespace) NewLabeledTimer(name, help string, labels ...string) LabeledTimer {
79
+	t := &labeledTimer{
80
+		m: prometheus.NewHistogramVec(n.newTimerOpts(name, help), labels),
81
+	}
82
+	n.addMetric(t)
83
+	return t
84
+}
85
+
86
+func (n *Namespace) newTimerOpts(name, help string) prometheus.HistogramOpts {
87
+	return prometheus.HistogramOpts{
88
+		Namespace:   n.name,
89
+		Subsystem:   n.subsystem,
90
+		Name:        fmt.Sprintf("%s_%s", name, Seconds),
91
+		Help:        help,
92
+		ConstLabels: prometheus.Labels(n.labels),
93
+	}
94
+}
95
+
96
+func (n *Namespace) NewGauge(name, help string, unit Unit) Gauge {
97
+	g := &gauge{
98
+		pg: prometheus.NewGauge(n.newGaugeOpts(name, help, unit)),
99
+	}
100
+	n.addMetric(g)
101
+	return g
102
+}
103
+
104
+func (n *Namespace) NewLabeledGauge(name, help string, unit Unit, labels ...string) LabeledGauge {
105
+	g := &labeledGauge{
106
+		pg: prometheus.NewGaugeVec(n.newGaugeOpts(name, help, unit), labels),
107
+	}
108
+	n.addMetric(g)
109
+	return g
110
+}
111
+
112
+func (n *Namespace) newGaugeOpts(name, help string, unit Unit) prometheus.GaugeOpts {
113
+	return prometheus.GaugeOpts{
114
+		Namespace:   n.name,
115
+		Subsystem:   n.subsystem,
116
+		Name:        fmt.Sprintf("%s_%s", name, unit),
117
+		Help:        help,
118
+		ConstLabels: prometheus.Labels(n.labels),
119
+	}
120
+}
121
+
122
+func (n *Namespace) Describe(ch chan<- *prometheus.Desc) {
123
+	n.mu.Lock()
124
+	defer n.mu.Unlock()
125
+
126
+	for _, metric := range n.metrics {
127
+		metric.Describe(ch)
128
+	}
129
+}
130
+
131
+func (n *Namespace) Collect(ch chan<- prometheus.Metric) {
132
+	n.mu.Lock()
133
+	defer n.mu.Unlock()
134
+
135
+	for _, metric := range n.metrics {
136
+		metric.Collect(ch)
137
+	}
138
+}
139
+
140
+func (n *Namespace) addMetric(collector prometheus.Collector) {
141
+	n.mu.Lock()
142
+	n.metrics = append(n.metrics, collector)
143
+	n.mu.Unlock()
144
+}
145
+
146
+// mergeLabels merges two or more labels objects into a single map, favoring
147
+// the later labels.
148
+func mergeLabels(lbs ...Labels) Labels {
149
+	merged := make(Labels)
150
+
151
+	for _, target := range lbs {
152
+		for k, v := range target {
153
+			merged[k] = v
154
+		}
155
+	}
156
+
157
+	return merged
158
+}
0 159
new file mode 100644
... ...
@@ -0,0 +1,15 @@
0
+package metrics
1
+
2
+import "github.com/prometheus/client_golang/prometheus"
3
+
4
+// Register adds all the metrics in the provided namespace to the global
5
+// metrics registry
6
+func Register(n *Namespace) {
7
+	prometheus.MustRegister(n)
8
+}
9
+
10
+// Deregister removes all the metrics in the provided namespace from the
11
+// global metrics registry
12
+func Deregister(n *Namespace) {
13
+	prometheus.Unregister(n)
14
+}
0 15
new file mode 100644
... ...
@@ -0,0 +1,68 @@
0
+package metrics
1
+
2
+import (
3
+	"time"
4
+
5
+	"github.com/prometheus/client_golang/prometheus"
6
+)
7
+
8
+// StartTimer begins a timer observation at the callsite. When the target
9
+// operation is completed, the caller should call the return done func().
10
+func StartTimer(timer Timer) (done func()) {
11
+	start := time.Now()
12
+	return func() {
13
+		timer.Update(time.Since(start))
14
+	}
15
+}
16
+
17
+// Timer is a metric that allows collecting the duration of an action in seconds
18
+type Timer interface {
19
+	// Update records an observation, duration, and converts to the target
20
+	// units.
21
+	Update(duration time.Duration)
22
+
23
+	// UpdateSince will add the duration from the provided starting time to the
24
+	// timer's summary with the precisions that was used in creation of the timer
25
+	UpdateSince(time.Time)
26
+}
27
+
28
+// LabeledTimer is a timer that must have label values populated before use.
29
+type LabeledTimer interface {
30
+	WithValues(labels ...string) Timer
31
+}
32
+
33
+type labeledTimer struct {
34
+	m *prometheus.HistogramVec
35
+}
36
+
37
+func (lt *labeledTimer) WithValues(labels ...string) Timer {
38
+	return &timer{m: lt.m.WithLabelValues(labels...)}
39
+}
40
+
41
+func (lt *labeledTimer) Describe(c chan<- *prometheus.Desc) {
42
+	lt.m.Describe(c)
43
+}
44
+
45
+func (lt *labeledTimer) Collect(c chan<- prometheus.Metric) {
46
+	lt.m.Collect(c)
47
+}
48
+
49
+type timer struct {
50
+	m prometheus.Histogram
51
+}
52
+
53
+func (t *timer) Update(duration time.Duration) {
54
+	t.m.Observe(duration.Seconds())
55
+}
56
+
57
+func (t *timer) UpdateSince(since time.Time) {
58
+	t.m.Observe(time.Since(since).Seconds())
59
+}
60
+
61
+func (t *timer) Describe(c chan<- *prometheus.Desc) {
62
+	t.m.Describe(c)
63
+}
64
+
65
+func (t *timer) Collect(c chan<- prometheus.Metric) {
66
+	t.m.Collect(c)
67
+}
0 68
new file mode 100644
... ...
@@ -0,0 +1,12 @@
0
+package metrics
1
+
2
+// Unit represents the type or precision of a metric that is appended to
3
+// the metrics fully qualified name
4
+type Unit string
5
+
6
+const (
7
+	Nanoseconds Unit = "nanoseconds"
8
+	Seconds     Unit = "seconds"
9
+	Bytes       Unit = "bytes"
10
+	Total       Unit = "total"
11
+)