cassandra-utils 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 676b1a4ee9e342140298782e820f8febaf32c40b
4
+ data.tar.gz: 6aa8c650bbcd8b5c7e666a54a6c5d7c8446df1c4
5
+ SHA512:
6
+ metadata.gz: 0fc348a064d31d9e7de6af588fe8ac2874064ba2877532f2228046149b46f766d16eac1980e8df4755e227c797f5e47d997b0b397bdf6363eca67adfc56540dd
7
+ data.tar.gz: 5c0d332b6cf818fb753ba58bce6b32c7aacc9da3e1d8f4d2f78ef8ca34b196ac19923044606551f9052360cd332ba98f98205c8d0c3a9202928e62749fdbd45f
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.4
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at Andrew_Thompson@rapid7.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cassandra-utils.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'bundler', '~> 1.7'
8
+ gem 'thor-scmversion', '= 1.7.0'
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cassandra-utils (0.0.1)
5
+ daemon_runner (~> 0.2)
6
+ dogstatsd-ruby (~> 1.6)
7
+ mixlib-shellout (~> 2.2)
8
+ thor (~> 0.19)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ daemon_runner (0.2.2)
14
+ logging (~> 2.1)
15
+ mixlib-shellout (~> 2.2)
16
+ dogstatsd-ruby (1.6.0)
17
+ little-plugger (1.1.4)
18
+ logging (2.1.0)
19
+ little-plugger (~> 1.1)
20
+ multi_json (~> 1.10)
21
+ minitest (5.9.0)
22
+ mixlib-shellout (2.2.7)
23
+ multi_json (1.12.1)
24
+ rake (10.5.0)
25
+ thor (0.19.1)
26
+ thor-scmversion (1.7.0)
27
+ mixlib-shellout
28
+ thor
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.7)
35
+ cassandra-utils!
36
+ minitest (~> 5.0)
37
+ rake (~> 10.0)
38
+ thor-scmversion (= 1.7.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Andrew Thompson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Cassandra::Utils
2
+
3
+ This is a utility for gathering data about the state of a Cassandra node and reporting metrics about that state.
4
+
5
+ The utility is composed of a collection of discrete _tasks_.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cassandra-utils'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cassandra-utils
22
+
23
+ ## Usage
24
+
25
+ ```bash
26
+ bin/cass-util stats
27
+ ```
28
+
29
+ ## Adding tasks
30
+
31
+ Add a file under `lib/cassandra/utils/` and add that new Class to [Cassandra::Utils::Daemon#tasks](/lib/cassandra/utils/daemon.rb).
32
+
33
+ You can subclass [Cassandra::Utils::CLI::Base](/lib/cassandra/utils/cli/base.rb) to simplify running shell commands and sending stats to Datadog.
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rapid7/cassandra-utils. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
44
+
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/Thorfile ADDED
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler'
4
+ require 'bundler/setup'
5
+ require 'thor/scmversion'
data/bin/cass-util ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/cassandra/utils'
3
+ require 'thor'
4
+
5
+ class CassandraUtils < Thor
6
+
7
+ method_option :loop_sleep_time, type: :numeric,
8
+ required: true, default: 120,
9
+ desc: 'Frequency tasks are run'
10
+ desc 'stats', 'Write metrics to Datadog'
11
+ def stats
12
+ s = ::Cassandra::Utils::Daemon.new(options)
13
+ s.start!
14
+ end
15
+ end
16
+
17
+ CassandraUtils.start
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cassandra/utils"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cassandra/utils/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cassandra-utils"
8
+ spec.version = Cassandra::Utils::VERSION
9
+ spec.authors = ["Andrew Thompson"]
10
+ spec.email = ["Andrew_Thompson@rapid7.com"]
11
+
12
+ spec.summary = %q{Utility to manage Cassandra Monitoring and Management}
13
+ spec.homepage = "https://github.com/rapid7/cassandra-utils"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "bin"
18
+ spec.executables = ["cass-util"]
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "mixlib-shellout", "~> 2.2"
22
+ spec.add_dependency "dogstatsd-ruby", "~> 1.6"
23
+ spec.add_dependency "thor", "~> 0.19"
24
+ spec.add_dependency "daemon_runner", "~> 0.2"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.12"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+ end
@@ -0,0 +1,52 @@
1
+ require 'mixlib/shellout'
2
+ require 'statsd'
3
+
4
+ module Cassandra
5
+ module Utils
6
+ module CLI
7
+ class Base
8
+ attr_reader :command, :stdout
9
+
10
+ def cwd
11
+ '/tmp'
12
+ end
13
+
14
+ def timeout
15
+ 15
16
+ end
17
+
18
+ def runner
19
+ @command ||= Mixlib::ShellOut.new(command, :cwd => cwd, :timeout => timeout)
20
+ end
21
+
22
+ def output
23
+ raise NotImplementedError, 'Must implement this in a subclass'
24
+ end
25
+
26
+ def run!
27
+ runner
28
+ @command.run_command
29
+ @command.error!
30
+ @stdout = @command.stdout
31
+ out = output
32
+ push_metric(out)
33
+ out
34
+ end
35
+
36
+ protected
37
+
38
+ def statsd
39
+ @statsd ||= ::Statsd.new('localhost', 8125)
40
+ end
41
+
42
+ def push_metric(value)
43
+ statsd.gauge(metric_name, value)
44
+ end
45
+
46
+ def to_dd(out)
47
+ out == true ? 1 : 0
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,15 @@
1
+ require 'daemon_runner'
2
+
3
+ module Cassandra
4
+ module Utils
5
+ class Daemon < ::DaemonRunner::Client
6
+
7
+ def tasks
8
+ [
9
+ [::Cassandra::Utils::Stats::Compaction.new, 'run!'],
10
+ [::Cassandra::Utils::Stats::Cleanup.new, 'run!']
11
+ ]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ module Cassandra
2
+ module Utils
3
+ module Stats
4
+ class Cleanup < Utils::CLI::Base
5
+
6
+ def command
7
+ 'nodetool compactionstats'
8
+ end
9
+
10
+ def output
11
+ cleanup = stdout.lines.any? { |l| l.include?('Cleanup') }
12
+ to_dd(cleanup)
13
+ end
14
+
15
+ def metric_name
16
+ 'cassandra.cleanup.running'
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Cassandra
2
+ module Utils
3
+ module Stats
4
+ class Compaction < Utils::CLI::Base
5
+
6
+ def command
7
+ 'nodetool compactionstats'
8
+ end
9
+
10
+ def output
11
+ compaction = stdout.lines.any? { |l| l.include?('Compaction') }
12
+ to_dd(compaction)
13
+ end
14
+
15
+ def metric_name
16
+ 'cassandra.compaction.running'
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'stats/compaction'
2
+ require_relative 'stats/cleanup'
@@ -0,0 +1,5 @@
1
+ module Cassandra
2
+ module Utils
3
+ VERSION = IO.read(File.expand_path('../../../../VERSION', __FILE__)) rescue '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'utils/cli/base'
2
+ require_relative 'utils/daemon'
3
+ require_relative 'utils/stats'
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cassandra-utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Thompson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mixlib-shellout
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dogstatsd-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.19'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.19'
55
+ - !ruby/object:Gem::Dependency
56
+ name: daemon_runner
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.0'
111
+ description:
112
+ email:
113
+ - Andrew_Thompson@rapid7.com
114
+ executables:
115
+ - cass-util
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".travis.yml"
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - Thorfile
128
+ - bin/cass-util
129
+ - bin/console
130
+ - bin/setup
131
+ - cassandra-utils.gemspec
132
+ - lib/cassandra/utils.rb
133
+ - lib/cassandra/utils/cli/base.rb
134
+ - lib/cassandra/utils/daemon.rb
135
+ - lib/cassandra/utils/stats.rb
136
+ - lib/cassandra/utils/stats/cleanup.rb
137
+ - lib/cassandra/utils/stats/compaction.rb
138
+ - lib/cassandra/utils/version.rb
139
+ homepage: https://github.com/rapid7/cassandra-utils
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.4.3
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Utility to manage Cassandra Monitoring and Management
163
+ test_files: []