commit
fba5f74e87
@ -44,7 +44,9 @@ func main() {
|
|||||||
NumSamples: *argSampleSize,
|
NumSamples: *argSampleSize,
|
||||||
ResetPeriod: *argResetPeriod,
|
ResetPeriod: *argResetPeriod,
|
||||||
})
|
})
|
||||||
containerManager, err := manager.New()
|
|
||||||
|
// TODO(monnand): Add stats writer for manager
|
||||||
|
containerManager, err := manager.New(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to create a Container Manager: %s", err)
|
log.Fatalf("Failed to create a Container Manager: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/google/cadvisor/container"
|
"github.com/google/cadvisor/container"
|
||||||
"github.com/google/cadvisor/info"
|
"github.com/google/cadvisor/info"
|
||||||
|
"github.com/google/cadvisor/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
var historyDuration = flag.Int("history_duration", 60, "number of seconds of container history to keep")
|
var historyDuration = flag.Int("history_duration", 60, "number of seconds of container history to keep")
|
||||||
@ -45,6 +46,7 @@ type containerInfo struct {
|
|||||||
type containerData struct {
|
type containerData struct {
|
||||||
handler container.ContainerHandler
|
handler container.ContainerHandler
|
||||||
info containerInfo
|
info containerInfo
|
||||||
|
storageDriver storage.StorageDriver
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
|
|
||||||
// Tells the container to stop.
|
// Tells the container to stop.
|
||||||
@ -84,7 +86,7 @@ func (c *containerData) GetInfo() (*containerInfo, error) {
|
|||||||
return &ret, nil
|
return &ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContainerData(containerName string) (*containerData, error) {
|
func NewContainerData(containerName string, driver storage.StorageDriver) (*containerData, error) {
|
||||||
cont := &containerData{}
|
cont := &containerData{}
|
||||||
handler, err := container.NewContainerHandler(containerName)
|
handler, err := container.NewContainerHandler(containerName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -98,6 +100,7 @@ func NewContainerData(containerName string) (*containerData, error) {
|
|||||||
cont.info.Name = ref.Name
|
cont.info.Name = ref.Name
|
||||||
cont.info.Aliases = ref.Aliases
|
cont.info.Aliases = ref.Aliases
|
||||||
cont.info.Stats = list.New()
|
cont.info.Stats = list.New()
|
||||||
|
cont.storageDriver = driver
|
||||||
cont.stop = make(chan bool, 1)
|
cont.stop = make(chan bool, 1)
|
||||||
|
|
||||||
return cont, nil
|
return cont, nil
|
||||||
@ -151,6 +154,16 @@ func (c *containerData) updateStats() error {
|
|||||||
if stats == nil {
|
if stats == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if c.storageDriver != nil {
|
||||||
|
ref, err := c.handler.ContainerReference()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = c.storageDriver.AddStats(ref, stats)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
summary, err := c.handler.StatsSummary()
|
summary, err := c.handler.StatsSummary()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/google/cadvisor/container"
|
"github.com/google/cadvisor/container"
|
||||||
"github.com/google/cadvisor/info"
|
"github.com/google/cadvisor/info"
|
||||||
|
"github.com/google/cadvisor/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Manager interface {
|
type Manager interface {
|
||||||
@ -38,7 +39,7 @@ type Manager interface {
|
|||||||
GetVersionInfo() (*info.VersionInfo, error)
|
GetVersionInfo() (*info.VersionInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() (Manager, error) {
|
func New(driver storage.StorageDriver) (Manager, error) {
|
||||||
newManager := &manager{}
|
newManager := &manager{}
|
||||||
newManager.containers = make(map[string]*containerData)
|
newManager.containers = make(map[string]*containerData)
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ func New() (Manager, error) {
|
|||||||
}
|
}
|
||||||
newManager.versionInfo = *versionInfo
|
newManager.versionInfo = *versionInfo
|
||||||
log.Printf("Version: %+v", newManager.versionInfo)
|
log.Printf("Version: %+v", newManager.versionInfo)
|
||||||
|
newManager.storageDriver = driver
|
||||||
|
|
||||||
return newManager, nil
|
return newManager, nil
|
||||||
}
|
}
|
||||||
@ -62,6 +64,7 @@ func New() (Manager, error) {
|
|||||||
type manager struct {
|
type manager struct {
|
||||||
containers map[string]*containerData
|
containers map[string]*containerData
|
||||||
containersLock sync.RWMutex
|
containersLock sync.RWMutex
|
||||||
|
storageDriver storage.StorageDriver
|
||||||
machineInfo info.MachineInfo
|
machineInfo info.MachineInfo
|
||||||
versionInfo info.VersionInfo
|
versionInfo info.VersionInfo
|
||||||
}
|
}
|
||||||
@ -160,7 +163,7 @@ func (m *manager) GetVersionInfo() (*info.VersionInfo, error) {
|
|||||||
|
|
||||||
// Create a container. This expects to only be called from the global manager thread.
|
// Create a container. This expects to only be called from the global manager thread.
|
||||||
func (m *manager) createContainer(containerName string) (*containerData, error) {
|
func (m *manager) createContainer(containerName string) (*containerData, error) {
|
||||||
cont, err := NewContainerData(containerName)
|
cont, err := NewContainerData(containerName, m.storageDriver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
21
storage/storage.go
Normal file
21
storage/storage.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2014 Google Inc. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import "github.com/google/cadvisor/info"
|
||||||
|
|
||||||
|
type StorageDriver interface {
|
||||||
|
AddStats(ref info.ContainerReference, stats *info.ContainerStats) error
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user