Create sensor readings | Computer Science homework help

Create a Sysinfo Protocol client which monitors the system specified. Your program should take a host name and optional port number on the command line. If the port number is not supplied, use 45490. Your client should attempt to connect to the indicated host and port, then monitor its status by printing a message each second. It will continue printing until the status until terminated with control-C. It will need to connect only once, as the protocol allows it to keep the connection open and request status information as many times as needed.

The protocol is a private one, and the only known server implementation presently runs on (If you want to run it on your system, let me know.) Mine client looks a bit like this:

[[email protected]]$ ./statmon
Up 02:40:22.12, 214 procs, 0 users, cpu util 0.025
Up 02:40:23.5, 212 procs, 0 users, cpu util 0.025, 100% idle
Up 02:40:24.89, 214 procs, 0 users, cpu util 0.025, 96.4029% idle
Up 02:40:26.27, 216 procs, 0 users, cpu util 0.025, 95.6522% idle
Up 02:40:27.64, 219 procs, 1 users, cpu util 0.025, 99.2701% idle
Up 02:40:29.03, 217 procs, 1 users, cpu util 0.025, 94.964% idle
Up 02:40:30.41, 217 procs, 1 users, cpu util 0.025, 100% idle
Up 02:40:31.79, 219 procs, 1 users, cpu util 0.025, 97.8261% idle
Up 02:40:33.17, 220 procs, 1 users, cpu util 0.025, 73.913% idle
Up 02:40:34.56, 220 procs, 1 users, cpu util 0.025, 48.2014% idle
Up 02:40:35.94, 220 procs, 1 users, cpu util 0.025, 49.2754% idle
Up 02:40:37.33, 220 procs, 1 users, cpu util 0.025, 50.3597% idle
Up 02:40:38.71, 220 procs, 1 users, cpu util 0.025, 47.1014% idle
Up 02:40:40.08, 220 procs, 1 users, cpu util 0.025, 48.9051% idle
Up 02:40:41.47, 220 procs, 1 users, cpu util 0.025, 48.9209% idle
Up 02:40:42.85, 220 procs, 1 users, cpu util 0.03, 50% idle
Up 02:40:44.24, 218 procs, 1 users, cpu util 0.03, 48.9209% idle
Up 02:40:45.64, 218 procs, 1 users, cpu util 0.03, 49.2857% idle
Up 02:40:47.02, 218 procs, 1 users, cpu util 0.03, 50% idle
Up 02:40:48.41, 220 procs, 1 users, cpu util 0.03, 49.6403% idle
Up 02:40:49.79, 220 procs, 1 users, cpu util 0.03, 47.8261% idle
Up 02:40:51.18, 220 procs, 1 users, cpu util 0.03, 48.9209% idle
Up 02:40:52.56, 220 procs, 1 users, cpu util 0.035, 55.0725% idle
Up 02:40:53.94, 220 procs, 1 users, cpu util 0.035, 100% idle
Up 02:40:55.32, 220 procs, 1 users, cpu util 0.035, 101.449% idle
Up 02:40:56.7, 220 procs, 1 users, cpu util 0.035, 98.5507% idle
Up 02:40:58.08, 220 procs, 1 users, cpu util 0.03, 98.5507% idle
Up 02:40:59.46, 219 procs, 1 users, cpu util 0.03, 95.6522% idle
Up 02:41:00.85, 219 procs, 1 users, cpu util 0.03, 100.719% idle
Up 02:41:02.24, 219 procs, 1 users, cpu util 0.03, 99.2806% idle
Up 02:41:03.62, 219 procs, 1 users, cpu util 0.03, 97.1014% idle
Up 02:41:05.01, 218 procs, 0 users, cpu util 0.03, 93.5252% idle
Up 02:41:06.39, 215 procs, 0 users, cpu util 0.03, 100% idle
Up 02:41:07.77, 213 procs, 0 users, cpu util 0.03, 97.8261% idle
Up 02:41:09.16, 213 procs, 0 users, cpu util 0.03, 100% idle
Up 02:41:10.55, 215 procs, 0 users, cpu util 0.03, 97.1223% idle
Up 02:41:11.93, 215 procs, 0 users, cpu util 0.03, 101.449% idle

Your client should print the following values.

Up Time

This is just the up value fetched from the server, but converted from seconds to some human-readable form in days, hours, minutes and seconds.

Number of Processes

The nproc value returned from the server. It actually includes both processes and threads.

Number of Users

The nuser value provided by the server.

CPU Utilization

This is the qsize divided by the number of CPUs, both values returned from the the sysinfo service.

Idle Percent

This involves a bit of calculation by the client. Each second, you need to fetch the up time and idle time. Take the difference between each new value, and the one from the previous fetch. This will give the change in up time and idle time. The percentage of idle is then just the ratio of these differences (times 100 to make a percentage). Obviously, this ratio is as computed over the previous second. Since your program is taking a new status each second, the up time difference should always be one second, but compute is as described, which will be more precise. Because of the way it is computed, do not print this on the first status report; just the later ones.

Your program should connect to the server, then enter a loop which repeatedly fetches the needed values from the server, then makes a report line. At the bottom of the loop, sleep for one second to create the delay between status lines. On Linux, Unix or Mac, use the Unix sleep call for one second, on Windows, you can use the Win32 Sleep call for 1000 milliseconds. (I believe this also requires #include <windows.h>, but please don’t use other Windows-specific calls.) In either case, the actual delay will be somewhat approximate.

Your client should handle gracefully. A failure to connect to the service should result in a message and program exit. Any failures to fetch needed information, or networking failures during the session, you may handle as you see fit.



Calculate your order
Pages (275 words)
Standard price: $0.00
Client Reviews
Our Guarantees
100% Confidentiality
Information about customers is confidential and never disclosed to third parties.
Original Writing
We complete all papers from scratch. You can get a plagiarism report.
Timely Delivery
No missed deadlines – 97% of assignments are completed in time.
Money Back
If you're confident that a writer didn't follow your order details, ask for a refund.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
Power up Your Academic Success with the
Team of Professionals. We’ve Got Your Back.
Power up Your Study Success with Experts We’ve Got Your Back.