Skip to content

Commit

Permalink
metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed May 1, 2017
1 parent 5aa6e18 commit 4d6a012
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/alloc_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

metrics "github.com/armon/go-metrics"
"github.com/boltdb/bolt"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/nomad/client/allocdir"
Expand Down Expand Up @@ -539,6 +540,7 @@ func (r *AllocRunner) appendTaskEvent(state *structs.TaskState, event *structs.T

// Run is a long running goroutine used to manage an allocation
func (r *AllocRunner) Run() {
start := time.Now()
defer close(r.waitCh)
go r.dirtySyncState()

Expand Down Expand Up @@ -604,6 +606,8 @@ func (r *AllocRunner) Run() {
}
r.taskLock.Unlock()

metrics.MeasureSince([]string{"client", "alloc_runner", "run_delay"}, start)

// taskDestroyEvent contains an event that caused the destroyment of a task
// in the allocation.
var taskDestroyEvent *structs.TaskEvent
Expand Down
2 changes: 2 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,8 @@ func (c *Client) watchNodeUpdates() {

// runAllocs is invoked when we get an updated set of allocations
func (c *Client) runAllocs(update *allocUpdates) {
defer metrics.MeasureSince([]string{"client", "client", "runAllocs"}, time.Now())

// Get the existing allocs
c.allocLock.RLock()
exist := make([]*structs.Allocation, 0, len(c.allocs))
Expand Down
5 changes: 5 additions & 0 deletions client/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ func (r *TaskRunner) updatedTokenHandler() {

// prestart handles life-cycle tasks that occur before the task has started.
func (r *TaskRunner) prestart(resultCh chan bool) {
defer metrics.MeasureSince([]string{"client", "task_runner", "prestart"}, time.Now())
if r.task.Vault != nil {
// Wait for the token
r.logger.Printf("[DEBUG] client: waiting for Vault token for task %v in alloc %q", r.task.Name, r.alloc.ID)
Expand Down Expand Up @@ -940,6 +941,7 @@ func (r *TaskRunner) postrun() {
// run is the main run loop that handles starting the application, destroying
// it, restarts and signals.
func (r *TaskRunner) run() {
start := time.Now()
// Predeclare things so we can jump to the RESTART
var stopCollection chan struct{}
var handleWaitCh chan *dstructs.WaitResult
Expand Down Expand Up @@ -978,6 +980,7 @@ func (r *TaskRunner) run() {
handleEmpty := r.handle == nil
r.handleLock.Unlock()
if handleEmpty {
metrics.MeasureSince([]string{"client", "task_runner", "run_delay"}, start)
startErr := r.startTask()
r.restartTracker.SetStartError(startErr)
if startErr != nil {
Expand Down Expand Up @@ -1255,6 +1258,7 @@ func (r *TaskRunner) killTask(killingEvent *structs.TaskEvent) {

// startTask creates the driver, task dir, and starts the task.
func (r *TaskRunner) startTask() error {
defer metrics.MeasureSince([]string{"client", "task_runner", "startTask"}, time.Now())
// Create a driver
drv, err := r.createDriver()
if err != nil {
Expand Down Expand Up @@ -1342,6 +1346,7 @@ func interpolateServices(taskEnv *env.TaskEnvironment, task *structs.Task) {
// buildTaskDir creates the task directory before driver.Prestart. It is safe
// to call multiple times as its state is persisted.
func (r *TaskRunner) buildTaskDir(fsi cstructs.FSIsolation) error {
defer metrics.MeasureSince([]string{"client", "task_runner", "buildTaskDir"}, time.Now())
r.persistLock.Lock()
built := r.taskDirBuilt
r.persistLock.Unlock()
Expand Down

0 comments on commit 4d6a012

Please sign in to comment.