WEBVTT

1
00:00.000 --> 00:04.160
Now previously we've been focused on how we can effectively parse memory

2
00:04.160 --> 00:04.920
information from

3
00:04.920 --> 00:05.920
our devices.

4
00:05.920 --> 00:10.050
What I now want to turn your attention to is how we can do a similar thing but

5
00:10.050 --> 00:11.040
for CPU

6
00:11.040 --> 00:13.040
that is our computer processing.

7
00:13.040 --> 00:16.560
So naturally if our processes happen to be overworked then what is going to

8
00:16.560 --> 00:17.080
happen is

9
00:17.080 --> 00:21.660
the CPU is not going to be freed up for other tasks and thus we're going to get

10
00:21.660 --> 00:22.320
sluggish

11
00:22.320 --> 00:23.320
performance.

12
00:23.320 --> 00:28.000
Now previously we also used this particular utility stress NG and once again we

13
00:28.000 --> 00:28.400
're going

14
00:28.400 --> 00:32.380
to use this same command this time with a different option so that we can
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

14
00:28.400 --> 00:32.380
to use this same command this time with a different option so that we can

15
00:32.380 --> 00:33.120
stress the

16
00:33.120 --> 00:34.120
CPU.

17
00:34.120 --> 00:37.640
So let's look at some of the commands that we could use with respect to our CPU

18
00:37.640 --> 00:37.800
and

19
00:37.800 --> 00:40.000
then we'll begin parsing some information.

20
00:40.000 --> 00:44.160
So obviously one we can use would be the top commands as we can see here we

21
00:44.160 --> 00:44.720
have our

22
00:44.720 --> 00:47.320
column specifying all the CPU information.

23
00:47.320 --> 00:50.370
If you so wish you can parse that information in a similar way what I would

24
00:50.370 --> 00:51.120
recommend though

25
00:51.120 --> 00:54.480
is when you use a top command if you go into the man page here and scroll on

26
00:54.480 --> 00:55.320
down the option

27
00:55.320 --> 00:59.140
I would specify would be the dash B flag for batch mode this is going to allow

28
00:59.140 --> 00:59.800
you to

29
00:59.800 --> 01:04.340
effectively send the output from top into other programs or to a file pretty
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

29
00:59.800 --> 01:04.340
effectively send the output from top into other programs or to a file pretty

30
01:04.340 --> 01:04.800
much we

31
01:04.800 --> 01:09.400
specify the dash N option so that we can specify how many iterations you want.

32
01:09.400 --> 01:14.260
So if I just say top dash B N1 and to enter as opposed to having our

33
01:14.260 --> 01:16.040
continually updating

34
01:16.040 --> 01:21.080
and interactive top output instead we just get this one snapshot captured here.

35
01:21.080 --> 01:22.080
Check this out see that.

36
01:22.080 --> 01:25.180
So to make things a little bit easier to read let's pipe this output into the

37
01:25.180 --> 01:25.960
head command.

38
01:25.960 --> 01:29.560
So the top few lines let's just focus on this one here CPU what I could do is

39
01:29.560 --> 01:29.880
just

40
01:29.880 --> 01:34.500
correct that output for CPU and check this out right here here is all the CPU
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

40
01:29.880 --> 01:34.500
correct that output for CPU and check this out right here here is all the CPU

41
01:34.500 --> 01:35.040
information

42
01:35.040 --> 01:39.340
once again if you want to pass this information into arc you could parse that

43
01:39.340 --> 01:39.880
no problem at

44
01:39.880 --> 01:43.900
all so like I say let's just parse it again and we can just begin printing our

45
01:43.900 --> 01:44.520
values here

46
01:44.520 --> 01:48.780
to first we can get the second value the third isn't really a value as such

47
01:48.780 --> 01:49.800
however the fourth

48
01:49.800 --> 01:53.350
value is and once again just like we saw before we can convert these numbers

49
01:53.350 --> 01:54.120
into integer

