riemann-tools 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +11 -0
  3. data/.github/workflows/ci.yml +13 -0
  4. data/.github/workflows/codeql-analysis.yml +72 -0
  5. data/.rubocop.yml +32 -0
  6. data/CHANGELOG.md +31 -2
  7. data/README.markdown +8 -24
  8. data/Rakefile +4 -2
  9. data/SECURITY.md +42 -0
  10. data/bin/riemann-apache-status +92 -78
  11. data/bin/riemann-bench +54 -49
  12. data/bin/riemann-cloudant +44 -40
  13. data/bin/riemann-consul +82 -76
  14. data/bin/riemann-dir-files-count +53 -47
  15. data/bin/riemann-dir-space +53 -47
  16. data/bin/riemann-diskstats +78 -75
  17. data/bin/riemann-fd +68 -48
  18. data/bin/riemann-freeswitch +108 -103
  19. data/bin/riemann-haproxy +46 -40
  20. data/bin/riemann-health +4 -343
  21. data/bin/riemann-kvminstance +18 -13
  22. data/bin/riemann-memcached +35 -29
  23. data/bin/riemann-net +4 -104
  24. data/bin/riemann-nginx-status +74 -67
  25. data/bin/riemann-ntp +4 -33
  26. data/bin/riemann-portcheck +40 -31
  27. data/bin/riemann-proc +96 -90
  28. data/bin/riemann-varnish +51 -45
  29. data/bin/riemann-zookeeper +38 -34
  30. data/lib/riemann/tools/health.rb +347 -0
  31. data/lib/riemann/tools/net.rb +104 -0
  32. data/lib/riemann/tools/ntp.rb +41 -0
  33. data/lib/riemann/tools/version.rb +1 -1
  34. data/lib/riemann/tools.rb +37 -40
  35. data/riemann-tools.gemspec +4 -1
  36. data/tools/riemann-aws/{Rakefile.rb → Rakefile} +2 -0
  37. data/tools/riemann-aws/bin/riemann-aws-billing +72 -66
  38. data/tools/riemann-aws/bin/riemann-aws-rds-status +55 -41
  39. data/tools/riemann-aws/bin/riemann-aws-sqs-status +37 -31
  40. data/tools/riemann-aws/bin/riemann-aws-status +63 -51
  41. data/tools/riemann-aws/bin/riemann-elb-metrics +149 -148
  42. data/tools/riemann-aws/bin/riemann-s3-list +70 -65
  43. data/tools/riemann-aws/bin/riemann-s3-status +85 -82
  44. data/tools/riemann-chronos/{Rakefile.rb → Rakefile} +2 -0
  45. data/tools/riemann-chronos/bin/riemann-chronos +136 -119
  46. data/tools/riemann-docker/{Rakefile.rb → Rakefile} +2 -0
  47. data/tools/riemann-docker/bin/riemann-docker +163 -174
  48. data/tools/riemann-elasticsearch/{Rakefile.rb → Rakefile} +2 -0
  49. data/tools/riemann-elasticsearch/bin/riemann-elasticsearch +155 -147
  50. data/tools/riemann-marathon/{Rakefile.rb → Rakefile} +2 -0
  51. data/tools/riemann-marathon/bin/riemann-marathon +138 -122
  52. data/tools/riemann-mesos/{Rakefile.rb → Rakefile} +2 -0
  53. data/tools/riemann-mesos/bin/riemann-mesos +125 -110
  54. data/tools/riemann-munin/{Rakefile.rb → Rakefile} +2 -0
  55. data/tools/riemann-munin/bin/riemann-munin +28 -22
  56. data/tools/riemann-rabbitmq/{Rakefile.rb → Rakefile} +2 -0
  57. data/tools/riemann-rabbitmq/bin/riemann-rabbitmq +226 -222
  58. data/tools/riemann-riak/{Rakefile.rb → Rakefile} +2 -0
  59. data/tools/riemann-riak/bin/riemann-riak +281 -289
  60. data/tools/riemann-riak/riak_status/riak_status.rb +39 -39
  61. metadata +65 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4c06d1c46f6c9c6d78ac614c29ee04f62d18227b2f306719185efcfd3747f56
