graphite-storage-calculator 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3688fbc478fa94211bd1aecd26bcd0ae0b8cf81
4
+ data.tar.gz: 514f7e5aa6e10c1263583805ec8c36e8cf8aa89b
5
+ SHA512:
6
+ metadata.gz: 4ca4bf0228542b12bdf5c1ca2c9c9abeff52e593c2feacf753683d020bde483dcda52ace04564feda7fb3c449b567a55c66058f22686865ab7ddeffedc08d5dc
7
+ data.tar.gz: 0277d1b75af0d8d594ebab5ac392c487cf270c33d22b01405762c927ba3424c025962e03f0015ada7e44fb386f5a5c071783f34abb2699125f73d3a689e82d04
@@ -0,0 +1,19 @@
1
+ *.rbc
2
+ *.sassc
3
+ .sass-cache
4
+ capybara-*.html
5
+ .rspec
6
+ .rvmrc
7
+ /.bundle
8
+ /vendor/bundle
9
+ /log/*
10
+ /tmp/*
11
+ /db/*.sqlite3
12
+ /public/system/*
13
+ /coverage/
14
+ /spec/tmp/*
15
+ **.orig
16
+ rerun.txt
17
+ pickle-email-*.html
18
+ .project
19
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,13 @@
1
+ # Utilities for working with graphite / carbon
2
+
3
+ Calculate the number of bytes a given Carbon retention policy will take
4
+
5
+ ## whisper-calc
6
+
7
+ ```
8
+ $ whisper-calc -n 10 -m 100 10s:1d,1m:7d,10m:1y,60m:5y
9
+ => 1.29 GB
10
+
11
+ $ whisper-calc -n 10 -m 100 10s:1d,1m:1y
12
+ => 5.97 GB
13
+ ```
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'active_support'
4
+ require 'whisper_calc'
5
+ require 'optparse'
6
+
7
+ options = { nodes: 1, metrics: 1, size_per_metric: 12 }
8
+
9
+ OptionParser.new do |opts|
10
+ opts.banner = 'Usage: whisper-calc [options]'
11
+
12
+ opts.on('-n', '--nodes [NODES]') do |n|
13
+ options[:nodes] = n.to_i
14
+ end
15
+
16
+ opts.on('-m', '--metrics [metrics]') do |m|
17
+ options[:metrics] = m.to_i
18
+ end
19
+ end.parse!
20
+
21
+ bytes_per_metric = WhisperCalc.new(ARGV[0]).to_i * options[:size_per_metric]
22
+ bytes_per_node = bytes_per_metric * options[:metrics]
23
+ total_bytes = bytes_per_node * options[:nodes]
24
+
25
+ puts ActiveSupport::NumberHelper.number_to_human_size(total_bytes)
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'graphite-storage-calculator'
5
+ spec.version = '0.0.1'
6
+ spec.authors = ['Chris Beer']
7
+ spec.email = ['chris@cbeer.info']
8
+ spec.summary = 'Utilities for working with graphite'
9
+ spec.homepage = ''
10
+ spec.license = 'Apache 2'
11
+
12
+ spec.files = `git ls-files -z`.split("\x0")
13
+ spec.bindir = 'exe'
14
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_dependency 'activesupport'
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.9'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'rspec', '~> 3.1'
23
+ end
@@ -0,0 +1,41 @@
1
+ require 'active_support/core_ext/integer/time'
2
+
3
+ ##
4
+ # Calculator Carbon / Whisper storage requirements
5
+ class WhisperCalc
6
+ attr_reader :aggregation
7
+
8
+ def initialize(aggregation)
9
+ @aggregation = aggregation
10
+ end
11
+
12
+ def to_h
13
+ Hash[aggregation.split(',').map { |x| x.split(':').map(&:strip) }]
14
+ end
15
+
16
+ def to_i
17
+ to_h.inject(0) do |i, (k, v)|
18
+ i + frequency_as_i(v) / frequency_as_i(k)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def frequency_as_i(v)
25
+ num, unit = v.scan(/(\d+)(.)$/).first
26
+ num = num.to_i
27
+
28
+ case unit
29
+ when 's'
30
+ num.seconds
31
+ when 'm'
32
+ num.minutes
33
+ when 'h'
34
+ num.hours
35
+ when 'd'
36
+ num.days
37
+ when 'y'
38
+ num.years
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'whisper_calc'
3
+
4
+ describe WhisperCalc do
5
+ subject { described_class.new('1s:2d,3h:4y') }
6
+
7
+ describe '#to_h' do
8
+ it 'should split an aggregation into frequency/history pairs' do
9
+ expect(subject.to_h).to eq '1s' => '2d', '3h' => '4y'
10
+ end
11
+ end
12
+
13
+ describe '#to_i' do
14
+ it 'should be the count of the data points in the aggregation' do
15
+ expect(subject.to_i).to eq 184_488
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,89 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ # # These two settings work together to allow you to limit a spec run
46
+ # # to individual examples or groups you care about by tagging them with
47
+ # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
48
+ # # get run.
49
+ # config.filter_run :focus
50
+ # config.run_all_when_everything_filtered = true
51
+ #
52
+ # # Limits the available syntax to the non-monkey patched syntax that is
53
+ # # recommended. For more details, see:
54
+ # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
55
+ # # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
56
+ # # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
57
+ # config.disable_monkey_patching!
58
+ #
59
+ # # This setting enables warnings. It's recommended, but in some cases may
60
+ # # be too noisy due to issues in dependencies.
61
+ # config.warnings = true
62
+ #
63
+ # # Many RSpec users commonly either run the entire suite or an individual
64
+ # # file, and it's useful to allow more verbose output when running an
65
+ # # individual spec file.
66
+ # if config.files_to_run.one?
67
+ # # Use the documentation formatter for detailed output,
68
+ # # unless a formatter has already been configured
69
+ # # (e.g. via a command-line flag).
70
+ # config.default_formatter = 'doc'
71
+ # end
72
+ #
73
+ # # Print the 10 slowest examples and example groups at the
74
+ # # end of the spec run, to help surface which specs are running
75
+ # # particularly slow.
76
+ # config.profile_examples = 10
77
+ #
78
+ # # Run specs in random order to surface order dependencies. If you find an
79
+ # # order dependency and want to debug it, you can fix the order by providing
80
+ # # the seed, which is printed after each run.
81
+ # # --seed 1234
82
+ # config.order = :random
83
+ #
84
+ # # Seed global randomization in this process using the `--seed` CLI option.
85
+ # # Setting this allows you to use `--seed` to deterministically reproduce
86
+ # # test failures related to randomization by passing the same `--seed` value
87
+ # # as the one that triggered the failure.
88
+ # Kernel.srand config.seed
89
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graphite-storage-calculator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Beer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ description:
70
+ email:
71
+ - chris@cbeer.info
72
+ executables:
73
+ - whisper-calc
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - exe/whisper-calc
82
+ - graphite-storage-calculator.gemspec
83
+ - lib/whisper_calc.rb
84
+ - spec/lib/whisper_calc_spec.rb
85
+ - spec/spec_helper.rb
86
+ homepage: ''
87
+ licenses:
88
+ - Apache 2
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.5
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Utilities for working with graphite
110
+ test_files:
111
+ - spec/lib/whisper_calc_spec.rb
112
+ - spec/spec_helper.rb