From 989798af04ce838d6a7d13bc91fb03e1d64888f9 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 19 Mar 2020 05:21:47 +0000 Subject: [PATCH 01/11] Update pg requirement from = 1.2.2 to = 1.2.3 Updates the requirements on [pg](https://github.com/ged/ruby-pg) to permit the latest version. - [Release notes](https://github.com/ged/ruby-pg/releases) - [Changelog](https://github.com/ged/ruby-pg/blob/master/History.rdoc) - [Commits](https://github.com/ged/ruby-pg/commits) Signed-off-by: dependabot-preview[bot] --- sensu-plugins-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sensu-plugins-postgres.gemspec b/sensu-plugins-postgres.gemspec index d851f12..224ea78 100644 --- a/sensu-plugins-postgres.gemspec +++ b/sensu-plugins-postgres.gemspec @@ -39,7 +39,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'sensu-plugin', '~> 4.0' s.add_runtime_dependency 'dentaku', '3.3.4' - s.add_runtime_dependency 'pg', '1.2.2' + s.add_runtime_dependency 'pg', '1.2.3' s.add_development_dependency 'bundler', '~> 2.1' s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0' From 4e18e890060c88bfde5423b9705335d508503096 Mon Sep 17 00:00:00 2001 From: Patrick Humpal Date: Sun, 29 Nov 2020 12:22:13 -0600 Subject: [PATCH 02/11] Find the total size of largest tables (#155) * Find the total size of largest tables * update changelog * appease the cops Co-authored-by: Ben Abrams --- CHANGELOG.md | 2 + README.md | 1 + bin/metric-postgres-relation-size.rb | 118 +++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100755 bin/metric-postgres-relation-size.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index e1b2a3c..bd34307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md). ## [Unreleased] +### Added +- new `bin/metric-postgres-relation-size.rb` find largest tables (@phumpal) ## [4.1.0] - 2020-06-04 ### Added diff --git a/README.md b/README.md index addbb06..0486c52 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ * bin/metric-postgres-statsio.rb * bin/check-postgres-query.rb * bin/metrics-postgres-query.rb + * bin/metric-postgres-relation-size.rb ## Usage diff --git a/bin/metric-postgres-relation-size.rb b/bin/metric-postgres-relation-size.rb new file mode 100755 index 0000000..efd2b05 --- /dev/null +++ b/bin/metric-postgres-relation-size.rb @@ -0,0 +1,118 @@ +#! /usr/bin/env ruby +# frozen_string_literal: false + +# metrics-postgres-relation-size.rb +# DESCRIPTION: +# +# This plugin finds the total size of the largest tables. +# +# https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADMIN-DBOBJECT +# +# OUTPUT: +# metric data +# +# PLATFORMS: +# Linux +# +# DEPENDENCIES: +# gem: sensu-plugin +# gem: pg +# +# USAGE: +# ./metric-postgres-relation-size.rb -u db_user -p db_pass -h db_host -d db +# +# NOTES: +# +# LICENSE: +# Copyright (c) 2020 Airbrake Technologies, Inc +# Author Patrick Humpal +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. +# + +require 'sensu-plugins-postgres/pgpass' +require 'sensu-plugin/metric/cli' +require 'pg' +require 'socket' + +class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite + option :pgpass, + description: 'Pgpass file', + short: '-f FILE', + long: '--pgpass', + default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass" + + option :user, + description: 'Postgres User', + short: '-u USER', + long: '--user USER' + + option :password, + description: 'Postgres Password', + short: '-p PASS', + long: '--password PASS' + + option :hostname, + description: 'Hostname to login to', + short: '-h HOST', + long: '--hostname HOST' + + option :port, + description: 'Database port', + short: '-P PORT', + long: '--port PORT' + + option :database, + description: 'Database name', + short: '-d DB', + long: '--db DB' + + option :scheme, + description: 'Metric naming scheme, text to prepend to $queue_name.$metric', + long: '--scheme SCHEME', + default: "#{Socket.gethostname}.postgresql" + + option :timeout, + description: 'Connection timeout (seconds)', + short: '-T TIMEOUT', + long: '--timeout TIMEOUT', + default: nil + + option :limit, + description: 'Limit query to this many results', + short: '-L LIMIT', + login: '--limit LIMIT', + default: 25 + + include Pgpass + + def run + timestamp = Time.now.to_i + pgpass + con = PG.connect(host: config[:hostname], + dbname: config[:database], + user: config[:user], + password: config[:password], + port: config[:port], + connect_timeout: config[:timeout]) + + # https://wiki.postgresql.org/wiki/Disk_Usage + request = [ + "SELECT nspname || '.' || relname AS relation, + pg_total_relation_size(C.oid) AS total_size + FROM pg_class C + LEFT JOIN pg_namespace N on (N.oid = C.relnamespace) + WHERE nspname NOT IN ('pg_catalog', 'information_schema') + ORDER BY pg_total_relation_size(C.oid) DESC + LIMIT '#{config[:limit]}'" + ] + + con.exec(request.join(' ')) do |result| + result.each do |row| + output "#{config[:scheme]}.size.#{config[:database]}.#{row['relation']}", row['total_size'], timestamp + end + end + + ok + end +end From ba2428185b7ad24ae806e7e67ab78d34035c0e69 Mon Sep 17 00:00:00 2001 From: Ben Abrams Date: Sun, 29 Nov 2020 10:52:32 -0800 Subject: [PATCH 03/11] prep for 4.2.0 release Signed-off-by: Ben Abrams --- CHANGELOG.md | 5 ++++- lib/sensu-plugins-postgres/version.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd34307..55338c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md). ## [Unreleased] + +## [4.2.0] - 2020-11-29 ### Added - new `bin/metric-postgres-relation-size.rb` find largest tables (@phumpal) @@ -219,7 +221,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins ### Added - initial release -[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.1.0...HEAD +[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.2.0...HEAD +[4.2.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.1.0...4.2.0 [4.1.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.0.2...4.1.0 [4.0.2]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.0.1...4.0.2 [4.0.1]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.0.0...4.0.1 diff --git a/lib/sensu-plugins-postgres/version.rb b/lib/sensu-plugins-postgres/version.rb index 24610d4..60acc0a 100644 --- a/lib/sensu-plugins-postgres/version.rb +++ b/lib/sensu-plugins-postgres/version.rb @@ -3,7 +3,7 @@ module SensuPluginsPostgres module Version MAJOR = 4 - MINOR = 1 + MINOR = 2 PATCH = 0 VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.') From 9ff9f312fe9253e07b336e3aea879154c336238b Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 2 Apr 2021 05:19:35 +0000 Subject: [PATCH 04/11] Update github-markup requirement from ~> 3.0 to ~> 4.0 Updates the requirements on [github-markup](https://github.com/github/markup) to permit the latest version. - [Release notes](https://github.com/github/markup/releases) - [Changelog](https://github.com/github/markup/blob/master/HISTORY.md) - [Commits](https://github.com/github/markup/compare/v3.0.0...v4.0.0) Signed-off-by: dependabot-preview[bot] --- sensu-plugins-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sensu-plugins-postgres.gemspec b/sensu-plugins-postgres.gemspec index 224ea78..df96a89 100644 --- a/sensu-plugins-postgres.gemspec +++ b/sensu-plugins-postgres.gemspec @@ -43,7 +43,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'bundler', '~> 2.1' s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0' - s.add_development_dependency 'github-markup', '~> 3.0' + s.add_development_dependency 'github-markup', '~> 4.0' s.add_development_dependency 'kitchen-docker', '~> 2.6' s.add_development_dependency 'kitchen-localhost', '~> 0.3' s.add_development_dependency 'mixlib-shellout', '~> 2.4' From a7e0fea3200644dc1880167d00ad5df7c26b38be Mon Sep 17 00:00:00 2001 From: Michalek Date: Tue, 24 Nov 2020 12:55:13 +0100 Subject: [PATCH 05/11] Added generic debian build --- .bonsai.yml | 9 ++++++++- CHANGELOG.md | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.bonsai.yml b/.bonsai.yml index cf5e417..8562dbe 100644 --- a/.bonsai.yml +++ b/.bonsai.yml @@ -63,4 +63,11 @@ builds: - "entity.system.arch == 'amd64'" - "entity.system.platform_family == 'debian'" - "entity.system.platform_version.split('.')[0] == '9'" - +- platform: "debian" + arch: "amd64" + asset_filename: "#{repo}_#{version}_debian_linux_amd64.tar.gz" + sha_filename: "#{repo}_#{version}_sha512-checksums.txt" + filter: + - "entity.system.os == 'linux'" + - "entity.system.arch == 'amd64'" + - "entity.system.platform_family == 'debian'" diff --git a/CHANGELOG.md b/CHANGELOG.md index 55338c9..f9964c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md). ## [Unreleased] +### Added +- asset for generic debian build (including ubuntu) (@VeselaHouba) ## [4.2.0] - 2020-11-29 ### Added From 6f3a42522e564c63ef76bad13534365b4c755170 Mon Sep 17 00:00:00 2001 From: Jef Spaleta Date: Wed, 15 Sep 2021 15:30:07 -0800 Subject: [PATCH 06/11] preparing for 4.3.0 release --- CHANGELOG.md | 5 ++++- lib/sensu-plugins-postgres/version.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9964c7..8efde9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md). ## [Unreleased] +## [4.3.0] - 2021-09-15 + ### Added - asset for generic debian build (including ubuntu) (@VeselaHouba) @@ -223,7 +225,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins ### Added - initial release -[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.2.0...HEAD +[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.3.0...HEAD +[4.3.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.2.0...4.3.0 [4.2.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.1.0...4.2.0 [4.1.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.0.2...4.1.0 [4.0.2]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.0.1...4.0.2 diff --git a/lib/sensu-plugins-postgres/version.rb b/lib/sensu-plugins-postgres/version.rb index 60acc0a..f180007 100644 --- a/lib/sensu-plugins-postgres/version.rb +++ b/lib/sensu-plugins-postgres/version.rb @@ -3,7 +3,7 @@ module SensuPluginsPostgres module Version MAJOR = 4 - MINOR = 2 + MINOR = 3 PATCH = 0 VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.') From 1f3154bed96442c7cf49e4624628b6f18a191870 Mon Sep 17 00:00:00 2001 From: Jef Spaleta Date: Wed, 15 Sep 2021 16:25:49 -0800 Subject: [PATCH 07/11] fix for centos6 asset build, using centOS 6 package repository archive --- asset_build_scripts/Dockerfile.centos6 | 1 + 1 file changed, 1 insertion(+) diff --git a/asset_build_scripts/Dockerfile.centos6 b/asset_build_scripts/Dockerfile.centos6 index 30d91aa..8b09c28 100644 --- a/asset_build_scripts/Dockerfile.centos6 +++ b/asset_build_scripts/Dockerfile.centos6 @@ -6,6 +6,7 @@ ARG GREP_EXCLUDE='(ld.so|ld-linux-x86-64.so|libBrokenLocale.so|libSegFault.so|li ARG RUBY_VERSION=2.4.4 WORKDIR /assets/build/ +RUN curl https://www.getpagespeed.com/files/centos6-eol.repo --output /etc/yum.repos.d/CentOS-Base.repo RUN yum install -y git RUN yum install -y https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm RUN yum install -y postgresql95 postgresql95-libs postgresql95-devel From f27efb07ef422312f8d8a8ab8a33e983e57fe81e Mon Sep 17 00:00:00 2001 From: Jef Spaleta Date: Wed, 15 Sep 2021 16:26:48 -0800 Subject: [PATCH 08/11] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8efde9d..1ffcda1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins ### Added - asset for generic debian build (including ubuntu) (@VeselaHouba) +### Fixed +- Fixing asset build directive for centos6, using package repository archive now that centos6 is EOL + ## [4.2.0] - 2020-11-29 ### Added - new `bin/metric-postgres-relation-size.rb` find largest tables (@phumpal) From 58717afe5edec9915f4ab873d7cde0ceca30f5dd Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 19 Jul 2021 05:16:19 +0000 Subject: [PATCH 09/11] Update dentaku requirement from = 3.3.4 to = 3.4.2 Updates the requirements on [dentaku](https://github.com/rubysolo/dentaku) to permit the latest version. - [Release notes](https://github.com/rubysolo/dentaku/releases) - [Changelog](https://github.com/rubysolo/dentaku/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubysolo/dentaku/compare/v3.3.4...v3.4.2) Signed-off-by: dependabot-preview[bot] --- sensu-plugins-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sensu-plugins-postgres.gemspec b/sensu-plugins-postgres.gemspec index df96a89..98d4299 100644 --- a/sensu-plugins-postgres.gemspec +++ b/sensu-plugins-postgres.gemspec @@ -38,7 +38,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'sensu-plugin', '~> 4.0' - s.add_runtime_dependency 'dentaku', '3.3.4' + s.add_runtime_dependency 'dentaku', '3.4.2' s.add_runtime_dependency 'pg', '1.2.3' s.add_development_dependency 'bundler', '~> 2.1' From 6a03fbe25931ad9cc28e49e10cd12223e2df2de8 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 29 Apr 2021 15:04:46 +0000 Subject: [PATCH 10/11] Upgrade to GitHub-native Dependabot --- .github/dependabot.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..8e6be22 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,14 @@ +version: 2 +updates: +- package-ecosystem: bundler + directory: "/" + schedule: + interval: daily + ignore: + - dependency-name: rubocop + versions: + - 1.10.0 + - 1.11.0 + - 1.12.0 + - 1.9.0 + - 1.9.1 From 291f900486fd959b8a20d81173fe3f63ae022bbe Mon Sep 17 00:00:00 2001 From: Jef Spaleta Date: Wed, 15 Sep 2021 17:00:22 -0800 Subject: [PATCH 11/11] .bonsai.yml --- asset_build_scripts/Dockerfile.centos8 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 asset_build_scripts/Dockerfile.centos8 diff --git a/asset_build_scripts/Dockerfile.centos8 b/asset_build_scripts/Dockerfile.centos8 new file mode 100644 index 0000000..5d5709e --- /dev/null +++ b/asset_build_scripts/Dockerfile.centos8 @@ -0,0 +1,25 @@ +FROM sensu/sensu-ruby-runtime-2.4.4-centos8:latest as builder +ARG ASSET_GEM +ARG GIT_REF +ARG GIT_REPO +ARG GREP_EXCLUDE='(ld.so|ld-linux-x86-64.so|libBrokenLocale.so|libSegFault.so|libanl.so|libc.so|libdl.so|libm.so|libmvec.so|libnss_compat.so|libnss_dns.so|libnss_files.so|libpthread.so|libresolv.so|librt.so|libthread_db.so|libutil.so|vdso.so)' +ARG RUBY_VERSION=2.4.4 + +WORKDIR /assets/build/ +RUN yum install -y git +RUN yum install -y https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm +RUN yum config-manager --disable pgdg* +RUN yum config-manager --enable pgdg95 +RUN yum list "postgresql95*" +RUN yum install --disablerepo=appstream -y postgresql95 postgresql95-libs postgresql95-devel +ENV CONFIGURE_ARGS="with-pg-config=/usr/pgsql-9.5/bin/pg_config" + +RUN \ + gem install --no-ri --no-doc bundler && \ + printf "source 'https://rubygems.org'\n\ngem \"%s\", :git => \"%s\" , :ref => \"%s\"\n" ${ASSET_GEM} ${GIT_REPO} ${GIT_REF}| tee Gemfile +RUN bundle install --path=lib/ --binstubs=bin/ --standalone +RUN tar -czf /assets/${ASSET_GEM}.tar.gz -C /assets/build/ . + +FROM scratch +ARG ASSET_GEM +COPY --from=builder /assets/${ASSET_GEM}.tar.gz /