You are not logged in.

#1 2014-02-06 20:56:15

badhat
Member
Registered: 2011-01-30
Posts: 112

[Solved] Monitor and log real time of a binary

I'm curious to see some time statistics about various applications (e.g. games and web browsers). It's probably easy to guess that this is related to parental control.
Is there a good daemon that already exists to collect the total running time (in real time, not cpu time) of different applications?

An easy example of what I wish to collect is in this ouput

myhost% ps -eo pid,cmd,etimes | grep zsh
 5550 -zsh                          25072
 8573 -zsh                           2863
 8987 -zsh                            345
 9065 grep zsh                          0

You can see that this returns the process ID, the command and args, and the running time in seconds. I could probably cron this with a granularity of once every 10min, which would give me a pretty good idea of running time. Later I would need to sort for unique PID + command combination (it's unlikely, but possible that a PID is reused -- probably much less likely that it's also reused with the same command) and I'd just take the highest time in seconds for a particular PID and throw out the smaller values. I could then sum the times of the largest unique PIDs for a command to give the total time for a given period.
I was thinking I'd also want to see the username so that would just be another field to add to '-o', but that's not really important for my example.

Anyway, is there a tool that already does what I'm essentially looking to do? The end goal is to look at current usage times in order to see what is appropriate for cutting back (or giving allowances) with regards to parental controls.

Last edited by badhat (2014-02-11 03:04:10)

Offline

#2 2014-02-06 23:18:11

amckee
Member
From: Cruise Ship Earth
Registered: 2012-02-13
Posts: 25
Website

Re: [Solved] Monitor and log real time of a binary

What you are looking for is called process accounting. There's a writeup here, which will help you determine if it'll work as you need it to:
http://www.tldp.org/HOWTO/text/Process-Accounting

I was able to find this as well:
https://aur.archlinux.org/packages/acct/

Good luck, and be sure those logs rotate properly. They can grow really quickly.

Offline

#3 2014-02-11 03:03:55

badhat
Member
Registered: 2011-01-30
Posts: 112

Re: [Solved] Monitor and log real time of a binary

superb! This looks much more elegant.

Offline

Board footer

Powered by FluxBB