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/.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 diff --git a/CHANGELOG.md b/CHANGELOG.md index e1b2a3c..1ffcda1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ 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) + +### 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) ## [4.1.0] - 2020-06-04 ### Added @@ -217,7 +228,9 @@ 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.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 [4.0.1]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.0.0...4.0.1 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/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 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 / 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 diff --git a/lib/sensu-plugins-postgres/version.rb b/lib/sensu-plugins-postgres/version.rb index 24610d4..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 = 1 + MINOR = 3 PATCH = 0 VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.') diff --git a/sensu-plugins-postgres.gemspec b/sensu-plugins-postgres.gemspec index d851f12..98d4299 100644 --- a/sensu-plugins-postgres.gemspec +++ b/sensu-plugins-postgres.gemspec @@ -38,12 +38,12 @@ 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 'dentaku', '3.4.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' - 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'