Need to determine Process-File association

I have a number of instances of MRTG running on my system which collect statistics on various switches/routers on the network and store the data in distinct directories. For e.g., for and, the graphs and data are stored in /www/servers/mrtg- and /www/servers/mrtg- The associated config files are stored in /home/mrtg/mrtg- and /home/mrtg/mrtg- There are about 50 such instances of mrtg running for 50 different devices. I wanted to find out which instance of mrtg is associated with which data file. Running ps -ef | grep mrtg returns all of my mrtg processes and their PIDs. I parse the output and feed it to 'lsof -p PID' and this returns a number of associated files, but no mention of my /www/servers/mrtg-XX data files.

What am I doing wrong? Regarding my MRTG, I'm not using RRDTOOL, and the MRTG data collector starts up every 5 minutes for data collection.

- Faheem
Who is Participating?
it is probably because /www/servers/mrtg-XX data files are not held open by your mrtg processes. Every 5 minutes it opens the file, writes the data and closes the file. So you could say it's working as designed and you're doing nothing wrong.

If it is critical for you to have this functionality, you could change mrtg (it is perl script, so you can change it). You could add a part which writes current pid to your log file. You can use $$ variable to access current PID value.
You are probably not doing anything wrong. I suspect that the mrtg processes are only opening the files when they need to log data, and then closing them again. Therefore, you'll only get one of these files listed if you run lsof at the exact moment that data is being logged.

Perhaps look at creating a seperate soft link for each of the switches/routers? That way, you'll be able to identify which is which:)
ccsenetAuthor Commented:
Hey All,

Thanks for answering. You were right - mrtg doesn't lock down the data file or anything between reads/writes. That was silly to think it might. I was gonna go with what dbac suggested - about working in the mrtg script, but might have found a workaround. 'lsof +D /home/mrtg/cfg' returns all processos associated with the files in the directory. So my output is somewhat like this:
COMMAND    PID    .....  NAME
mrtg            4178         /mrtg-
mrtg            4193         /mrtg-

That solved the problem for determining which mrtg instance (PID) was associated with which device. However, I dunno why '_l' is appended to the files. The file does exist in each device's respective folder, but its empty --> 0L, 0C. Probably some internal working on MRTG.. Its not as nice and clean as logging PID by changing the mrtg script would be, but works for now.

Thanks again
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.