@@ -46,19 +46,18 @@ public function clusterAction(): void
46
46
);
47
47
48
48
$ metrics = new Metrics (Database::connection ());
49
- $ clusterMetrics = [];
50
49
51
- $ clusterMetrics = $ metrics ->getClusterUsage (
50
+ $ clusterMetrics = $ metrics ->getClusterMetrics (
52
51
(new DateTime ())->sub (new DateInterval ('PT12H ' )),
53
- Metrics::$ ClusterCpuUsage ,
54
- Metrics::$ ClusterMemoryUsage
52
+ Metrics::CLUSTER_CPU_USAGE ,
53
+ Metrics::CLUSTER_MEMORY_USAGE
55
54
);
56
55
57
56
$ this ->addContent (
58
57
new LineChart (
59
58
'chart-medium ' ,
60
- implode (', ' , $ clusterMetrics [Metrics::$ ClusterCpuUsage ]),
61
- implode (', ' , array_keys ($ clusterMetrics [Metrics::$ ClusterCpuUsage ])),
59
+ implode (', ' , $ clusterMetrics [Metrics::CLUSTER_CPU_USAGE ]),
60
+ implode (', ' , array_keys ($ clusterMetrics [Metrics::CLUSTER_CPU_USAGE ])),
62
61
'CPU Usage ' ,
63
62
'#00a8ff '
64
63
)
@@ -67,23 +66,18 @@ public function clusterAction(): void
67
66
$ this ->addContent (
68
67
new LineChart (
69
68
'chart-medium ' ,
70
- implode (', ' , $ clusterMetrics [Metrics::$ ClusterMemoryUsage ]),
71
- implode (', ' , array_keys ($ clusterMetrics [Metrics::$ ClusterMemoryUsage ])),
69
+ implode (', ' , $ clusterMetrics [Metrics::CLUSTER_MEMORY_USAGE ]),
70
+ implode (', ' , array_keys ($ clusterMetrics [Metrics::CLUSTER_MEMORY_USAGE ])),
72
71
'Memory Usage ' ,
73
72
'#8c7ae6 '
74
73
)
75
74
);
76
75
77
- // $numberOfRunningPods = $metrics->getNumberOfPodsByState('running');
78
- // $numberOfPendingPods = $metrics->getNumberOfPodsByState('pending');
79
- // $numberOfFailedPods = $metrics->getNumberOfPodsByState('failed');
80
- // $numberOfSucceededPods = $metrics->getNumberOfPodsByState('succeeded');
81
-
82
76
$ pods = $ metrics ->getNumberOfPodsByState (
83
- Metrics::$ PodStateRunning ,
84
- Metrics::$ PodStatePending ,
85
- Metrics::$ PodStateFailed ,
86
- Metrics::$ PodStateSucceeded
77
+ Metrics::POD_STATE_RUNNING ,
78
+ Metrics::POD_STATE_PENDING ,
79
+ Metrics::POD_STATE_FAILED ,
80
+ Metrics::POD_STATE_SUCCEEDED
87
81
);
88
82
89
83
$ this ->addContent (
@@ -92,35 +86,35 @@ public function clusterAction(): void
92
86
implode (
93
87
', ' ,
94
88
[
95
- $ pods [Metrics::$ PodStateRunning ],
96
- $ pods [Metrics::$ PodStatePending ],
97
- $ pods [Metrics::$ PodStateFailed ],
98
- $ pods [Metrics::$ PodStateSucceeded ]
89
+ $ pods [Metrics::POD_STATE_RUNNING ],
90
+ $ pods [Metrics::POD_STATE_PENDING ],
91
+ $ pods [Metrics::POD_STATE_FAILED ],
92
+ $ pods [Metrics::POD_STATE_SUCCEEDED ]
99
93
]
100
94
),
101
95
implode (
102
96
', ' ,
103
97
[
104
- $ pods [Metrics::$ PodStateRunning ] . ' Running ' ,
105
- $ pods [Metrics::$ PodStatePending ] . ' Pending ' ,
106
- $ pods [Metrics::$ PodStateFailed ] . ' Failed ' ,
107
- $ pods [Metrics::$ PodStateSucceeded ] . ' Succeeded '
98
+ $ pods [Metrics::POD_STATE_RUNNING ] . ' Running ' ,
99
+ $ pods [Metrics::POD_STATE_PENDING ] . ' Pending ' ,
100
+ $ pods [Metrics::POD_STATE_FAILED ] . ' Failed ' ,
101
+ $ pods [Metrics::POD_STATE_SUCCEEDED ] . ' Succeeded '
108
102
]
109
103
),
110
104
'#007bff, #ffc107, #dc3545, #28a745 '
111
105
)
112
106
);
113
107
114
- $ current = $ metrics ->getClusterUsage (
115
- (new DateTime ())->sub (new DateInterval ('PT1M ' )),
116
- Metrics::$ ClusterCpuUsage ,
117
- Metrics::$ ClusterMemoryUsage
108
+ $ current = $ metrics ->getClusterMetrics (
109
+ (new DateTime ())->sub (new DateInterval ('PT2M ' )),
110
+ Metrics::CLUSTER_CPU_USAGE ,
111
+ Metrics::CLUSTER_MEMORY_USAGE
118
112
);
119
113
120
114
$ this ->addContent (
121
115
new DoughnutChartStates (
122
116
'chart-small ' ,
123
- $ current [Metrics::$ ClusterCpuUsage ][array_key_last ($ current [Metrics::$ ClusterCpuUsage ])],
117
+ $ current [Metrics::CLUSTER_CPU_USAGE ][array_key_last ($ current [Metrics::CLUSTER_CPU_USAGE ])],
124
118
'CPU Usage ' ,
125
119
'#28a745, #ffc107, #dc3545 '
126
120
)
@@ -129,7 +123,7 @@ public function clusterAction(): void
129
123
$ this ->addContent (
130
124
new DoughnutChartStates (
131
125
'chart-small ' ,
132
- $ current [Metrics::$ ClusterMemoryUsage ][array_key_last ($ current [Metrics::$ ClusterMemoryUsage ])],
126
+ $ current [Metrics::CLUSTER_MEMORY_USAGE ][array_key_last ($ current [Metrics::CLUSTER_MEMORY_USAGE ])],
133
127
'Memory Usage ' ,
134
128
'#28a745, #ffc107, #dc3545 '
135
129
)
@@ -149,19 +143,22 @@ public function nodeAction(): void
149
143
);
150
144
151
145
$ metrics = new Metrics (Database::connection ());
152
- $ nodeMetrics = [];
153
146
154
- $ metrics ->getNodeNetworkBytes ($ nodeMetrics , 'received ' , $ this ->LAST_1_HOUR );
155
- $ metrics ->getNodeNetworkBytes ($ nodeMetrics , 'transmitted ' , $ this ->LAST_1_HOUR );
147
+ $ nodeNetworkMetrics = $ metrics ->getNodeNetworkBytes (
148
+ (new DateTime ())->sub (new DateInterval ('PT1H ' )),
149
+ Metrics::NODE_NETWORK_RECEIVED_BYTES ,
150
+ Metrics::NODE_NETWORK_TRANSMITTED_BYTES
151
+ );
152
+
156
153
157
- foreach ($ nodeMetrics as $ node ) {
154
+ foreach ($ nodeNetworkMetrics as $ node ) {
158
155
$ this ->addContent (
159
156
new LineChart (
160
157
'chart-medium ' ,
161
- implode (', ' , $ node [' receivedBytes ' ])
158
+ implode (', ' , $ node [Metrics:: NODE_NETWORK_RECEIVED_BYTES ])
162
159
. '; '
163
- . implode (', ' , $ node [' transmittedBytes ' ]),
164
- implode (', ' , array_keys ($ node [' receivedBytes ' ])),
160
+ . implode (', ' , $ node [Metrics:: NODE_NETWORK_TRANSMITTED_BYTES ]),
161
+ implode (', ' , array_keys ($ node [Metrics:: NODE_NETWORK_RECEIVED_BYTES ])),
165
162
'Received Bytes; Transmitted Bytes ' ,
166
163
'#593684; #a3367f '
167
164
)
@@ -182,23 +179,23 @@ public function podAction(): void
182
179
);
183
180
184
181
$ metrics = new Metrics (Database::connection ());
185
- $ podMetrics = [];
186
-
187
- $ metrics ->getPodRequest ($ podMetrics , 'cpu ' );
188
- $ metrics ->getPodRequest ($ podMetrics , 'memory ' );
189
182
190
- $ metrics ->getPodLimit ($ podMetrics , 'cpu ' );
191
- $ metrics ->getPodLimit ($ podMetrics , 'memory ' );
192
-
193
- $ metrics ->getPodCpuCoreUsage ($ podMetrics );
194
- $ metrics ->getPodMemoryByteUsage ($ podMetrics );
183
+ $ podMetricsCurrent = $ metrics ->getPodMetricsCurrent (
184
+ Metrics::POD_CPU_REQUEST ,
185
+ Metrics::POD_CPU_LIMIT ,
186
+ Metrics::POD_CPU_USAGE_CORES ,
187
+ Metrics::POD_MEMORY_REQUEST ,
188
+ Metrics::POD_MEMORY_LIMIT ,
189
+ Metrics::POD_MEMORY_USAGE_BYTES
190
+ );
195
191
196
- $ metrics ->getPodUsage ($ podMetrics , 'cpu ' , $ this ->LAST_1_HOUR );
197
- $ metrics ->getPodUsage ($ podMetrics , 'memory ' , $ this ->LAST_1_HOUR );
192
+ $ podMetricsPeriod = $ metrics ->getPodMetrics (
193
+ (new DateTime ())->sub (new DateInterval ('PT1H ' )),
194
+ Metrics::POD_CPU_USAGE ,
195
+ Metrics::POD_MEMORY_USAGE
196
+ );
198
197
199
- echo '<pre> ' ;
200
- // print_r($podMetrics);
201
- // exit;
198
+ $ podMetrics = Metrics::mergeMetrics ($ podMetricsCurrent , $ podMetricsPeriod );
202
199
203
200
$ table = new HtmlElement ('table ' , new Attributes (['class ' => 'condition-table ' ]));
204
201
$ table ->addHtml (
@@ -224,40 +221,43 @@ public function podAction(): void
224
221
$ tr ->addHtml (new HtmlElement ('td ' , null , new Text ($ pod ['name ' ])));
225
222
$ td = new HtmlElement ('td ' , null );
226
223
227
- if (isset ($ pod [' cpuLimit ' ]) && $ pod [' cpuRequest ' ] < $ pod [' cpuLimit ' ]) {
224
+ if (isset ($ pod [Metrics:: POD_CPU_LIMIT ]) && $ pod [Metrics:: POD_CPU_REQUEST ] < $ pod [Metrics:: POD_CPU_LIMIT ]) {
228
225
$ td ->addHtml (
229
226
new DoughnutChartRequestLimit (
230
227
'chart-mini ' ,
231
- $ pod [' cpuRequest ' ],
232
- $ pod [' cpuLimit ' ],
233
- $ pod [' cpuUsageCores ' ]
228
+ $ pod [Metrics:: POD_CPU_REQUEST ],
229
+ $ pod [Metrics:: POD_CPU_LIMIT ],
230
+ $ pod [Metrics:: POD_CPU_USAGE_CORES ]
234
231
)
235
232
);
236
233
}
237
234
238
235
$ tr ->addHtml ($ td );
239
236
$ td = new HtmlElement ('td ' , null );
240
237
241
- if (isset ($ pod ['memoryLimit ' ]) && $ pod ['memoryRequest ' ] < $ pod ['memoryLimit ' ]) {
238
+ if (
239
+ isset ($ pod [Metrics::POD_MEMORY_LIMIT ])
240
+ && $ pod [Metrics::POD_MEMORY_REQUEST ] < $ pod [Metrics::POD_MEMORY_LIMIT ]
241
+ ) {
242
242
$ td ->addHtml (
243
243
new DoughnutChartRequestLimit (
244
244
'chart-mini ' ,
245
- $ pod [' memoryRequest ' ],
246
- $ pod [' memoryLimit ' ],
247
- $ pod [' memoryUsageBytes ' ]
245
+ $ pod [Metrics:: POD_MEMORY_REQUEST ],
246
+ $ pod [Metrics:: POD_MEMORY_LIMIT ],
247
+ $ pod [Metrics:: POD_MEMORY_USAGE_BYTES ]
248
248
)
249
249
);
250
250
}
251
251
252
252
$ tr ->addHtml ($ td );
253
253
$ td = new HtmlElement ('td ' , null );
254
254
255
- if (isset ($ pod [' cpu ' ])) {
255
+ if (isset ($ pod [Metrics:: POD_CPU_USAGE ])) {
256
256
$ td ->addHtml (
257
257
new LineChartMinified (
258
258
'chart-mini ' ,
259
- implode (', ' , $ pod [' cpu ' ]),
260
- implode (', ' , array_keys ($ pod [' cpu ' ])),
259
+ implode (', ' , $ pod [Metrics:: POD_CPU_USAGE ]),
260
+ implode (', ' , array_keys ($ pod [Metrics:: POD_CPU_USAGE ])),
261
261
'#00a8ff '
262
262
)
263
263
);
@@ -266,12 +266,12 @@ public function podAction(): void
266
266
$ tr ->addHtml ($ td );
267
267
$ td = new HtmlElement ('td ' , null );
268
268
269
- if (isset ($ pod [' memory ' ])) {
269
+ if (isset ($ pod [Metrics:: POD_MEMORY_USAGE ])) {
270
270
$ td ->addHtml (
271
271
new LineChartMinified (
272
272
'chart-mini ' ,
273
- implode (', ' , $ pod [' memory ' ]),
274
- implode (', ' , array_keys ($ pod [' memory ' ])),
273
+ implode (', ' , $ pod [Metrics:: POD_MEMORY_USAGE ]),
274
+ implode (', ' , array_keys ($ pod [Metrics:: POD_MEMORY_USAGE ])),
275
275
'#ffa800 '
276
276
)
277
277
);
0 commit comments