1
1
import type { ContainerHealth , ContainerStat , ContainerState } from "@/types/Container" ;
2
- import type { UseThrottledRefHistoryReturn } from "@vueuse/core" ;
3
- import { useExponentialMovingAverage } from "@/utils" ;
2
+ import { useExponentialMovingAverage , useSimpleRefHistory } from "@/utils" ;
4
3
import { Ref } from "vue" ;
5
4
6
5
type Stat = Omit < ContainerStat , "id" > ;
@@ -19,7 +18,7 @@ const hosts = computed(() =>
19
18
20
19
export class Container {
21
20
private _stat : Ref < Stat > ;
22
- private readonly throttledStatHistory : UseThrottledRefHistoryReturn < Stat , Stat > ;
21
+ private readonly _statsHistory : Ref < Stat [ ] > ;
23
22
public readonly swarmId : string | null = null ;
24
23
public readonly isSwarm : boolean = false ;
25
24
private readonly movingAverageStat : Ref < Stat > ;
@@ -34,10 +33,11 @@ export class Container {
34
33
public readonly labels = { } as Record < string , string > ,
35
34
public status : string ,
36
35
public state : ContainerState ,
36
+ stats : Stat [ ] ,
37
37
public health ?: ContainerHealth ,
38
38
) {
39
39
this . _stat = ref ( { cpu : 0 , memory : 0 , memoryUsage : 0 } ) ;
40
- this . throttledStatHistory = useThrottledRefHistory ( this . _stat , { capacity : 300 , deep : true , throttle : 1000 } ) ;
40
+ this . _statsHistory = useSimpleRefHistory ( this . _stat , { capacity : 300 , deep : true , initial : stats } ) ;
41
41
this . movingAverageStat = useExponentialMovingAverage ( this . _stat , 0.2 ) ;
42
42
43
43
const match = name . match ( SWARM_ID_REGEX ) ;
@@ -48,8 +48,8 @@ export class Container {
48
48
}
49
49
}
50
50
51
- get statHistory ( ) {
52
- return unref ( this . throttledStatHistory . history ) ;
51
+ get statsHistory ( ) {
52
+ return unref ( this . _statsHistory ) ;
53
53
}
54
54
55
55
get movingAverage ( ) {
0 commit comments