[Last Call] Learn how to a build a cloud-first strategyRegister Now


Need to determine Process-File association

Posted on 2005-04-24
Medium Priority
Last Modified: 2010-04-20
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
Question by:ccsenet

Accepted Solution

dbacalja earned 250 total points
ID: 13858394
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.
LVL 22

Expert Comment

ID: 13865976
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:)

Author Comment

ID: 13880628
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

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month18 days, 2 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question