50
01:54.120 --> 01:58.230
or float values and begin at running comparison so that is one command you can

51
01:58.230 --> 01:58.640
use you could

52
01:58.640 --> 02:01.710
also use the uptime commands now in this case here we're going to see the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

52
01:58.640 --> 02:01.710
also use the uptime commands now in this case here we're going to see the

53
02:01.710 --> 02:03.240
actual load average.

54
02:03.240 --> 02:06.720
Now this is what I'm going to focus in on in this particular video so can you

55
02:06.720 --> 02:07.200
recall

56
02:07.200 --> 02:11.280
how to interpret the load average we have three different values here one is

57
02:11.280 --> 02:11.800
the load

58
02:11.800 --> 02:16.140
average which is pretty much a little snapshot of the general activity on the

59
02:16.140 --> 02:16.840
system and

60
02:16.840 --> 02:19.120
we see it in three different time increments.

61
02:19.120 --> 02:23.130
The first one here is the load average over the past one minutes the next one

62
02:23.130 --> 02:23.720
is the load

63
02:23.720 --> 02:27.060
average over the past five minute period let me just draw that a little bit

64
02:27.060 --> 02:27.760
clearer here

65
02:27.760 --> 02:32.250
we go five minutes and the last one here the third one this is the load average
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

65
02:27.760 --> 02:32.250
we go five minutes and the last one here the third one this is the load average

66
02:32.250 --> 02:32.720
over the

67
02:32.720 --> 02:37.580
past 15 minutes now the general rule of thumb is that you really don't want to

68
02:37.580 --> 02:38.320
have a load

69
02:38.320 --> 02:43.170
average greater than the number of CPU cores on your systems so if I just go to

70
02:43.170 --> 02:44.000
my terminal

71
02:44.000 --> 02:48.320
here now say LS CPU we have a whole bunch of information popping out.

72
02:48.320 --> 02:51.930
If I scroll on up we can see our CPUs in fact let me just wait for that to make

73
02:51.930 --> 02:52.440
it a little

74
02:52.440 --> 02:57.510
bit easier as we can see here from my output I have two CPUs so in the case of

75
02:57.510 --> 02:58.320
my uptime

76
02:58.320 --> 03:02.140
if I saw any of my load averages approaching the 2.0 mark that would
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

76
02:58.320 --> 03:02.140
if I saw any of my load averages approaching the 2.0 mark that would

77
03:02.140 --> 03:03.400
potentially be a cause

78
03:03.400 --> 03:07.080
for concern especially for prolonged periods so if you saw it in the third

79
03:07.080 --> 03:07.760
column then

80
03:07.760 --> 03:11.200
this would definitely merit some investigation now as opposed to actually

81
03:11.200 --> 03:12.440
getting this information

82
03:12.440 --> 03:17.460
via the uptime commands and trying to parse it via you know if I print one or

83
03:17.460 --> 03:18.120
five you

84
03:18.120 --> 03:21.080
really recommend all these values one and five I figure all the way up to eight

85
03:21.080 --> 03:22.000
for example

86
03:22.000 --> 03:25.820
notice I'm now getting these numerical values but I'm also getting a trailing

87
03:25.820 --> 03:26.680
comma similarly

88
03:26.680 --> 03:30.680
let's go to the next value so I'll use dollar sign nine there's the next we
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

88
03:26.680 --> 03:30.680
let's go to the next value so I'll use dollar sign nine there's the next we

89
03:30.680 --> 03:31.400
also have a

90
03:31.400 --> 03:36.260
comma and now we get to the third load average via the value 10 and we don't

91
03:36.260 --> 03:37.040
have a comma

92
03:37.040 --> 03:40.200
at the end you see that look at the information here we have two commas when it

93
03:40.200 --> 03:41.160
comes to comparing

94
03:41.160 --> 03:44.530
these numerical values we would actually have to manually strip out the commas

95
03:44.530 --> 03:45.040
for two of

