Skip to content

Commit 29b0740

Browse files
author
Xuewei Zhang
committed
Refactor systemstatsmonitor/metric_helper.go into a metrics package
1 parent 146dfd7 commit 29b0740

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

pkg/systemstatsmonitor/disk_collector.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ import (
2727
"go.opencensus.io/stats"
2828
"go.opencensus.io/stats/view"
2929
"go.opencensus.io/tag"
30+
3031
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
32+
"k8s.io/node-problem-detector/pkg/util/metrics"
3133
)
3234

3335
type diskCollector struct {
@@ -46,21 +48,21 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
4648
dc := diskCollector{config: diskConfig}
4749
dc.keyDevice, _ = tag.NewKey("device")
4850

49-
dc.mIOTime = newInt64Metric(
51+
dc.mIOTime = metrics.NewInt64Metric(
5052
diskConfig.MetricsConfigs["disk/io_time"].DisplayName,
5153
"The IO time spent on the disk",
5254
"second",
5355
view.LastValue(),
5456
[]tag.Key{dc.keyDevice})
5557

56-
dc.mWeightedIO = newInt64Metric(
58+
dc.mWeightedIO = metrics.NewInt64Metric(
5759
diskConfig.MetricsConfigs["disk/weighted_io"].DisplayName,
5860
"The weighted IO on the disk",
5961
"second",
6062
view.LastValue(),
6163
[]tag.Key{dc.keyDevice})
6264

63-
dc.mAvgQueueLen = newFloat64Metric(
65+
dc.mAvgQueueLen = metrics.NewFloat64Metric(
6466
diskConfig.MetricsConfigs["disk/avg_queue_len"].DisplayName,
6567
"The average queue length on the disk",
6668
"second",

pkg/systemstatsmonitor/system_stats_monitor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/golang/glog"
25+
2526
"k8s.io/node-problem-detector/pkg/problemdaemon"
2627
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
2728
"k8s.io/node-problem-detector/pkg/types"

pkg/systemstatsmonitor/metric_helper.go renamed to pkg/util/metrics/helpers.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
17-
package systemstatsmonitor
16+
package metrics
1817

1918
import (
2019
"go.opencensus.io/stats"
2120
"go.opencensus.io/stats/view"
2221
"go.opencensus.io/tag"
2322
)
2423

25-
// newInt64Metric create a stats.Int64 metrics, returns nil when name is empty.
26-
func newInt64Metric(name string, description string, unit string, aggregation *view.Aggregation, tagKeys []tag.Key) *stats.Int64Measure {
24+
// NewInt64Metric create a stats.Int64 metrics, returns nil when name is empty.
25+
func NewInt64Metric(name string, description string, unit string, aggregation *view.Aggregation, tagKeys []tag.Key) *stats.Int64Measure {
2726
if name == "" {
2827
return nil
2928
}
@@ -39,8 +38,8 @@ func newInt64Metric(name string, description string, unit string, aggregation *v
3938
return measure
4039
}
4140

42-
// newFloat64Metric create a stats.Float64 metrics, returns nil when name is empty.
43-
func newFloat64Metric(name string, description string, unit string, aggregation *view.Aggregation, tagKeys []tag.Key) *stats.Float64Measure {
41+
// NewFloat64Metric create a stats.Float64 metrics, returns nil when name is empty.
42+
func NewFloat64Metric(name string, description string, unit string, aggregation *view.Aggregation, tagKeys []tag.Key) *stats.Float64Measure {
4443
if name == "" {
4544
return nil
4645
}

0 commit comments

Comments
 (0)