From 29b0740f4c7ac1b3ef456f5cddb0092cc6f9af45 Mon Sep 17 00:00:00 2001 From: Xuewei Zhang Date: Thu, 27 Jun 2019 11:27:05 -0700 Subject: [PATCH] Refactor systemstatsmonitor/metric_helper.go into a metrics package --- pkg/systemstatsmonitor/disk_collector.go | 8 +++++--- pkg/systemstatsmonitor/system_stats_monitor.go | 1 + .../metric_helper.go => util/metrics/helpers.go} | 11 +++++------ 3 files changed, 11 insertions(+), 9 deletions(-) rename pkg/{systemstatsmonitor/metric_helper.go => util/metrics/helpers.go} (83%) diff --git a/pkg/systemstatsmonitor/disk_collector.go b/pkg/systemstatsmonitor/disk_collector.go index 5297ad4b..fce560d7 100644 --- a/pkg/systemstatsmonitor/disk_collector.go +++ b/pkg/systemstatsmonitor/disk_collector.go @@ -27,7 +27,9 @@ import ( "go.opencensus.io/stats" "go.opencensus.io/stats/view" "go.opencensus.io/tag" + ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types" + "k8s.io/node-problem-detector/pkg/util/metrics" ) type diskCollector struct { @@ -46,21 +48,21 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector dc := diskCollector{config: diskConfig} dc.keyDevice, _ = tag.NewKey("device") - dc.mIOTime = newInt64Metric( + dc.mIOTime = metrics.NewInt64Metric( diskConfig.MetricsConfigs["disk/io_time"].DisplayName, "The IO time spent on the disk", "second", view.LastValue(), []tag.Key{dc.keyDevice}) - dc.mWeightedIO = newInt64Metric( + dc.mWeightedIO = metrics.NewInt64Metric( diskConfig.MetricsConfigs["disk/weighted_io"].DisplayName, "The weighted IO on the disk", "second", view.LastValue(), []tag.Key{dc.keyDevice}) - dc.mAvgQueueLen = newFloat64Metric( + dc.mAvgQueueLen = metrics.NewFloat64Metric( diskConfig.MetricsConfigs["disk/avg_queue_len"].DisplayName, "The average queue length on the disk", "second", diff --git a/pkg/systemstatsmonitor/system_stats_monitor.go b/pkg/systemstatsmonitor/system_stats_monitor.go index 03a66e54..c14d2b8e 100644 --- a/pkg/systemstatsmonitor/system_stats_monitor.go +++ b/pkg/systemstatsmonitor/system_stats_monitor.go @@ -22,6 +22,7 @@ import ( "time" "github.com/golang/glog" + "k8s.io/node-problem-detector/pkg/problemdaemon" ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types" "k8s.io/node-problem-detector/pkg/types" diff --git a/pkg/systemstatsmonitor/metric_helper.go b/pkg/util/metrics/helpers.go similarity index 83% rename from pkg/systemstatsmonitor/metric_helper.go rename to pkg/util/metrics/helpers.go index fb82b230..7c3eeecb 100644 --- a/pkg/systemstatsmonitor/metric_helper.go +++ b/pkg/util/metrics/helpers.go @@ -13,8 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ - -package systemstatsmonitor +package metrics import ( "go.opencensus.io/stats" @@ -22,8 +21,8 @@ import ( "go.opencensus.io/tag" ) -// newInt64Metric create a stats.Int64 metrics, returns nil when name is empty. -func newInt64Metric(name string, description string, unit string, aggregation *view.Aggregation, tagKeys []tag.Key) *stats.Int64Measure { +// NewInt64Metric create a stats.Int64 metrics, returns nil when name is empty. +func NewInt64Metric(name string, description string, unit string, aggregation *view.Aggregation, tagKeys []tag.Key) *stats.Int64Measure { if name == "" { return nil } @@ -39,8 +38,8 @@ func newInt64Metric(name string, description string, unit string, aggregation *v return measure } -// newFloat64Metric create a stats.Float64 metrics, returns nil when name is empty. -func newFloat64Metric(name string, description string, unit string, aggregation *view.Aggregation, tagKeys []tag.Key) *stats.Float64Measure { +// NewFloat64Metric create a stats.Float64 metrics, returns nil when name is empty. +func NewFloat64Metric(name string, description string, unit string, aggregation *view.Aggregation, tagKeys []tag.Key) *stats.Float64Measure { if name == "" { return nil }