Include custom metrics in ContainerStats structure

This commit is contained in:
anushree-n 2015-07-13 16:13:56 -07:00
parent 44f86044e1
commit 4f83aae835
7 changed files with 18 additions and 15 deletions

View File

@ -19,7 +19,7 @@ import (
"strings"
"time"
"github.com/google/cadvisor/info/v2"
"github.com/google/cadvisor/info/v1"
)
type collectorManager struct {
@ -48,12 +48,12 @@ func (cm *collectorManager) RegisterCollector(collector Collector) error {
return nil
}
func (cm *collectorManager) Collect() (time.Time, []v2.Metric, error) {
func (cm *collectorManager) Collect() (time.Time, []v1.Metric, error) {
var errors []error
// Collect from all collectors that are ready.
var next time.Time
var metrics []v2.Metric
var metrics []v1.Metric
for _, c := range cm.collectors {
if c.nextCollectionTime.Before(time.Now()) {
nextCollection, newMetrics, err := c.collector.Collect()

View File

@ -18,7 +18,7 @@ import (
"testing"
"time"
"github.com/google/cadvisor/info/v2"
"github.com/google/cadvisor/info/v1"
"github.com/stretchr/testify/assert"
)
@ -28,9 +28,9 @@ type fakeCollector struct {
collectedFrom int
}
func (fc *fakeCollector) Collect() (time.Time, []v2.Metric, error) {
func (fc *fakeCollector) Collect() (time.Time, []v1.Metric, error) {
fc.collectedFrom++
return fc.nextCollectionTime, []v2.Metric{}, fc.err
return fc.nextCollectionTime, []v1.Metric{}, fc.err
}
func (fc *fakeCollector) Name() string {

View File

@ -17,7 +17,7 @@ package collector
import (
"time"
"github.com/google/cadvisor/info/v2"
"github.com/google/cadvisor/info/v1"
)
type FakeCollectorManager struct {
@ -27,7 +27,7 @@ func (fkm *FakeCollectorManager) RegisterCollector(collector Collector) error {
return nil
}
func (fkm *FakeCollectorManager) Collect() (time.Time, []v2.Metric, error) {
func (fkm *FakeCollectorManager) Collect() (time.Time, []v1.Metric, error) {
var zero time.Time
return zero, []v2.Metric{}, nil
return zero, []v1.Metric{}, nil
}

View File

@ -19,7 +19,7 @@ import (
"io/ioutil"
"time"
"github.com/google/cadvisor/info/v2"
"github.com/google/cadvisor/info/v1"
)
type GenericCollector struct {
@ -56,7 +56,7 @@ func (collector *GenericCollector) Name() string {
}
//Returns collected metrics and the next collection time of the collector
func (collector *GenericCollector) Collect() (time.Time, []v2.Metric, error) {
func (collector *GenericCollector) Collect() (time.Time, []v1.Metric, error) {
//TO BE IMPLEMENTED
return time.Now(), nil, nil
}

View File

@ -15,7 +15,7 @@
package collector
import (
"github.com/google/cadvisor/info/v2"
"github.com/google/cadvisor/info/v1"
"time"
)
@ -27,7 +27,7 @@ type Collector interface {
// Returns the next time this collector should be collected from.
// Next collection time is always returned, even when an error occurs.
// A collection time of zero means no more collection.
Collect() (time.Time, []v2.Metric, error)
Collect() (time.Time, []v1.Metric, error)
// Name of this collector.
Name() string
@ -42,5 +42,5 @@ type CollectorManager interface {
// at which a collector will be ready to collect from.
// Next collection time is always returned, even when an error occurs.
// A collection time of zero means no more collection.
Collect() (time.Time, []v2.Metric, error)
Collect() (time.Time, []v1.Metric, error)
}

View File

@ -419,6 +419,9 @@ type ContainerStats struct {
// Task load stats
TaskStats LoadStats `json:"task_stats,omitempty"`
//Custom metrics from all collectors
CustomMetrics []Metric `json:"custom_metrics,omitempty"`
}
func timeEq(t1, t2 time.Time, tolerance time.Duration) bool {

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package v2
package v1
import (
"time"