| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package tsmon | 5 package tsmon |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "golang.org/x/net/context" | 8 "golang.org/x/net/context" |
| 9 | 9 |
| 10 "github.com/luci/gae/service/module" | 10 "github.com/luci/gae/service/module" |
| 11 "github.com/luci/luci-go/common/logging" | 11 "github.com/luci/luci-go/common/logging" |
| 12 "github.com/luci/luci-go/common/tsmon" | 12 "github.com/luci/luci-go/common/tsmon" |
| 13 "github.com/luci/luci-go/common/tsmon/metric" | 13 "github.com/luci/luci-go/common/tsmon/metric" |
| 14 "github.com/luci/luci-go/common/tsmon/runtimestats" | 14 "github.com/luci/luci-go/common/tsmon/runtimestats" |
| 15 "github.com/luci/luci-go/common/tsmon/versions" |
| 15 ) | 16 ) |
| 16 | 17 |
| 17 var ( | 18 var ( |
| 18 defaultVersion = metric.NewCallbackString( | 19 defaultVersion = metric.NewCallbackString( |
| 19 "appengine/default_version", | 20 "appengine/default_version", |
| 20 "Name of the version currently marked as default.", | 21 "Name of the version currently marked as default.", |
| 21 nil) | 22 nil) |
| 22 ) | 23 ) |
| 23 | 24 |
| 24 // collectGlobalMetrics populates service-global metrics. | 25 // collectGlobalMetrics populates service-global metrics. |
| 25 // | 26 // |
| 26 // Called by tsmon from inside /housekeeping cron handler. Metrics reported must | 27 // Called by tsmon from inside /housekeeping cron handler. Metrics reported must |
| 27 // not depend on the state of the particular process that happens to report | 28 // not depend on the state of the particular process that happens to report |
| 28 // them. | 29 // them. |
| 29 func collectGlobalMetrics(c context.Context) { | 30 func collectGlobalMetrics(c context.Context) { |
| 30 version, err := module.DefaultVersion(c, "") | 31 version, err := module.DefaultVersion(c, "") |
| 31 if err != nil { | 32 if err != nil { |
| 32 logging.Errorf(c, "Error getting default appengine version: %s",
err) | 33 logging.Errorf(c, "Error getting default appengine version: %s",
err) |
| 33 defaultVersion.Set(c, "(unknown)") | 34 defaultVersion.Set(c, "(unknown)") |
| 34 } else { | 35 } else { |
| 35 defaultVersion.Set(c, version) | 36 defaultVersion.Set(c, version) |
| 36 } | 37 } |
| 37 } | 38 } |
| 38 | 39 |
| 39 // collectProcessMetrics populates per-process metrics. | 40 // collectProcessMetrics populates per-process metrics. |
| 40 // | 41 // |
| 41 // It is called by each individual process right before flushing the metrics. | 42 // It is called by each individual process right before flushing the metrics. |
| 42 func collectProcessMetrics(c context.Context, s *tsmonSettings) { | 43 func collectProcessMetrics(c context.Context, s *tsmonSettings) { |
| 44 versions.Report(c) |
| 43 if s.ReportRuntimeStats { | 45 if s.ReportRuntimeStats { |
| 44 runtimestats.Report(c) | 46 runtimestats.Report(c) |
| 45 } | 47 } |
| 46 } | 48 } |
| 47 | 49 |
| 48 func init() { | 50 func init() { |
| 49 tsmon.RegisterGlobalCallback(collectGlobalMetrics, defaultVersion) | 51 tsmon.RegisterGlobalCallback(collectGlobalMetrics, defaultVersion) |
| 50 } | 52 } |
| OLD | NEW |