YavarTechWorks
Published in

YavarTechWorks

Netdata configuration with PostgreSQL

In this article, I will explain the Netdata and PostgreSQL configuration.

Google image

In one of my article, I explained about Netdata installation. If you are not installed Netdata in your machine please go through this link and install it. After install move to Postgres configuration.

Installation required

  • PostgreSQL
  • python-psycopg2
$ sudo apt-get install postgresql

For python-psycopg2 the installation we need pip. Pip is a package management system that simplifies installation and management of software packages written in Python such as those found in the Python Package Index (PyPI).

Pip installation

$ sudo apt update
$ sudo apt install python-pip
$ pip --version

Once installed install python-psycopg2 .

$ pip install psycopg2

After finished all installation move to the configuration part.

Configuration Netdata and Postgres

Access Netdata

We installed Netdata in our machine using docker. So we need to access docker container.

$ docker container ls
$ docker exec -it <container name> /bin/bash

Below I have given an example of access Netdata bash terminal using container name.

$ docker exec -it netdata /bin/bash

Using the above command we can access the bash terminal of Netdata.

$ cd /etc/netdata
$ ./edit-config python.d/postgres.conf

When no configuration file is found, the module tries to connect to TCP/IP socket: localhost:5432.

socket:
name : 'socket'
user : 'postgres'
database : 'postgres'
tcp:
name : 'tcp'
user : 'postgres'
database : 'postgres'
host : 'localhost'
port : 5432

Here we have to update socket then it reflects in our browser.

In that example there two methods one is TCP and socket. It is the different ways of user communicate with the Postgres database.

The default method is the socket. It will only listen for connections to a local Unix socket. The location of this socket is defined by the PostgreSQL configuration variable unix_socket_directories . We can run psql comment with no arguments but it manages to connect the database. This works because psql uses the PostgreSQL supplied client library (libpq) and this client library has the default behaviour of connecting to the local Unix socket if no hostname is supplied.

In the TCP method, we are connecting the database using the IP address localhost .

tcp:
name : 'local'
database : 'project1-dev'
user : 'edison'
host : 'localhost'
password : 'password'
port : 5432

The above is an example of setting a Postgres configuration using TCP method. In the configuration, I set the password as one of the fields because it needed to make a connection.

If these changes want to reflect in our machine we need to run docker again.

$ docker stop <Container id>
$ docker start <Container id>

Below I have given an example of running the docker again.

$ docker stop b3c310ebe66e
$ docker start b3c310ebe66e

Open the Netdata browser and you can see the output.

Example

Sample output

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Edison Devadoss

Edison Devadoss

Software developer / JavaScript / React / React Native / Firebase / Node.js / C Programming / Book Reader / Story Teller