fujisan, not clear you can monitor everything you want in g-code, but let's assume you can. In other words, if you go through the programming manual for your machine's controller, everything you want to see is accessible either directly (e.g. you know the spindle speed is 6000 rpm because you executed an "S6000") or indirectly via a # system variable.
If you controller has a means of monitoring these variables directly, great. OTOH, a lot of data collection is done using a DPRNT statement in the g-code. You see this for monitoring cycle times or for tool life management, for example.
DPRNT just writes out whatever you want it to via the serial port. You use DNC software that has the ability to collect this information to gather it into a file. You can then analyze the file using Excel, a Basic program, or whatever tool is most convenient.
For example, let's say you want to monitor which programs ran, which tools in the changer where accessed, how long each was accessed, and at what feeds and speeds the tool ran. You can get all that by instrumenting the "O", "S", "F", and "T" words.
What I mean by instrumenting, is you'd go through the g-code and for each of those words you'd add a DPRNT that sends the value out the serial port.
This is not too hard to do with search and replace (well, you'd better have regular expression capability!). But, some g-code editors can do it too. For example, G-Wizard has a "Monitor Revision" that lets you add a particular string to the g-code after a particular word, or a particular word followed by a particular address.
The output might look something like this:
Program O0100
Spindle S6000
Feed F110
Tool T12
...
etc.
Hopefully you can get a timestamp on those entries or output one as part of the DPRNT.
So, that's another way to go about it. Several of the machine data collection software programs are based on this kind of approach.
Best,
BW
Try G-Wizard Machinist's Calculator for free:
http://www.cnccookbook.com/CCGWizard.html