Zabbix customize report with Grafana and PostgreSQL
Direct fetching data from Zabbix database (PostgreSQL) with Grafana data source.
Published Dec 1, 2024
- Step1: PostgreSQL accessibility configuration
- Step2: Add PostgreSQL data source in Grafana
- Step3: Queries from Zabbix tables in PostgreSQL
- Step4: Create Grafana visualization panel
This step is for when your Grafana-server and Postgresql lunched on split server with Zabbix-server.
Step1.PostgreSQL accessibility configuration
First, you need check your PostgreSQL configuration file in
pg_hba.conf
under path:/etc/postgres/YOUR_POSTGRES_VERSION/main/
for access from Grafana server:Add your Grafana-server IP address under
IPv4 local connections
and save it:After that you need restart postgresql.service:
Step2.Add PostgreSQL data source in Grafana
Login to your Grafana domain and go to connections tab and click on Data sources:
- Click on Add data source
- Search PostgreSQL and click it to open grafana-postgresql-datasource configuration
- Enter data-source Name(optional)
- Enter Host URL(postgresql server address: in our example: 10.10.10.90), Database name(example:zabbixDB) in Connection section
- Complete Username(zabbix) and Password(zabbixDBpass) in Authentication section
Database name and username and password saved in your /etc/zabbix/zabbix_server.conf file in your Zabbix server
Step3.Queries from Zabbix tables in PostgreSQL
Zabbix fetch data from own database for creatin graph and dashboard and any reports. But we need special report from zabbix database directly. for test and see custom query, we should login to postgresql (zabbix database) and write we own queries.
login to Postgresql and work in database environment
\l
list and show all databases in Postgresql\c
change database (same asuse
in MySQL)\dt
show all tables
Output:
Test Queries:
So I want join three tables(acknowledges, events and users) and make special query for reporting all events and find acknowledged events and who ack that:
Step4: Create Grafana visualization panel
Go to Dashboard menu in Grafana and click Create dashboard
- Click Add visualization
- Select grafana-postgresql-datasource
- Click on Code beside of Builder
- Write your query same as database cli terminal in code box and click on Run query button
Select Table from Visualization in side bar menu at right.
Conclusion
You can write any specified query from Zabbix database directly and create own table visualization in Grafana server.
Good Luck!