Merge pull request #816 from anushree-n/cacheAlternative

Include custom metrics in ContainerStats structure
This commit is contained in:
Victor Marmol 2015-07-14 08:13:27 -07:00
commit d85d832a8a
7 changed files with 18 additions and 15 deletions

View File

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

View File

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

View File

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

View File

@ -19,7 +19,7 @@ import (
"io/ioutil" "io/ioutil"
"time" "time"
"github.com/google/cadvisor/info/v2" "github.com/google/cadvisor/info/v1"
) )
type GenericCollector struct { type GenericCollector struct {
@ -56,7 +56,7 @@ func (collector *GenericCollector) Name() string {
} }
//Returns collected metrics and the next collection time of the collector //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 //TO BE IMPLEMENTED
return time.Now(), nil, nil return time.Now(), nil, nil
} }

View File

@ -15,7 +15,7 @@
package collector package collector
import ( import (
"github.com/google/cadvisor/info/v2" "github.com/google/cadvisor/info/v1"
"time" "time"
) )
@ -27,7 +27,7 @@ type Collector interface {
// Returns the next time this collector should be collected from. // Returns the next time this collector should be collected from.
// Next collection time is always returned, even when an error occurs. // Next collection time is always returned, even when an error occurs.
// A collection time of zero means no more collection. // 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 of this collector.
Name() string Name() string
@ -42,5 +42,5 @@ type CollectorManager interface {
// at which a collector will be ready to collect from. // at which a collector will be ready to collect from.
// Next collection time is always returned, even when an error occurs. // Next collection time is always returned, even when an error occurs.
// A collection time of zero means no more collection. // 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 // Task load stats
TaskStats LoadStats `json:"task_stats,omitempty"` 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 { 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 // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package v2 package v1
import ( import (
"time" "time"