Skip to content

Commit

Permalink
Include custom metrics in ContainerStats structure
Browse files Browse the repository at this point in the history
  • Loading branch information
anushree-n committed Jul 14, 2015
1 parent 44f8604 commit 4f83aae
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions collector/collector_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"strings"
"time"

"github.com/google/cadvisor/info/v2"
"github.com/google/cadvisor/info/v1"
)

type collectorManager struct {
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions collector/collector_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"testing"
"time"

"github.com/google/cadvisor/info/v2"
"github.com/google/cadvisor/info/v1"
"github.com/stretchr/testify/assert"
)

Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions collector/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package collector
import (
"time"

"github.com/google/cadvisor/info/v2"
"github.com/google/cadvisor/info/v1"
)

type FakeCollectorManager struct {
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions collector/generic_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"io/ioutil"
"time"

"github.com/google/cadvisor/info/v2"
"github.com/google/cadvisor/info/v1"
)

type GenericCollector struct {
Expand Down Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions collector/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package collector

import (
"github.com/google/cadvisor/info/v2"
"github.com/google/cadvisor/info/v1"
"time"
)

Expand All @@ -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
Expand All @@ -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)
}
3 changes: 3 additions & 0 deletions info/v1/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion info/v2/metric.go → info/v1/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package v2
package v1

import (
"time"
Expand Down

0 comments on commit 4f83aae

Please sign in to comment.