@@ -128,7 +128,44 @@ private function collectForDevice($device)
128
128
}
129
129
}
130
130
131
- // var_dump($collection);
131
+ $ update = end ($ collection );
132
+
133
+ $ keys = [];
134
+ $ values = [];
135
+ $ mapping = [
136
+ 'rrqm/s ' => 'RRMerge ' ,
137
+ 'wrqm/s ' => 'WRMerge ' ,
138
+ 'r/s ' => 'RReq ' ,
139
+ 'w/s ' => 'WReq ' ,
140
+ 'rkB/s ' => 'RByte ' ,
141
+ 'wkB/s ' => 'WByte ' ,
142
+ 'avgrq-sz ' => 'RSize ' ,
143
+ 'avgqu-sz ' => 'QLength ' ,
144
+ 'await ' => 'WTime ' ,
145
+ 'r_await ' => 'RWTime ' ,
146
+ 'w_await ' => 'WWTime ' ,
147
+ 'svctm ' => 'STime ' ,
148
+ '%util ' => 'Util '
149
+ ];
150
+
151
+ foreach ($ mapping as $ from => $ to ){
152
+ if (isset ($ update [$ from ])) {
153
+ array_push ($ keys , $ to );
154
+ if (in_array ($ from ,['rkB/s ' , 'wkB/s ' ])) {
155
+ array_push ($ values , (float ) ($ update [$ from ] * 1024 )); // We want these at Bytes not KB
156
+ continue ;
157
+ }
158
+ array_push ($ values , (float ) $ update [$ from ]);
159
+ }
160
+ }
161
+
162
+ if (!rrd_update ($ this ->rrdFilePath [$ device ], [
163
+ "-t " ,
164
+ implode (': ' , $ keys ),
165
+ 'N: ' . implode (': ' , $ values )
166
+ ])){
167
+ $ this ->fail (rrd_error ());
168
+ }
132
169
}
133
170
134
171
public function collect ()
@@ -143,6 +180,50 @@ public function graph($period = 'day', $graphPath = __DIR__)
143
180
if (!file_exists ($ graphPath )) {
144
181
$ this ->fail ("The path [ $ graphPath] does not exist or is not readable. \n" );
145
182
}
183
+
184
+ $ colours = [
185
+ '#2C3E50 ' ,
186
+ '#0EAD9A ' ,
187
+ '#F8C82D ' ,
188
+ '#E84B3A ' ,
189
+ '#832D51 ' ,
190
+ '#74525F ' ,
191
+ '#404148 ' ,
192
+ '#6EC198 ' ,
193
+ '#27AE60 '
194
+ ];
195
+
196
+ $ config = [
197
+ "-s " ,"-1 $ period " ,
198
+ "-t Disk Utilization in the last $ period " ,
199
+ "-z " ,
200
+ "--lazy " ,
201
+ "-h " , "150 " , "-w " , "700 " ,
202
+ "-l 0 " ,
203
+ "-a " , "PNG " ,
204
+ "-v Utilization % "
205
+ ];
206
+
207
+ foreach ($ this ->devices as $ device ) {
208
+ array_push ($ config , "DEF: {$ device }Avg= {$ this ->rrdFilePath [$ device ]}:Util:AVERAGE " );
209
+ array_push ($ config , "DEF: {$ device }Max= {$ this ->rrdFilePath [$ device ]}:Util:MAX " );
210
+ }
211
+
212
+ foreach ($ this ->devices as $ device ) {
213
+ $ colour = array_pop ($ colours );
214
+ $ config = array_merge ($ config , [
215
+ "LINE2: {$ device }Avg {$ colour }: " . $ device . ' Utilization ' ,
216
+ "GPRINT: {$ device }Avg:LAST: Current \\: %5.2lf%% " ,
217
+ "GPRINT: {$ device }Avg:MIN: Min \\: %5.2lf%% " ,
218
+ "GPRINT: {$ device }Max:MAX: Max \\: %5.2lf%% " ,
219
+ "GPRINT: {$ device }Avg:AVERAGE: Avg \\: %5.2lf%% \\n " ,
220
+ ]);
221
+ }
222
+
223
+ if (!rrd_graph ($ graphPath . '/disk_usage_ ' . $ period . '.png ' , $ config )) {
224
+ $ this ->fail ('Error writing connections graph for period ' . $ period .' [ ' . rrd_error () .'] ' );
225
+ }
226
+
146
227
}
147
228
}
148
229
0 commit comments