Docker container HOST is 127.0.0.1, how to get to run the container in the real IP address?

Issue #571 resolved
Former user created an issue

Event:

Event:       Content match
Service:     US_dgateway_log_alert
Date:        Thu, 09 Mar 2017 10:27:53
Action:      alert
Host:        127.0.0.1
Description: content match:

Comments (12)

  1. Tildeslash repo owner

    Please can you provide more details?:

    1. Monit configuration
    2. network interfaces on the docker host
    3. describe what exactly you need to monitor
  2. Anwar Xiao
    set daemon 30 with start delay 1
    set logfile   /var/log/monit/monit.log
    set pidfile   /opt/monit/pid/monit.pid
    set idfile    /opt/monit/id/.monit.id
    set statefile /opt/monit/state/.monit.state
    
    set ssl {
        verify     : enable, # verify SSL certificates (disabled by default but STRONGLY RECOMMENDED)
        selfsigned : allow   # allow self signed SSL certificates (reject by default)
    }
    
    set mailserver
        smtp.gmail.com port 587
        username "gogogo" password "zzzzzzzzzzzzzzzz"
        using ssl,smtp.163.com port 465
        username "gogogo" password "xxxxxxxxxxxxxxx"
        using SSLAUTO with timeout 15 seconds
        using hostname "163.com"
    
    set eventqueue basedir /opt/monit/event/monit slots 200
    
    set mail-format {
      from:    Monit <monitservice@gmail.com>
      subject: monit alert --  $EVENT $SERVICE
      message: :)                         
                    Event:       $EVENT
                    Service:     $SERVICE
                    Date:        $DATE
                    Action:      $ACTION
                    Host:        $HOST
                    Description: $DESCRIPTION
    }
    
    check file monit_config_file path /opt/monit/conf/monitrc
        if changed sha1 checksum
        then exec "/opt/monit/bin/monit -c /opt/monit/conf/monitrc reload"
    
    check system $HOST
        group system
        if loadavg (1min) > 4 for 2 cycles then alert
        if loadavg (5min) > 2 for 2 cycles then alert
        if memory usage > 80% for 5 cycles then alert
        if swap usage > 65% then alert
        if cpu usage (user) > 95% for 4 times within 5 cycles then alert
        if cpu usage (system) > 85% for 4 times within 5 cycles  then alert
        if cpu usage (wait) > 65% for 4 times within 5 cycles then alert
    
    check filesystem root with path /
        group system
        if space usage > 85% for 5 times within 15 cycles then alert
    
    check network public with interface eth0
        if failed link then alert
        if changed link then alert
        if saturation > 90% then alert
        if download > 20 MB/s then alert
        if total upload > 100 GB in last hour then alert
    
    include /opt/monit/monit.s/*
    
  3. Anwar Xiao

    Here's what I'm doing in the docker back to the details:

    root@c6f6e22d5081:~# hostname -f
    c6f6e22d5081
    root@c6f6e22d5081:~# hostname -i
    172.10.0.6
    

    As I understand, the monit variable $HOST should not be the result of the hostname -f return; and the response is the result of the hostname -i return.

  4. Tildeslash repo owner

    Thank you for data.

    Monit expands the $HOST to a name, which should match output of "hostname" command-line utility with no options.

    When alert is triggered, the hostname is mapped to a FQDN name using getaddrinfo().

    Please can you provide output of following commands?:

    hostname
    hostname --all-fqdns 
    grep c6f6e22d5081 /etc/hosts
    
  5. Anwar Xiao

    from docker container, the output of following:

    root@4c481dc8ed0b:~# hostname
    4c481dc8ed0b
    root@4c481dc8ed0b:~# hostname --all-fqdns 
    4c481dc8ed0b 
    root@4c481dc8ed0b:~# grep 4c481dc8ed0b /etc/hosts
    172.10.0.5  4c481dc8ed0b
    root@4c481dc8ed0b:~#
    
  6. Tildeslash repo owner

    Thanks for data. I think the problem may be related to issues #559 and #537 - the AI_ADDRCONFIG can reduce the getaddrinfo() result set.

    Please can you test with Monit 5.21.0?

  7. Anwar Xiao

    I have been test, this issue not fix.

    In fact, my idea is very simple, that is, in the docker container, when the alarm, Host docker IP, there are host IP.

    Such as the host IP is: 10.0.4.9, started three docker, docker ip were 172.18.1.4, 172.18.1.5, 172.18.1.6

    At this point when the docker container monit alarm, Host should be:

    Host: 10.0.4.9_172.18.1.4
    or
    Host: 10.0.4.9_172.18.1.5
    or
    Host: 10.0.4.9_172.18.1.6
    

    So that in a cluster environment it is easy to know which physical machine that a Docker alarm

  8. Tildeslash repo owner

    adding custom hostname to monit configuration is simple, just use string instead of "$HOST" macro in "check system", for example:

    check system "10.0.4.9_172.18.1.4"
    
  9. Log in to comment