mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-06 19:51:39 +00:00
As it is an initial implementation, it only controls latency of the outgoing (egress) traffic. There is also a TODO to turn this plugin into something more serious. Also, at some point we may consider moving this plugin outside of "example" directory.
58 lines
983 B
Go
58 lines
983 B
Go
package main
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
type State int
|
|
|
|
const (
|
|
Created State = iota
|
|
Running
|
|
Stopped
|
|
Destroyed
|
|
)
|
|
|
|
type Container struct {
|
|
State State
|
|
PID int
|
|
}
|
|
|
|
type Store struct {
|
|
lock sync.Mutex
|
|
containers map[string]Container
|
|
}
|
|
|
|
func NewStore() *Store {
|
|
return &Store{
|
|
containers: map[string]Container{},
|
|
}
|
|
}
|
|
|
|
func (s *Store) Container(containerID string) (Container, bool) {
|
|
s.lock.Lock()
|
|
defer s.lock.Unlock()
|
|
container, found := s.containers[containerID]
|
|
return container, found
|
|
}
|
|
|
|
func (s *Store) SetContainer(containerID string, container Container) {
|
|
s.lock.Lock()
|
|
defer s.lock.Unlock()
|
|
s.containers[containerID] = container
|
|
}
|
|
|
|
func (s *Store) DeleteContainer(containerID string) {
|
|
s.lock.Lock()
|
|
defer s.lock.Unlock()
|
|
delete(s.containers, containerID)
|
|
}
|
|
|
|
func (s *Store) ForEach(callback func(ID string, c Container)) {
|
|
s.lock.Lock()
|
|
defer s.lock.Unlock()
|
|
for containerID, container := range s.containers {
|
|
callback(containerID, container)
|
|
}
|
|
}
|