0

Is it possible to export output from apachetop to file? Something like this: "apachetop > file", but because apachetop is running "forever", so this command is also running forever. I just need to obtain actual output from this program and handle it in my GTK# application. Every answer will be very appreciated. Matej.

1
  • You may find the manual page for tail of interest, either as a command to directly leverage or an idea to duplicate in your own code. May 1, 2012 at 18:57

2 Answers 2

1

This might work:

{ apachetop > file 2>&1 & sleep 1; kill $! ; }

but no guarantees :)

Another way using linux is to find out the /dev/vcsN device that is being used when running the program and reading from that file directly. It contains a copy of the screen data for a given VT; I'm not sure if there is a applicable device for a pty.

4
  • Output of your command looks good but it is full of escape sequence characters (when I use vim, cat -v or I give it to my gtk# application): ^[[?1049h^[[1;24r^[(B^[[m^[[4l^[[?7h^[[?1h^[=^[[H^[[2Jlast hit: 00:00:00^[[1;28Hatop runtime: 0 days, 00:00:00^[[1;72H18:00:55^M^[[2d^[(B^[[0;1mAll: 0 reqs ( 0.0/sec) 0.0B ( 0.0B/sec) 0.0B/req^M^[[3d^[(B^[[m2xx:.... I also tried cat file -v > file, sed 's/^[[^a-zA-Z]\+[a-zA-Z]//g' file or sed -r "s/\x1B[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" file > file2. output from strings was the best, but not perfect. Can u help me?
    – matej148
    May 3, 2012 at 18:38
  • Try sed -r "s/\x1B[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g". Source: serverfault.com/questions/71285/. May 3, 2012 at 18:49
  • Thanks for fast answer, but output from vim is: ^[[?1049h^[[1;24r^[(B^[[4l^[[?7h^[[?1h^[=^[[H^[[2Jlast hit: 00:00:00^[[1;28Hatop runtime: 0 days, 00:00:00^[[1;72H18:00:55^M^[[2d^[(BAll: 0 reqs ( 0.0/sec) 0.0B ( 0.0B/sec) 0.0B/req^M^[[3d^[(B2xx: 0 ( 0.0%) 3xx: 0 ( 0.0%) 4xx: 0 ( 0.0%) 5xx: 0 ( 0.0%)^M^[[4d^[(BR ( 1s): 0 reqs ( 0.0/sec) 0.0B ( 0.0B/sec) 0.0B/req^M^[[5d^[(B2xx: 0 ( 0.0%) 3xx: 0 ( 0.0%) 4xx: 0 ( 0.0%) 5xx: 0 ( 0.0%)^M^[[7d
    – matej148
    May 3, 2012 at 18:59
  • There was also an answer I got the last one from on using the col -b command. Maybe try that. Looking at that sed command it doesn't seem complete. If col fails I suggest googling stripping out escape sequences from a text file. May 3, 2012 at 19:18
0

Well indirectly apachetop is using the access.log file to get it's data.

Look at

/var/log/apache2/access.log

You'll simply have to parse the file to get the info you're looking for!/var/log/apache2/access.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.