New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add prometheus metrics output to docker #25820
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"net" | ||
"net/http" | ||
|
||
"github.com/Sirupsen/logrus" | ||
metrics "github.com/docker/go-metrics" | ||
) | ||
|
||
func startMetricsServer(addr string) error { | ||
if err := allocateDaemonPort(addr); err != nil { | ||
return err | ||
} | ||
l, err := net.Listen("tcp", addr) | ||
if err != nil { | ||
return err | ||
} | ||
mux := http.NewServeMux() | ||
mux.Handle("/metrics", metrics.Handler()) | ||
go func() { | ||
if err := http.Serve(l, mux); err != nil { | ||
logrus.Errorf("serve metrics api: %s", err) | ||
} | ||
}() | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
package daemon | ||
|
||
import "github.com/docker/docker/pkg/archive" | ||
import ( | ||
"time" | ||
|
||
"github.com/docker/docker/pkg/archive" | ||
) | ||
|
||
// ContainerChanges returns a list of container fs changes | ||
func (daemon *Daemon) ContainerChanges(name string) ([]archive.Change, error) { | ||
start := time.Now() | ||
container, err := daemon.GetContainer(name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
container.Lock() | ||
defer container.Unlock() | ||
return container.RWLayer.Changes() | ||
c, err := container.RWLayer.Changes() | ||
if err != nil { | ||
return nil, err | ||
} | ||
containerActions.WithValues("changes").UpdateSince(start) | ||
return c, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package events | ||
|
||
import "github.com/docker/go-metrics" | ||
|
||
var ( | ||
eventsCounter metrics.Counter | ||
eventSubscribers metrics.Gauge | ||
) | ||
|
||
func init() { | ||
ns := metrics.NewNamespace("engine", "daemon", nil) | ||
eventsCounter = ns.NewCounter("events", "The number of events logged") | ||
eventSubscribers = ns.NewGauge("events_subscribers", "The number of current subscribers to events", metrics.Total) | ||
metrics.Register(ns) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a separate file for metrics is a smell, metrics should be treated like logging and live in the same file as what they're instrumenting.
Similarly that the same metric is being updated in multiple files is a smell, indicating that you're not instrumenting at the right place in your code. Either you shouldn't be using a label, or you should move the instrumentation up the call stack so each metric only lives in one file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the inferred pungency here?
Are you saying that metrics should be representative of the call tree? How do we reconcile implementation versus the exported API that metrics invariably become?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm saying that metrics should usually be right beside what they're instrumenting, and that a given metric should almost always live in exactly one file.
For this particular file I think it should be merged into events.go. This saves someone trying to understand the code having to jump around files.
My stance is based on years of trying to debug code that looked just like this. It gets really frustrating when you're already trying to understand a bug code spread across 10s functions in 10s files, to then have to open up another set of files to find out what the metrics available are and another set of files again to see which confusing behaviour this team's metrics wrapper has.
I'd expect metrics to change over time as changes are made to the code. A handful are likely to end up highly depended on, so some future compromise might be required if the choice is made to make them an official API.
For Prometheus itself our stability guarantees don't include the metrics, as that'd be too constraining and effectively prevent significant development as any major internal change would likely become a breaking change to metrics. Given Docker is under rapid development, you may wish to take a similar stance.