96
03:45.040 --> 03:48.700
the values and that is just a little bit additional work we can get the same

97
03:48.700 --> 03:49.680
information but in

98
03:49.680 --> 03:53.640
a slightly different format that is more conducive to our playbooks just by

99
03:53.640 --> 03:54.600
simply going into

100
03:54.600 --> 03:58.900
the command or rather into the file should I say proc load avg so let's just

101
03:58.900 --> 03:59.520
cat this

102
03:59.520 --> 04:03.430
particular file right here and check this out this here these first the values
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

102
03:59.520 --> 04:03.430
particular file right here and check this out this here these first the values

103
04:03.430 --> 04:04.080
are actually

104
04:04.080 --> 04:07.550
the load averages but we don't have to contend with this weird formatting of

105
04:07.550 --> 04:08.240
dealing with

106
04:08.240 --> 04:12.540
the commas so let's use this particular command and again we really don't want

107
04:12.540 --> 04:13.080
to be seeing

108
04:13.080 --> 04:17.580
the value over two but just for a general warning how about we write a playbook

109
04:17.580 --> 04:17.920
to warm

110
04:17.920 --> 04:22.610
us if the value ever gets greater than one so let's go and do this then let's

111
04:22.610 --> 04:23.240
create

112
04:23.240 --> 04:27.020
a playbook called play three dot yml go into insert mode have a three hyphens

113
04:27.020 --> 04:27.480
give it a

114
04:27.480 --> 04:31.730
name we'll just say play three testing cpu usage again we'll target the all-g
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

114
04:27.480 --> 04:31.730
name we'll just say play three testing cpu usage again we'll target the all-g

115
04:31.730 --> 04:32.440
rit within

116
04:32.440 --> 04:37.090
our host gather facts will be set to false and they will define our tasks so I

117
04:37.090 --> 04:37.440
will say

118
04:37.440 --> 04:41.040
is I'll pull the one minute load average and I'll use the answer will built in

119
04:41.040 --> 04:42.040
shell module

120
04:42.040 --> 04:46.580
so again if I cat my proc load average file if I take that output and I feed it

121
04:46.580 --> 04:47.080
into the

122
04:47.080 --> 04:51.370
all commands and then I'll have my quotations and curly braces and I'm going to

123
04:51.370 --> 04:51.920
specify

124
04:51.920 --> 04:56.160
that I want to print the very first value that we get the first column should I

125
04:56.160 --> 04:56.440
say

126
04:56.440 --> 05:00.410
that will be this value right here if I answer notice the value in this case
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

126
04:56.440 --> 05:00.410
that will be this value right here if I answer notice the value in this case

127
05:00.410 --> 05:01.560
here just happened

128
05:01.560 --> 05:06.150
to change these values are in flux after all depending on the CPU utilization

129
05:06.150 --> 05:06.800
if I happen

130
05:06.800 --> 05:11.740
to do dollar sign to we get the five minute average and then dollar sign three

131
05:11.740 --> 05:12.320
we get the

132
05:12.320 --> 05:15.430
fifteen minute average so this command here will parse out the one minute

133
05:15.430 --> 05:16.120
average which

134
05:16.120 --> 05:20.020
will be much more variable so let's go back into our playbook okay so let's

135
05:20.020 --> 05:20.560
paste this

136
05:20.560 --> 05:24.870
in and let's register this I'll say this is the variable one minute average and

137
05:24.870 --> 05:25.240
now I'll

138
05:25.240 --> 05:29.310
write a task to test the one minute average so now let's use the answer will

139
05:29.310 --> 05:29.880
built in

140
05:29.880 --> 05:34.750
the debug module and the message is going to be warning the one minute load
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

140
05:29.880 --> 05:34.750
the debug module and the message is going to be warning the one minute load

141
05:34.750 --> 05:35.720
average is

142
05:35.720 --> 05:40.010
above one and then what I can do is actually use my double curly braces and

143
05:40.010 --> 05:40.800
then print out

