stats processor
This commit is contained in:
parent
750b5b464e
commit
103e83fd86
@ -6,6 +6,7 @@ before_script:
|
|||||||
- go get github.com/kr/pretty
|
- go get github.com/kr/pretty
|
||||||
script:
|
script:
|
||||||
- go test -v -race github.com/google/cadvisor/container
|
- go test -v -race github.com/google/cadvisor/container
|
||||||
|
- go test -v -race github.com/google/cadvisor/storage
|
||||||
- go test -v github.com/google/cadvisor/info
|
- go test -v github.com/google/cadvisor/info
|
||||||
- go test -v github.com/google/cadvisor/client
|
- go test -v github.com/google/cadvisor/client
|
||||||
- go test -v github.com/google/cadvisor/sampling
|
- go test -v github.com/google/cadvisor/sampling
|
||||||
|
61
manager/statsproc.go
Normal file
61
manager/statsproc.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// 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 manager
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/google/cadvisor/info"
|
||||||
|
"github.com/google/cadvisor/storage"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ContainerStats struct {
|
||||||
|
ContainerReference info.ContainerReference
|
||||||
|
Stats *info.ContainerStats
|
||||||
|
ResChan chan<- error
|
||||||
|
}
|
||||||
|
|
||||||
|
type ContainerStatsProcessor interface {
|
||||||
|
StartStatsProcessors(numProcs int) (chan<- *ContainerStats, error)
|
||||||
|
StopAllProcessors()
|
||||||
|
}
|
||||||
|
|
||||||
|
type containerStatsWriter struct {
|
||||||
|
config *storage.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *containerStatsWriter) StartStatsProcessors(numProcs int) (chan<- *ContainerStats, error) {
|
||||||
|
ch := make(chan *ContainerStats)
|
||||||
|
statsWriter, err := storage.NewContainerStatsWriter(self.config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for i := 0; i < numProcs; i++ {
|
||||||
|
go self.process(statsWriter, ch)
|
||||||
|
}
|
||||||
|
return ch, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *containerStatsWriter) process(statsWriter storage.ContainerStatsWriter, ch <-chan *ContainerStats) {
|
||||||
|
for stats := range ch {
|
||||||
|
err := statsWriter.Write(stats.ContainerReference, stats.Stats)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("unable to write stats: %v", err)
|
||||||
|
}
|
||||||
|
if stats.ResChan != nil {
|
||||||
|
stats.ResChan <- err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user