-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PostgreSQL agent script for CE #3
Comments
#!/usr/bin/env perl PostgreSQL stats script for Observiumuse warnings; --- Configuration ---my $DEBUG = 1; # Enable debug output --- Variables ---my ($drvName, $hostName, $dbUser, $dbPass, $dbName, $conn, $query, $all, $version, $cmd); --- Functions ---Debugging and error handlingsub debug { Find duplicates in arrayssub findDup { Execute an SQL command and return a single array resultsub sqlArray { Execute an SQL command and return a hash referencesub sqlHashRef { --- Main Script ---Load configuration from postgresql.confopen(my $confFH, '<', $confFile) or debug("Error opening debug("Parsed Config: Driver=$drvName, Host=$hostName, User=$dbUser, DB=$dbName"); Connect to the PostgreSQL database$conn = DBI->connect("DBI:$drvName:dbname=$dbName;host=$hostName", $dbUser, $dbPass, { debug("Connected to database: $dbName"); Get PostgreSQL version$cmd = "SELECT version()"; Fallback if version is not detectedif (!$version) { debug("PostgreSQL Version: $version"); Match major versions like 8.x, 9.x, 10.x through 14.x, ignoring minor versionsif ($version =~ /^([89]|1[0-4]).\d+/) { Collect activity stats$all = sqlHashRef($cmd);
} debug("Collected stats: Connections=$cCount, Idle=$idle, Select=$select, Update=$update, Delete=$delete, Other=$other"); Collect database stats$cmd = "SELECT SUM(xact_commit) AS xact_commit, SUM(xact_rollback) AS xact_rollback, SUM(blks_read) AS blks_read, Clean up$query->finish(); debug("Disconnected from database"); Print resultsprint "<<>>\n"; |
Any plans on updating for psql v10+
Thanks
The text was updated successfully, but these errors were encountered: