The CPU. Sh script on the monitored end collects the CPU usage of the Local Machine, sends an HTTP request to the monitoring end recvinfo servlet, and submits data.
Content:
#! /Bin/sh
# Endless loop. Note the space after while
While:
Do
# Interval: one second
Sleep 1
CPU = $ (SAR-u 1 1 | awk 'nr = 4 {print $8 }')
# Use curl to send data to the specified Servlet
Curl-d "CPU = $ CPU" http: // localhost: 8080/monitor/recvinfo
Done
1 SAR: Ubuntu is not installed by default. Use apt-Get install sysstat to install it.
2 curl usage:
When submitting a form over HTTP, the post mode and get mode are commonly used. You only need to write the variable in the URL.
For example:
Curl http://www.yahoo.com/login.cgi? User = nickwolfe & Password = 12345 while option in post mode is-d For example, curl-d "user = nickwolfe & Password = 12345" http://www.yahoo.com/login.cgi
This is equivalent to sending a login application to this site ~~~~~ Whether to use the get mode or post mode depends on the program settings of the opposite server. Note that, in post mode, files are uploaded, such
<Form method = "Post" enctype = "multipar/form-Data" Action = "http://cgi2.tky.3web.ne.jp /~ Zzh/up_file.cgi ">
<Input type = file name = upload>
<Input type = submit name = Nick value = "go">
</Form>
To simulate such an HTTP form with curl, the syntax is as follows:
Curl-F upload = @ localfile-F Nick = go http://cgi2.tky.3web.ne.jp /~ Zzh/up_file.cgi