144
05:40.800 --> 05:45.480
the one minute average and I'll take the STD out so let's save this and writing

145
05:45.480 --> 05:46.080
quits now

146
05:46.080 --> 05:49.260
if I happen to run the playbook right now it's always going to print out that

147
05:49.260 --> 05:49.720
warning

148
05:49.720 --> 05:54.400
message as we see here warning the one minute average is above one point zero

149
05:54.400 --> 05:55.080
and then it

150
05:55.080 --> 05:59.020
shows us the value which in this case here is only 0.04 and then in this case

151
05:59.020 --> 05:59.520
here for

152
05:59.520 --> 06:04.420
the blue box is 0.0 very very low so pretty much this statement is not actually
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

152
05:59.520 --> 06:04.420
the blue box is 0.0 very very low so pretty much this statement is not actually

153
06:04.420 --> 06:04.960
true we

154
06:04.960 --> 06:08.920
only want the warning to print when a particular condition is met so let's go

155
06:08.920 --> 06:09.800
in here go into

156
06:09.800 --> 06:13.700
our playbook and we will only print this particular message when something

157
06:13.700 --> 06:14.520
happens and what is

158
06:14.520 --> 06:21.090
that going to actually be them but if I take my one minute avg.stdout value

159
06:21.090 --> 06:22.040
which is by

160
06:22.040 --> 06:25.620
the way what we just saw printed on the screen right here in this case of the

161
06:25.620 --> 06:26.440
yellow box it

162
06:26.440 --> 06:31.770
was 0.4 and the blue box 0.00 these are float values by the way now remember we
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

162
06:26.440 --> 06:31.770
was 0.4 and the blue box 0.00 these are float values by the way now remember we

163
06:31.770 --> 06:32.200
don't want

164
06:32.200 --> 06:35.950
this to be string values so I'm going to use a filter to convert it into a

165
06:35.950 --> 06:36.640
float so not

166
06:36.640 --> 06:40.320
using integer this time because we're using the point zeros let's use the float

167
06:40.320 --> 06:40.800
and what

168
06:40.800 --> 06:45.470
I want to do is I want to print this when that particular value when it is

169
06:45.470 --> 06:46.480
converted to a

170
06:46.480 --> 06:51.330
float when that value is greater than one so let's save this right here now if

171
06:51.330 --> 06:51.680
I just

172
06:51.680 --> 06:55.410
run this at the moment nothing should actually print because the load average

173
06:55.410 --> 06:56.160
is really quite

174
06:56.160 --> 06:59.950
small at the moment but if I go to my device here let's maybe go to the blue

175
06:59.950 --> 07:00.680
box and I say
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

175
06:59.950 --> 07:00.680
box and I say

176
07:00.680 --> 07:06.470
stress ng-cpu2 to use two CPUs and I say the timer is 100 seconds watch what

177
07:06.470 --> 07:07.040
happens

178
07:07.040 --> 07:11.780
if I go to a new terminal window if I just say uptime for example to see the

179
07:11.780 --> 07:12.760
load average

180
07:12.760 --> 07:16.650
this here is beginning to creep up and again let's do it again arrow up it's

181
07:16.650 --> 07:17.000
beginning

182
07:17.000 --> 07:20.430
to get high and higher basically it's now greater than one so if we run the

183
07:20.430 --> 07:21.040
playbook

184
07:21.040 --> 07:24.980
we should actually see that reflected over on the blue box device let's try

185
07:24.980 --> 07:25.520
this one

186
07:25.520 --> 07:29.670
more time and to enter look at what we're getting here we're pulling the

187
07:29.670 --> 07:30.400
command for
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

187
07:29.670 --> 07:30.400
command for

188
07:30.400 --> 07:34.350
both devices in the case of the yellow box the print message is skipped because

189
07:34.350 --> 07:35.000
the condition

190
07:35.000 --> 07:38.720
was not met but in the blue box we're actually getting this warming the one

