-
Notifications
You must be signed in to change notification settings - Fork 1
/
base_monitor.go
76 lines (61 loc) · 2.6 KB
/
base_monitor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2023 Arista Networks, Inc.
// Use of this source code is governed by the Apache License 2.0
// that can be found in the COPYING file.
package libmain
import (
log "github.com/sirupsen/logrus"
)
// BaseLogger only logs std info or error.
type BaseLogger struct {
logger *log.Entry
level log.Level
}
// Infof logs and records info message.
func (l *BaseLogger) Infof(format string, args ...interface{}) {
l.logger.Infof(format, args...)
}
// Errorf logs internal error message.
func (l *BaseLogger) Errorf(format string, args ...interface{}) {
l.logger.Errorf(format, args...)
}
// Debugf logs message only when in debug level.
func (l *BaseLogger) Debugf(format string, args ...interface{}) {
l.logger.Debugf(format, args...)
}
// Tracef logs message only when in trace level.
func (l *BaseLogger) Tracef(format string, args ...interface{}) {
l.logger.Tracef(format, args...)
}
// BaseMetricCollector provides a base implementation for metric management.
type BaseMetricCollector struct{}
// SetMetricString sets the value of the metric with the specified name to the provided
// string value. This method returns nil as there is no default implementation.
func (m *BaseMetricCollector) SetMetricString(name string, value string) error { return nil }
// SetMetricFloat sets the value of the metric with the specified name to the provided
// float64 value. This method returns nil as there is no default implementation.
func (m *BaseMetricCollector) SetMetricFloat(name string, value float64) error { return nil }
// SetMetricInt sets the value of the metric with the specified name to the provided int64 value.
// This method returns nil as there is no default implementation.
func (m *BaseMetricCollector) SetMetricInt(name string, value int64) error { return nil }
// IncMetricInt increases the metric value by the specified int64 amount.
// This method returns nil as there is no default implementation.
func (m *BaseMetricCollector) IncMetricInt(name string, value int64) error { return nil }
// CreateMetric creates a new metric with the specified name, unit, and description.
func (m *BaseMetricCollector) CreateMetric(name string, valueUnit string,
description string) error {
return nil
}
// BaseMonitor is a not fully functional monitor
// for device creation in cmd/Collector.
type BaseMonitor struct {
BaseLogger
BaseMetricCollector
}
// NewBaseMonitor returns a new noop monitor for the collector.
func NewBaseMonitor(logger *log.Entry) *BaseMonitor {
nm := &BaseMonitor{
BaseLogger: BaseLogger{logger: logger, level: log.InfoLevel},
BaseMetricCollector: BaseMetricCollector{},
}
return nm
}