4
- data.tar.gz: e71e90f111b57c7466ac0a6d33e0111525e8192e5c152b64903644bf8be92aa2
3
+ metadata.gz: 32ac83ea47b36e6632eea36cb430b0c9547b0aaecc3be6b7e10098c8a4c8c5fe
4
+ data.tar.gz: 4227da1e9388eb3d2b831071db0b21132b51d834167ddfa54c57faa57360672b
5
5
  SHA512:
6
- metadata.gz: d598a191d654c8be5cdd9d32bd5f99d54f3f86fb062022f4b9ab84b48c8d2cfc5cef2929354082d2b3796c0eb5d7f79dfdf789bfec5b222f295066fb7ca95332
7
- data.tar.gz: 0fddd305b30cbdac305a5bcd8cff3f3b139285d9e0d53a27019b5dcf70c12b9b0d29177460b166c7f7d70d1f1cc85d39d11e22c08c47153ef02b49478de80253
6
+ metadata.gz: 4a218c867ea61f0cb64f581e386861f22a28fcf9a8ab24870ceb20d7239a0224e33df98a0364b513a984d2317695a482257039367ca65eb249f6f8e625b24ba1
7
+ data.tar.gz: e8310afa539023c8dffb2e3ed3ccf91ebc703ff3939a730823b0001ffa75e9ac28e61f0a014bd8582880900566d6bf2f633e6119d5dd662b1ce97b399e052e66
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "daily"
@@ -10,11 +10,24 @@ on:
10
10
  - main
11
11
 
12
12
  jobs:
13
+ lint:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Setup ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: '2.7'
21
+ bundler-cache: true
22
+ - name: Run rubocop
23
+ run: bundle exec rubocop
13
24
  test:
25
+ needs: lint
14
26
  runs-on: ubuntu-latest
15
27
  strategy:
16
28
  matrix:
17
29
  ruby-version:
30
+ - 2.6
18
31
  - 2.7
19
32
  - 3.0
20
33
  - 3.1
@@ -0,0 +1,72 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL"
13
+
14
+ on:
15
+ push:
16
+ branches: [ "main" ]
17
+ pull_request:
18
+ # The branches below must be a subset of the branches above
19
+ branches: [ "main" ]
20
+ schedule:
21
+ - cron: '27 16 * * 6'
22
+
23
+ jobs:
24
+ analyze:
25
+ name: Analyze
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ actions: read
29
+ contents: read
30
+ security-events: write
31
+
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ language: [ 'ruby' ]
36
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
+ # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
38
+
39
+ steps:
40
+ - name: Checkout repository
41
+ uses: actions/checkout@v3
42
+
43
+ # Initializes the CodeQL tools for scanning.
44
+ - name: Initialize CodeQL
45
+ uses: github/codeql-action/init@v2
46
+ with:
47
+ languages: ${{ matrix.language }}
48
+ # If you wish to specify custom queries, you can do so here or in a config file.
49
+ # By default, queries listed here will override any specified in a config file.
50
+ # Prefix the list here with "+" to use these queries and those in the config file.
51
+
52
+ # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
53
+ # queries: security-extended,security-and-quality
54
+
55
+
56
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57
+ # If this step fails, then you should remove it and run the build manually (see below)
58
+ - name: Autobuild
59
+ uses: github/codeql-action/autobuild@v2
60
+
61
+ # ℹ️ Command-line programs to run using the OS shell.
62
+ # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
63
+
64
+ # If the Autobuild fails above, remove it and uncomment the following three lines.
65
+ # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
66
+
67
+ # - run: |
68
+ # echo "Run, Build Application using script"
69
+ # ./location_of_script_within_repo/buildscript.sh
70
+
71
+ - name: Perform CodeQL Analysis
72
+ uses: github/codeql-action/analyze@v2
data/.rubocop.yml ADDED
@@ -0,0 +1,32 @@
1
+ ---
2
+ Layout/HashAlignment:
3
+ EnforcedHashRocketStyle: table
4
+ Layout/LineLength:
5
+ Enabled: false
6
+ Metrics/AbcSize:
7
+ Enabled: false
8
+ Metrics/BlockLength:
9
+ Enabled: false
10
+ Metrics/ClassLength:
11
+ Enabled: false
12
+ Metrics/CyclomaticComplexity:
13
+ Enabled: false
14
+ Metrics/MethodLength:
15
+ Enabled: false
16
+ Metrics/ParameterLists:
17
+ Enabled: false
18
+ Metrics/PerceivedComplexity:
19
+ Enabled: false
20
+ Naming/MethodParameterName:
21
+ AllowedNames:
22
+ - az # availability zone
23
+ - id
24
+ - lb # load balancer
25
+ Style/Documentation:
26
+ Enabled: false
27
+ Style/TrailingCommaInArguments:
28
+ EnforcedStyleForMultiline: consistent_comma
29
+ Style/TrailingCommaInArrayLiteral:
30
+ EnforcedStyleForMultiline: consistent_comma
31
+ Style/TrailingCommaInHashLiteral:
32
+ EnforcedStyleForMultiline: consistent_comma
data/CHANGELOG.md CHANGED
@@ -1,8 +1,37 @@
1
1
  # Changelog
