Ad Widget

Collapse

Problem with PostgreSQL monitoring

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Spectator
    Member
    • Sep 2021
    • 71

    #1

    Problem with PostgreSQL monitoring

    I have a Linux host, which I successfully monitor with active agent2 via an active proxy with the "Linux by Zabbix agent active" template.
    A PostreSQL database server runs on this linux host, which I would also like to monitor.

    I started based on this:


    I have successfully completed point 1 and point 2, so I have created zbx_user and modified pg_hba.conf.

    With this command, I can access the database with zbx_user on the linux host:
    Code:
    [root@test-zbx-db3 ~]# psql -Uzbx_monitor -W -p5432 -dpostgres
    Password:
    psql (14.5)
    Type "help" for help.
    
    postgres=>

    On the Zabbix web interface, "Configuration", "Hosts", click on the linux host. "Templates", "Select", add "PostgreSQL by Zabbix agent 2"

    On the "Macros" tab "Inherited and host macros".
    I give {$PG.USER} the zbx_monitor and {$PG.PASSWORD} the zbx_monitor user password.
    I also tried giving {$PG.URI} this: tcp://localhost:5432.
    Unfortunately, Postgres monitoring does not work.
    It writes this error message for Postgres items:
    Code:
    Connection failed: failed to connect to `host=localhost user=zbx_monitor database=postgres`: hostname resolving error (lookup localhost: device or resource busy).
    It writes similar error messages to the zabbix_agent2.log of the Linux host:
    Code:
    2022/11/02 17:58:16.145707 [Postgres] Connection failed: failed to connect to `host=localhost user=zbx_monitor database=postgres`: hostname resolving error (lookup localhost: device or resource busy)
    I tried leaving {$PG.URI} out of the macros, but the situation didn't change.

    I can ping localhost:
    Code:
    [root@test-zbx-db3 ~]# ping localhost
    PING localhost (127.0.0.1) 56(84) bytes of data.
    64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.035 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.024 ms
    ^C
    --- localhost ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1047ms
    rtt min/avg/max/mdev = 0.024/0.029/0.035/0.007 ms
    [root@test-zbx-db3 ~]#
    And I can telnet also to the port 5432:
    Code:
    [root@test-zbx-db3 ~]# telnet localhost 5432
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    quit
    Connection closed by foreign host.
    [root@test-zbx-db3 ~]#
    Zabbix version: 6.0.9
    OS version: Almalinux 8.6
    PostgreSQL version: 14.5

    What could be the problem? What am I messing up?
  • Spectator
    Member
    • Sep 2021
    • 71

    #2
    The situation has improved a little.

    In summary:
    Postgresql is running on a Linux machine with Agent 2 installed.
    I can measure this Linux machine perfectly with the "Linux by Zabbix agent active" template.
    I added the "PostgreSQL by Zabbix agent 2" template to this machine on the web interface.

    I started based on this:
    https://www.zabbix.com/integrations/...tgresql_agent2

    I have successfully completed point 1 and point 2, so I have created zbx_user and modified pg_hba.conf.​

    The linux measurements are fine.
    The PostgreSQL measurements are all "Unknown metrics", such as "Unknown metric pgsql.connections"

    In the macros, I set {$PG.USER} the zbx_monitor and {$PG.PASSWORD} the zbx_monitor user password.​

    Does anyone have an idea what the problem could be?​

    Comment

    • Spectator
      Member
      • Sep 2021
      • 71

      #3
      OK, so it is still necessary to install the zabbix-agent2-plugin-postgresql package on the PostgreSQL host.
      It is "great" that this is not mentioned anywhere in the official documentation


      I found the solution here:


      After that, it is sufficient to enter the user name and password in the macro.​

      Maybe this will help others in the future.​

      Comment

      • aspitzer
        Junior Member
        • Feb 2023
        • 11

        #4
        Originally posted by Spectator
        OK, so it is still necessary to install the zabbix-agent2-plugin-postgresql package on the PostgreSQL host.
        It is "great" that this is not mentioned anywhere in the official documentation


        I found the solution here:


        After that, it is sufficient to enter the user name and password in the macro.​

        Maybe this will help others in the future.​
        Awesome, thanks! I was just banging my head on this, but this helped!

        Comment

        • molnart
          Junior Member
          • Feb 2024
          • 5

          #5
          i still cannot get this up and running. initially i was trying to it according to this guide https://www.youtube.com/watch?v=Dw_2-SB-QKY but never got any postgres related data from the agent and the log was also very silent about anything, so no idea if the agent was actually able to connect to the db.
          then I have tried building the plugin from sources, but here I am just getting an error by the zabbix agent:
          Code:
          postgres zabbix_agent2[3865]: zabbix_agent2 [3865]: ERROR: Cannot assign configuration: invalid parameter data_directory at line 9: unknown parameter
          i have no idea where this line 9 is supposed to be, as neither zabbix_agent2.conf or postgresql.conf contain anything relevant at line 9

          also I have tried building different versions of the plugin, my zabbix-agent2 has version 6.0.14, but I have not not found the matching sources so tried a bunch of closest ones (unfortunately it looks like there is no postgres plugin in the debian repos)

          EDIT: solved by adding the zabbix repo to the system and installing the agent and the plugin from there. I hate it so much when i need to add foreign repos...
          Last edited by molnart; 25-08-2024, 21:26.

          Comment

          Working...