8

It is occasionally useful for me to know when my machine (Debian wheezy) was last touched. To be precise, I mean the more recent of the times I typed on the keyboard or moved the mouse. When I currently try to do this, I adopt ad-hoc means, like checking the last modification times of files that I was editing. However, a most systematic way would be useful. If not the precise time, approaches to get a reasonably close estimate would be welcome. I would prefer methods that used information that was not easily destroyed, like file modification times.

I suppose the ultimate approach would be to install some kind of program that monitors my computers activity. I don't know if I would go so far, but would be willing to hear about it, at least.

Any software installed for this purpose must be free, and available in Debian, for preference. Having said that, solutions don't have to be Debian-specific, or even Linux specific. In fact, it is better if they are not.

It's ok if only activity in an X11 session is taken into account.

Faheem Mitha
  • 35,108
  • 1
    whistles and moves along... – jasonwryan Oct 20 '14 at 23:03
  • Do an ls -l on the device files? Like /dev/tty (or the specific tty maybe /dev/console) and /dev/mouse? Of course once you issue the command from your terminal the dates on both would probably change. So it would have to be something running in the background and not connected to your terminal. – mdpc Oct 21 '14 at 01:38
  • @mdpc: Thanks for the suggestion, but are the device files really modified in real time? I see ls -lah /dev/console /dev/input/mouse0 /dev/input/mice crw------- 1 root root 5, 1 Oct 20 01:40 /dev/console crw------- 1 root root 13, 63 Oct 14 07:31 /dev/input/mice crw------- 1 root root 13, 32 Oct 14 07:31 /dev/input/mouse0 – Faheem Mitha Oct 21 '14 at 07:28
  • According to some of my previous work they are. – mdpc Oct 21 '14 at 21:01
  • @mdpc maybe I'm looking at the wrong devices, but that does not seem to be the case here. – Faheem Mitha Oct 21 '14 at 21:17
  • 1
    Input device files' timestamps don't change when you move the mouse or press a key. The timestamp is part of the inode in the filesystem, which is unrelated to the driver that actually handles the input. – Wyzard Oct 22 '14 at 02:23
  • @Wyzard yes, I figured something like that. Thanks. – Faheem Mitha Oct 22 '14 at 02:25

1 Answers1

3

There is an xprintidle utility (available as a package, at least in Debian and Ubuntu) that will do this. It gives you the number of milliseconds since last keyboard or mouse activity. Of course, if you type that in a terminal and run it, the result will be near-0.

Alternatively, there is a Perl module.

C code (apparently borrowed from that Perl module) can be found on Stack Overflow.

edit: You mentioned on chat possibly wanting it to be like a munin graph. Actually, you should be able to hook it into munin, but you'll need to get it access to your X display. The minimal requirement to do that is to set the DISPLAY=:0 environment variable (or whatever display you log in on) and also get it access to the magic-cookie, which will come from ~/.Xauthority or $XAUTHORITY. xauth is the command to manipulate xauthority files. See also Open a window on a remote X display (why "Cannot open display")? for some approaches on getting access to the X display.

derobert
  • 109,670
  • 1
    This isn't a complete solution by itself, but might be part of a larger solution. I'd really like a system that archives idle times for future reference. It is possible no such thing exists, though. – Faheem Mitha Dec 31 '14 at 14:44