191
07:38.720 --> 07:39.840
minute load average

192
07:39.840 --> 07:45.100
is above one and it shows us the value 1.46 at the snapshot so what I could do

193
07:45.100 --> 07:45.480
is I could

194
07:45.480 --> 07:49.290
actually build out my playbook and I could effectively just copy all this right

195
07:49.290 --> 07:49.600
here

196
07:49.600 --> 07:53.220
and then paste this in and all I will do is I'll make some modifications for

197
07:53.220 --> 07:53.760
the second

198
07:53.760 --> 07:58.180
one here I will change the name to pull the five minute average so it's nice

199
07:58.180 --> 07:59.280
and descriptive

200
07:59.280 --> 08:03.310
my awkward is going to print out the second value which will be the five minute
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

200
07:59.280 --> 08:03.310
my awkward is going to print out the second value which will be the five minute

201
08:03.310 --> 08:03.840
average

202
08:03.840 --> 08:08.720
and I'll change the name of the variable here to be five minute a vg and then

203
08:08.720 --> 08:09.520
down here

204
08:09.520 --> 08:13.390
where we run the test I'll change the name to test the five minute average and

205
08:13.390 --> 08:13.760
change

206
08:13.760 --> 08:17.250
the morning message to be the five minute average as above one and again I'm

207
08:17.250 --> 08:17.680
going to

208
08:17.680 --> 08:22.670
change the value here to be the variable five minute a vg dot s ed out and

209
08:22.670 --> 08:23.720
again the condition

210
08:23.720 --> 08:28.230
here once again change to five minute average and again let's just scroll on

211
08:28.230 --> 08:29.200
down let's paste

212
08:29.200 --> 08:32.870
all this in one more time and all I'm going to do once again is just change
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

212
08:29.200 --> 08:32.870
all this in one more time and all I'm going to do once again is just change

213
08:32.870 --> 08:33.520
this value

214
08:33.520 --> 08:39.210
here to be 15 minute average when I cat the proc value I'm going to get the

215
08:39.210 --> 08:40.160
third column

216
08:40.160 --> 08:44.990
and I'll register the variable as 15 minutes and again moving on down test the

217
08:44.990 --> 08:45.800
15 minute

218
08:45.800 --> 08:49.610
average and then have the average here 15 minutes reference the correct

219
08:49.610 --> 08:50.440
variable here

220
08:50.440 --> 08:55.320
as 15 minute average and again 15 minute average down here so essentially we've

221
08:55.320 --> 08:55.800
now written a

222
08:55.800 --> 08:59.810
playbook that is going to test for all over three different load averages

223
08:59.810 --> 09:00.600
across three
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

223
08:59.810 --> 09:00.600
across three

224
09:00.600 --> 09:05.120
different time periods and give us a warning if we happen to have a value over

225
09:05.120 --> 09:05.920
a particular

226
09:05.920 --> 09:10.910
value that we deem worrisome or at least worthy of notification and again adapt

227
09:10.910 --> 09:11.720
these values

228
09:11.720 --> 09:16.050
to whatever your system is and to whatever levels you want to see so let's last

229
09:16.050 --> 09:16.680
ly just run the

230
09:16.680 --> 09:20.240
playbook once again and to enter we'll probably see the same type of output

231
09:20.240 --> 09:21.240
once again so the

232
09:21.240 --> 09:25.380
playbit runs if we scroll on up we can see here the 15 minute average and five

233
09:25.380 --> 09:26.440
minute average have

234
09:26.440 --> 09:30.700
both been skipped over because the actual stress test has not been running long
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

234
09:26.440 --> 09:30.700
both been skipped over because the actual stress test has not been running long

235
09:30.700 --> 09:31.640
enough to affect

236
09:31.640 --> 09:36.200
those averages but once again on the one minute average we still have a value

237
09:36.200 --> 09:37.720
of 1.29 which is

238
09:37.720 --> 09:41.960
above the value 1 and therefore the warning message was triggered.
