mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
add aggression multiplier to mock collector
This commit is contained in:
@@ -13,11 +13,13 @@ type Mock struct {
|
|||||||
stream chan Metrics
|
stream chan Metrics
|
||||||
done bool
|
done bool
|
||||||
running bool
|
running bool
|
||||||
|
aggression int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMock() *Mock {
|
func NewMock(a int64) *Mock {
|
||||||
c := &Mock{
|
c := &Mock{
|
||||||
Metrics: Metrics{},
|
Metrics: Metrics{},
|
||||||
|
aggression: a,
|
||||||
}
|
}
|
||||||
c.MemLimit = 2147483648
|
c.MemLimit = 2147483648
|
||||||
return c
|
return c
|
||||||
@@ -47,13 +49,14 @@ func (c *Mock) run() {
|
|||||||
defer close(c.stream)
|
defer close(c.stream)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
c.CPUUtil += rand.Intn(2)
|
c.CPUUtil += rand.Intn(2) * int(c.aggression)
|
||||||
if c.CPUUtil > 100 {
|
if c.CPUUtil >= 100 {
|
||||||
c.CPUUtil = 0
|
c.CPUUtil = 0
|
||||||
}
|
}
|
||||||
c.NetTx += rand.Int63n(600)
|
|
||||||
c.NetRx += rand.Int63n(600)
|
c.NetTx += rand.Int63n(60) * c.aggression
|
||||||
c.MemUsage += rand.Int63n(c.MemLimit / 32)
|
c.NetRx += rand.Int63n(60) * c.aggression
|
||||||
|
c.MemUsage += rand.Int63n(c.MemLimit/16) * c.aggression
|
||||||
if c.MemUsage > c.MemLimit {
|
if c.MemUsage > c.MemLimit {
|
||||||
c.MemUsage = 0
|
c.MemUsage = 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,20 +26,28 @@ func NewMockContainerSource() *MockContainerSource {
|
|||||||
|
|
||||||
// Create Mock containers
|
// Create Mock containers
|
||||||
func (cs *MockContainerSource) Init() {
|
func (cs *MockContainerSource) Init() {
|
||||||
total := 20
|
|
||||||
rand.Seed(int64(time.Now().Nanosecond()))
|
rand.Seed(int64(time.Now().Nanosecond()))
|
||||||
|
|
||||||
for i := 0; i < total; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
//time.Sleep(1 * time.Second)
|
time.Sleep(500 * time.Millisecond)
|
||||||
collector := metrics.NewMock()
|
cs.makeContainer(3)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < 16; i++ {
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
cs.makeContainer(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cs *MockContainerSource) makeContainer(aggression int64) {
|
||||||
|
collector := metrics.NewMock(aggression)
|
||||||
c := NewContainer(makeID(), collector)
|
c := NewContainer(makeID(), collector)
|
||||||
c.SetMeta("name", makeName())
|
c.SetMeta("name", makeName())
|
||||||
c.SetState(makeState())
|
c.SetState(makeState())
|
||||||
cs.containers = append(cs.containers, c)
|
cs.containers = append(cs.containers, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cs *MockContainerSource) Loop() {
|
func (cs *MockContainerSource) Loop() {
|
||||||
iter := 0
|
iter := 0
|
||||||
for {
|
for {
|
||||||
|
|||||||
Reference in New Issue
Block a user