Ad Widget

Collapse

Linux Autodiscovery : services, processes, hard disks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Starko
    Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Aug 2012
    • 93

    #16
    The reason I write this, is because your script doesn't work as perfect as i want it to be. My problem is the core function, which gets the process names.
    Code:
    ps axo comm | sort | uniq -c
    I gets me something like this on our mailgateways
    Code:
    ...
          1 tlsmgr
          2 trivial-rewrite
          3 udevd
          1 uniq
         11 /usr/sbin/amavi
          1 /usr/sbin/postf
          1 /usr/sbin/postg
          1 /usr/sbin/spamd
          1 verify
          1 watchdog/0
          1 watchdog/1
          1 watchdog/2
          1 watchdog/3
          1 xe-daemon
    ...
    So my core processes amavisd, postfix, etc are never monitored.
    And by now I'm not able to find a solution for a command that would get me a process list like this:
    Code:
    apache2
    bash
    clamd
    cron
    squid

    Comment

    • ghusson
      Junior Member
      • Jul 2012
      • 16

      #17
      Typically, I don't have time to do this : spent time to analyse symptoms, dig, try, dig, RTFM, try, check, verify.
      Anyway I spent 1h on it. My ps command showed only the first 8 chars of the process name. I made modifications. Can you test?

      Code:
      #!/usr/bin/perl
      
      $first = 1;
      
      print "{\n";
      print "\t\"data\":[\n\n";
      
      for (`cat /proc/*/comm`) {
        ($procname) = m/^(.*)$/;
      
        print "\t,\n" if not $first;
        $first = 0;
      
        print "\t{\n";
        print "\t\t\"{#PROCNAME}\":\"$procname\"\n";
        print "\t}\n";
        }
      
      print "\n\t]\n";
      print "}\n";

      Comment

      • Starko
        Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Aug 2012
        • 93

        #18
        Hello and sorry for the late reply. I'm still here and I'm still testing. Just had a bad week, so there wasn't time for a reply.

        I tried your new command:
        Code:
        cat /proc/*/comm
        Code:
        kjournald
        ksoftirqd/1
        scache
        kworker/u:1
        watchdog/1
        smtp
        smtpd
        migration/2
        smtp
        smtp
        kworker/2:0
        flush-202:32
        smtpd
        smtpd
        ksoftirqd/2
        watchdog/2
        apache2
        apache2
        apache2
        kjournald
        migration/3
        trivial-rewrite
        kworker/3:0
        smtpd
        trivial-rewrite
        ksoftirqd/3
        smtpd
        watchdog/3
        init
        smtpd
        smtpd
        xe-daemon
        cpuset
         postfwd2::poli
        khelper
        rsyslogd
         postfwd2::poli
        kdevtmpfs
        zabbix_agentd
        udevd
        dccifd
        kworker/0:2
        policyd-weight
        policyd-weight
        cron
        pdns_recursor
        smtp
        smtp
        dbus-daemon
        /usr/sbin/postf
         postfwd2::cach
         postfwd2::poli
        /usr/sbin/amavi
        sshd
        sync_supers
        /usr/sbin/amavi
         postfwd2::poli
        /usr/sbin/amavi
        /usr/sbin/postg
        smtp
        smtp
        smtp
        bdi-default
        smtp
         postfwd2::poli
        smtp
         postfwd2::poli
        kintegrityd
        smtpd
        kblockd
        kthreadd
        smtpd
        cleanup
        clamd
        cleanup
         postfwd2::poli
        /usr/sbin/amavi
        /usr/sbin/amavi
        kworker/1:1
        /usr/sbin/amavi
        /usr/sbin/amavi
        udevd
        udevd
        freshclam
        tlsmgr
        khungtaskd
        kswapd0
        sleep
         postfwd2::poli
        ksmd
        bounce
        kworker/2:1
        /usr/sbin/spamd
        spamd child
        kworker/0:0
        flush-202:0
        kworker/u:0
        migration/0
         postfwd2::poli
         postfwd2::poli
        kworker/3:1
        I think I just have to use the "/usr/sbin/amavi" to monitor the amavisd process. But there still seem to miss some chars.

        Comment

        • ghusson
          Junior Member
          • Jul 2012
          • 16

          #19
          Hello Starko,
          I was asking myself if you had the solution and flew away... Happy to see it is not the case Sorry for your bad week.

          After googleing, I found other solution. Sorry, it is still bash based (I could use Perl). But I think this will be stable (and will work at last in GNU-Linux).

          Please try this and replace in the script :
          Code:
          for process_exepath in $(ls /proc/*/exe); do process_binpath=$(readlink --canonicalize $process_exepath); if [ "$process_binpath" != "" ]; then basename $process_binpath ; fi ;  done
          BR
          Gautier.

          Comment

          Working...