2
2
 
3
- ## [1.0.0](https://github.com/riemann/riemann-tools/tree/1.0.0) (2022-06-21)
3
+ ## [1.1.0](https://github.com/riemann/riemann-tools/tree/1.1.0) (2022-07-01)
4
4
 
5
- [Full Changelog](https://github.com/riemann/riemann-tools/compare/0.2.14...1.0.0)
5
+ [Full Changelog](https://github.com/riemann/riemann-tools/compare/v1.0.0...1.1.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Report computed disk metric [\#213](https://github.com/riemann/riemann-tools/pull/213) ([smortex](https://github.com/smortex))
10
+ - Add support for FreeBSD system fd monitoring [\#204](https://github.com/riemann/riemann-tools/pull/204) ([smortex](https://github.com/smortex))
11
+ - Improve interface matching flexibility [\#203](https://github.com/riemann/riemann-tools/pull/203) ([smortex](https://github.com/smortex))
12
+ - Improve disk usage reporting [\#200](https://github.com/riemann/riemann-tools/pull/200) ([smortex](https://github.com/smortex))
13
+
14
+ **Fixed bugs:**
15
+
16
+ - Revert tmpfs as an ignored filesystem by default [\#206](https://github.com/riemann/riemann-tools/pull/206) ([smortex](https://github.com/smortex))
17
+ - Fix network interfaces reporting [\#202](https://github.com/riemann/riemann-tools/pull/202) ([smortex](https://github.com/smortex))
18
+ - Fix setting custom load thresholds [\#201](https://github.com/riemann/riemann-tools/pull/201) ([smortex](https://github.com/smortex))
19
+
20
+ **Closed issues:**
21
+
22
+ - Disk usage resolution is coarse [\#212](https://github.com/riemann/riemann-tools/issues/212)
23
+ - Load warning/critical doesn't work [\#182](https://github.com/riemann/riemann-tools/issues/182)
24
+
25
+ **Merged pull requests:**
26
+
27
+ - Modernized riemann-ntp and included warning for macOS [\#211](https://github.com/riemann/riemann-tools/pull/211) ([jamtur01](https://github.com/jamtur01))
28
+ - Create dependabot.yml [\#209](https://github.com/riemann/riemann-tools/pull/209) ([jamtur01](https://github.com/jamtur01))
29
+ - Create codeql-analysis.yml [\#208](https://github.com/riemann/riemann-tools/pull/208) ([jamtur01](https://github.com/jamtur01))
30
+ - Setup Rubocop [\#205](https://github.com/riemann/riemann-tools/pull/205) ([smortex](https://github.com/smortex))
31
+
32
+ ## [v1.0.0](https://github.com/riemann/riemann-tools/tree/v1.0.0) (2022-06-22)
33
+
34
+ [Full Changelog](https://github.com/riemann/riemann-tools/compare/0.2.14...v1.0.0)
6
35
 
7
36
  **Implemented enhancements:**
8
37
 
data/README.markdown CHANGED
@@ -1,5 +1,4 @@
1
- Riemann Tools
2
- =============
1
+ # Riemann Tools
3
2
 
4
3
  Tiny programs to submit events to Riemann.
5
4
 
@@ -9,18 +8,14 @@ randomly distributed metrics for load testing.
9
8
 
10
9
  [![Gem Version](https://badge.fury.io/rb/riemann-tools.svg)](https://badge.fury.io/rb/riemann-tools) [![CI](https://github.com/riemann/riemann-tools/actions/workflows/ci.yml/badge.svg)](https://github.com/riemann/riemann-tools/actions/workflows/ci.yml)
11
10
 
12
-
13
-
14
- Get started
15
- ===========
11
+ ## Get started
16
12
 
17
13
  ``` bash
18
14
  gem install riemann-tools
19
15
  riemann-health --host my.riemann.server
20
16
  ```
21
17
 
22
- Riemann-tools programs
23
- ======================
18
+ ## Riemann-tools programs
24
19
 
25
20
  This repository contains a number of different programs. Some of them
26
21
  ship with the `riemann-tools` gem, including:
@@ -49,18 +44,15 @@ ship with the `riemann-tools` gem, including:
49
44
  Also contained in the repository are a number of stand-alone monitoring
50
45
  tools, which are shipped as separate gems.
51
46
 
52
- Riemann stand-alone tools
53
- =========================
47
+ ## Riemann stand-alone tools
54
48
 
55
49
  Use these tools by installing their individual gems, usually named for
56
- the specific tool, for example:
50
+ the specific tool, for example, to install the AWS tools:
57
51
 
58
52
  ```bash
59
53
  gem install riemann-aws
60
54
  ```
61
55
 
62
- To install the AWS tools.
63
-
64
56
  * riemann-aws - Monitor various AWS services.
65
57
  * riemann-elasticsearch - Monitor Elasticsearch.
66
58
  * riemann-mesos - Monitor Mesos.
@@ -74,20 +66,12 @@ To install the AWS tools.
74
66
  There are also a number of additional, stand-alone tools, contained in
75
67
  the [Riemann GitHub account](https://github.com/riemann/).
76
68
 
77
- Docker Images
78
- =============
69
+ ## Docker Images
79
70
 
80
71
  You can find Docker images for the tools [here](https://hub.docker.com/u/riemannio/dashboard/).
81
72
 
82
- Build status
83
- ============
84
-
85
- [![Build Status](https://travis-ci.com/riemann/riemann-tools.svg?branch=master)](https://travis-ci.com/riemann/riemann-tools)
86
-
87
- License
88
- =======
73
+ ## License
89
74
 
90
75
  The MIT License
91
76
 
92
- Copyright (c) 2011-2016 Kyle Kingsbury
93
-
77
+ Copyright (c) 2011-2022 Kyle Kingsbury
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'riemann/tools/version'
2
4
 
3
5
  require 'bundler/gem_tasks'
@@ -13,9 +15,9 @@ end
13
15
 
14
16
  desc 'Recursively build all gems'
15
17
  task :rbuild do
16
- Dir.glob("tools/**") do |dir|
18
+ Dir.glob('tools/**') do |dir|
17
19
  Dir.chdir(dir)
18
20
  sh 'rake gem'
19
- Dir.chdir("../..")
21
+ Dir.chdir('../..')
20
22
  end
21
23
  end
data/SECURITY.md ADDED
@@ -0,0 +1,42 @@
1
+ # Riemann Security and Disclosure Information
2
+ This page describes Riemann security and disclosure information.
3
+
4
+ ## Supported Versions
5
+
6
+ The currently supported version of Riemann for security-patching purposes is always the latest version.
7
+
8
+ ## Security Announcements
9
+
10
+ Will be made on the [Riemann mailing list](https://groups.google.com/g/riemann-users?pli=1).
11
+
12
+ ## Report a Vulnerability
13
+
14
+ We're extremely grateful for security researchers and users that report vulnerabilities to Riemann. All reports are thoroughly investigated by the maintainers.
15
+
16
+ To make a report, you should email the private security@riemann.io list with the details.
17
+
18
+ ## When Should I Report a Vulnerability?
19
+
20
+ * You think you discovered a potential security vulnerability in Riemann.
21
+ * You are unsure how a vulnerability affects Riemann.
22
+ * You think you discovered a vulnerability in another project that Riemann depends on
23
+
24
+ For projects with their own vulnerability reporting and disclosure process, please report it directly there.
25
+
26
+ ## When Should I NOT Report a Vulnerability?
27
+
28
+ * You need help tuning Riemann components for security
29
+ * You need help applying security related updates
30
+ * Your issue is not security related
31
+
32
+ ## Security Vulnerability Response
33
+
34
+ Each report is acknowledged and analyzed within 5 working days.
35
+
36
+ Any vulnerability information shared stays within Riemann project and will not be disseminated to other projects unless it is necessary to get the issue fixed.
37
+
38
+ As the security issue moves from triage, to identified fix, to release planning we will keep the reporter updated.
39
+
40
+ ## Public Disclosure Timing
41
+
42
+ A public disclosure date is negotiated by the Riemann maintainers nd the bug submitter. We prefer to fully disclose the bug as soon as possible once a user mitigation is available. It is reasonable to delay disclosure when the bug or the fix is not yet fully understood, the solution is not well-tested, or for vendor coordination. The timeframe for disclosure is from immediate (especially if it's already publicly known) to a few weeks. For a vulnerability with a straightforward mitigation, we expect report date to disclosure date to be on the order of 7 days. The Riemann maintainers hold the final say when setting a disclosure date.
@@ -1,99 +1,113 @@
1
1
  #!/usr/bin/env ruby
2
- Process.setproctitle($0)
2
+ # frozen_string_literal: true
3
+
4
+ Process.setproctitle($PROGRAM_NAME)
3
5
 
4
6
  # Collects Apache metrics and submits them to Riemann
5
7
  # More information can be found at http://httpd.apache.org/docs/2.4/mod/mod_status.html
6
8
 
7
9
  # Removes whitespace from 'Total Accesses' and 'Total kBytes' for output to graphite
8
10
 
9
- require File.expand_path('../../lib/riemann/tools', __FILE__)
10
-
11
- class Riemann::Tools::ApacheStatus
12
- include Riemann::Tools
13
- require 'net/http'
14
- require 'uri'
15
-
16
- opt :uri, 'Apache Server Status URI', :default => 'http://localhost/server-status'
17
-
18
- def initialize
19
- @uri = URI.parse(opts[:uri]) + '?auto'
20
- # Sample Response with ExtendedStatus On
21
- # Total Accesses: 20643
22
- # Total kBytes: 36831
23
- # CPULoad: .0180314
24
- # Uptime: 43868
25
- # ReqPerSec: .470571
26
- # BytesPerSec: 859.737
27
- # BytesPerReq: 1827.01
28
- # BusyWorkers: 6
29
- # IdleWorkers: 94
30
- # Scoreboard: ___K_____K____________W_
31
-
32
- @scoreboard_map = { '_' => 'waiting', 'S' => 'starting', 'R' => 'reading', 'W' => 'sending',
33
- 'K' => 'keepalive', 'D' => 'dns', 'C' => 'closing', 'L' => 'logging', 'G' => 'graceful',
34
- 'I' => 'idle', '.' => 'open' }
35
- end
11
+ require File.expand_path('../lib/riemann/tools', __dir__)
12
+
13
+ module Riemann
14
+ module Tools
15
+ class ApacheStatus
16
+ include Riemann::Tools
17
+ require 'net/http'
18
+ require 'uri'
19
+
20
+ opt :uri, 'Apache Server Status URI', default: 'http://localhost/server-status'
21
+
22
+ def initialize
23
+ @uri = "#{URI.parse(opts[:uri])}?auto"
24
+ # Sample Response with ExtendedStatus On
25
+ # Total Accesses: 20643
26
+ # Total kBytes: 36831
27
+ # CPULoad: .0180314
28
+ # Uptime: 43868
29
+ # ReqPerSec: .470571
30
+ # BytesPerSec: 859.737
31
+ # BytesPerReq: 1827.01
32
+ # BusyWorkers: 6
33
+ # IdleWorkers: 94
34
+ # Scoreboard: ___K_____K____________W_
35
+
36
+ @scoreboard_map = {
37
+ '_' => 'waiting',
38
+ 'S' => 'starting',
39
+ 'R' => 'reading',
40
+ 'W' => 'sending',
41
+ 'K' => 'keepalive',
42
+ 'D' => 'dns',
43
+ 'C' => 'closing',
44
+ 'L' => 'logging',
45
+ 'G' => 'graceful',
46
+ 'I' => 'idle',
47
+ '.' => 'open',
48
+ }
49
+ end
36
50
 
51
+ def get_scoreboard_metrics(response)
52
+ results = Hash.new(0)
37
53
 
38
- def get_scoreboard_metrics(response)
39
- results = Hash.new(0)
54
+ response.slice! 'Scoreboard: '
55
+ response.each_char do |char|
56
+ results[char] += 1
57
+ end
58
+ results.transform_keys { |k| @scoreboard_map[k] }
59
+ end
40
60
 
41
- response.slice! 'Scoreboard: '
42
- response.each_char do |char|
43
- results[char] += 1
44
- end
45
- Hash[results.map { |k, v| [@scoreboard_map[k], v] }]
46
- end
61
+ def report_metrics(metrics)
62
+ metrics.each do |k, v|
63
+ report(
64
+ service: "httpd #{k}",
65
+ metric: v.to_f,
66
+ state: 'ok',
67
+ tags: ['httpd'],
68
+ )
69
+ end
70
+ end
47
71
 
48
- def report_metrics(metrics)
49
- metrics.each do |k, v|
50
- report(
51
- :service => "httpd #{k}",
52
- :metric => v.to_f,
53
- :state => 'ok',
54
- :tags => ['httpd']
55
- )
56
- end
57
- end
72
+ def connection
73
+ response = nil
74
+ begin
75
+ response = Net::HTTP.get(@uri)
76
+ rescue StandardError => e
77
+ report(
78
+ service: 'httpd health',
79
+ state: 'critical',
80
+ description: "Httpd connection error: #{e.class} - #{e.message}",
81
+ tags: ['httpd'],
82
+ )
83
+ else
84
+ report(
85
+ service: 'httpd health',
86
+ state: 'ok',
87
+ description: 'Httpd connection status ok',
88
+ tags: ['httpd'],
89
+ )
90
+ end
91
+ response
92
+ end
58
93
 
59
- def get_connection
60
- response = nil
61
- begin
62
- response = Net::HTTP.get(@uri)
63
- rescue => e
64
- report(
65
- :service => 'httpd health',
66
- :state => 'critical',
67
- :description => 'Httpd connection error: #{e.class} - #{e.message}',
68
- :tags => ['httpd']
69
- )
70
- else
71
- report(
72
- :service => 'httpd health',
73
- :state => 'ok',
74
- :description => 'Httpd connection status ok',
75
- :tags => ['httpd']
76
- )
77
- end
78
- response
79
- end
94
+ def tick
95
+ return if (response = connection).nil?
80
96
 
81
- def tick
82
- unless (response = get_connection).nil?
83
- response.each_line do |line|
84
- metrics = Hash.new
97
+ response.each_line do |line|
98
+ metrics = {}
85
99
 
86
- if line =~ /Scoreboard/
87
- metrics = get_scoreboard_metrics(line.strip)
88
- else
89
- key, value = line.strip.split(':')
90
- metrics[key.gsub(/\s/, '')] = value
100
+ if line =~ /Scoreboard/
101
+ metrics = get_scoreboard_metrics(line.strip)
102
+ else
103
+ key, value = line.strip.split(':')
104
+ metrics[key.gsub(/\s/, '')] = value
105
+ end
106
+ report_metrics(metrics)
91
107
  end
92
- report_metrics(metrics)
93
108
  end
94
109
  end
95
110
  end
96
-
97
111
  end
98
112
 
99
113
  Riemann::Tools::ApacheStatus.run
data/bin/riemann-bench CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- Process.setproctitle($0)
2
+ # frozen_string_literal: true
3
+
4
+ Process.setproctitle($PROGRAM_NAME)
3
5
 
4
6
  # Connects to a server (first arg) and populates it with a constant stream of
5
7
  # events for testing.
@@ -8,62 +10,65 @@ require 'rubygems'
8
10
  require 'riemann/client'
9
11
  require 'pp'
10
12
 
11
- class Riemann::Bench
12
- attr_accessor :client, :hosts, :services, :states
13
- def initialize
14
- @hosts = [nil] + (0...10).map { |i| "host#{i}" }
15
- @hosts = %w(a b c d e f g h i j)
16
- @services = %w(test1 test2 test3 foo bar baz xyzzy attack cat treat)
17
- @states = {}
18
- @client = Riemann::Client.new(:host => (ARGV.first || 'localhost'))
19
- end
13
+ module Riemann
14
+ class Bench
15
+ attr_accessor :client, :hosts, :services, :states
16
+
17
+ def initialize
18
+ @hosts = [nil] + (0...10).map { |i| "host#{i}" }
19
+ @hosts = %w[a b c d e f g h i j]
20
+ @services = %w[test1 test2 test3 foo bar baz xyzzy attack cat treat]
21
+ @states = {}
22
+ @client = Riemann::Client.new(host: (ARGV.first || 'localhost'))
23
+ end
24
+
25
+ def evolve(state)
26
+ m = state[:metric] + (rand - 0.5) * 0.1
27
+ m = [[0, m].max, 1].min
20
28
 
21
- def evolve(state)
22
- m = state[:metric] + (rand - 0.5) * 0.1
23
- m = [[0,m].max, 1].min
29
+ s = case m
30
+ when 0...0.75
31
+ 'ok'
32
+ when 0.75...0.9
33
+ 'warning'
34
+ when 0.9..1.0
35
+ 'critical'
36
+ end
24
37
 
25
- s = case m
26
- when 0...0.75
27
- 'ok'
28
- when 0.75...0.9
29
- 'warning'
30
- when 0.9..1.0
31
- 'critical'
38
+ {
39
+ metric: m,
40
+ state: s,
41
+ host: state[:host],
42
+ service: state[:service],
43
+ description: "at #{Time.now}",
44
+ }
32
45
  end
33
46
 
34
- {
35
- :metric => m,
36
- :state => s,
37
- :host => state[:host],
38
- :service => state[:service],
39
- :description => "at #{Time.now}"
40
- }
41
- end
42
-
43
- def tick
44
- # pp @states
45
- hosts.product(services).each do |id|
46
- client << (states[id] = evolve(states[id]))
47
+ def tick
48
+ # pp @states
49
+ hosts.product(services).each do |id|
50
+ client << (states[id] = evolve(states[id]))
51
+ end
47
52
  end
48
- end
49
53
 
50
- def run
51
- start
52
- loop do
53
- sleep 0.05
54
- tick
54
+ def run
55
+ start
56
+ loop do
57
+ sleep 0.05
58
+ tick
59
+ end
55
60
  end
56
- end
57
61
 
58
- def start
59
- hosts.product(services).each do |host, service|
60
- states[[host, service]] = {
61
- :metric => 0.5,
62
- :state => 'ok',
63
- :description => "Starting up",
64
- :host => host,
65
- :service => service
66
- }
62
+ def start
63
+ hosts.product(services).each do |host, service|
64
+ states[[host, service]] = {
65
+ metric: 0.5,
66
+ state: 'ok',
67
+ description: 'Starting up',
68
+ host: host,
69
+ service: service,
70
+ }
71
+ end
67
72
  end
68
73
  end
69
74
  end