Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
Community Edition
-
None
-
Ubuntu 18.04 LTS
PostgreSQL 12
Description
Hello,
I successfully integrated MySQL and MongoDB application monitorings. However, PostgreSQL with Perl script fails.
- Parses the wrong version (Ubuntu 7.4.0-1ubuntu1~18.04.1 becomes version?)
- Fails to initialize data from PG.
/usr/lib/observium_agent/local# /usr/lib/observium_agent/local/postgresql.pl
|
<<<app-postgresql>>>
|
version:7.4 |
cCount:0 |
tDbs:0 |
tUsr:0 |
tHst:0 |
idle:0 |
select:0 |
update:0 |
delete:0 |
other:0 |
Use of uninitialized value in concatenation (.) or string at /usr/lib/observium_agent/local/postgresql.pl line 161. |
xact_commit:
|
Use of uninitialized value in concatenation (.) or string at /usr/lib/observium_agent/local/postgresql.pl line 162. |
xact_rollback:
|
Use of uninitialized value in concatenation (.) or string at /usr/lib/observium_agent/local/postgresql.pl line 163. |
blks_read:
|
Use of uninitialized value in concatenation (.) or string at /usr/lib/observium_agent/local/postgresql.pl line 164. |
blks_hit:
|
Use of uninitialized value in concatenation (.) or string at /usr/lib/observium_agent/local/postgresql.pl line 166. |
tup_returned:
|
Use of uninitialized value in concatenation (.) or string at /usr/lib/observium_agent/local/postgresql.pl line 167. |
tup_fetched:
|
Use of uninitialized value in concatenation (.) or string at /usr/lib/observium_agent/local/postgresql.pl line 168. |
tup_inserted:
|
Use of uninitialized value in concatenation (.) or string at /usr/lib/observium_agent/local/postgresql.pl line 169. |
tup_updated:
|
Use of uninitialized value in concatenation (.) or string at /usr/lib/observium_agent/local/postgresql.pl line 170. |
tup_deleted:
|
select version()
|
PostgreSQL 12.2 (Ubuntu 12.2-2.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0, 64-bit |
I have had some time and rewrote the original Perl script to Python3 with a mind that I can add my own functionality. However, I don't understand how to calculate the data from PG which keeps increasing from the beginning. I understand that Ivan subtracted the numbers every 5 minutes, but the question remains where the state was kept?
Sharing my script attempt:
#!/usr/bin/env python3
##: Author: Tomas Andriekus @ <t.andriekus at gmail dot com>
# Please *SECURE your credentials*
SELECT datname, usename, client_addr, query FROM pg_stat_activity WHERE client_addr is not NULL;
SELECT SUM(xact_commit) as xact_commit, SUM(xact_rollback) as xact_rollback, SUM(blks_read) as blks_read,
SUM(blks_hit) as blks_hit, SUM(tup_returned) as tup_returned, SUM(tup_fetched) as tup_fetched,
SUM(tup_inserted) as tup_inserted, SUM(tup_updated) as tup_updated, SUM(tup_deleted) as tup_deleted
FROM pg_stat_database;
version = []
pg_commits = {}
pg_datnames = []
pg_usenames = []
pg_client_addrs = []
pg_idle = []
pg_select = []
pg_insert = []
pg_update = []
pg_delete = []
pg_other = []
def analyze_pg_version(pg_ver):
# This should never happen.
def execute_pg_statement(cursor, statement):
cursor.execute(statement)
data = cursor.fetchall()
def aggregate_connections_data(data):
count = len(data)
seen_datnames = set(pg_datnames)
seen_usenames = set(pg_usenames)
seen_client_addrs = set(pg_client_addrs)
def aggregate_commits(data):
def fetch():
conn = psycopg2.connect(host=db_host, user=db_user, password=db_pass, database=db_name)
version.append(analyze_pg_version(conn.server_version))
cursor = conn.cursor()
# Execute SQL queries;
pg_activity_result = execute_pg_statement(cursor, PG_ACTIVITY)
aggregate_connections_data(pg_activity_result)
pg_num_activity_result = execute_pg_statement(cursor, NUM_COMMITS)
except (Exception, psycopg2.DatabaseError) as error:
print(error)
conn.close()
fetch()
Thanks!