graphite-tools 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84f37872baa6a9859c607a9e779dc1c0b820b481
4
+ data.tar.gz: 33996be26e72fade67009b47f5f2f139d401c65e
5
+ SHA512:
6
+ metadata.gz: 4d360d9380bb60f084ab6071cb06a14f131395b679c48bb5ef897b7e43d2af97b543078934c8539b3b9a6951aea0bb85f57d94eb8b97d7e6d9bfa3a8d02a78b0
7
+ data.tar.gz: 3f4a3f13aeb94d9e50b2197dc0364baca9e6ba52247bc9ff375eb47f35fa2e4071a5853a9e3a8d3d6f7819c1d321804df782d4f1e65a15e6d490bb6c9f6b2e64
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in graphite-tools.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
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
+ ```
14
+
15
+ ## graphite-predict
16
+
17
+ ```
18
+ $ curl "http://localhost/render/?from=-7days&target=server.diskspace.root.byte_free&format=json" | graphite-predict
19
+ => server.diskspace.root.byte_free : 2015-07-26 19:59:24 -0700
20
+ ```
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'graphite/tools'
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'active_support'
4
+ require 'graphite/tools'
5
+ require 'optparse'
6
+ require 'json'
7
+
8
+ options = { nodes: 1, metrics: 1, size_per_metric: 12 }
9
+
10
+ OptionParser.new do |opts|
11
+ opts.banner = 'Usage: graphite-predict [options]'
12
+ end.parse!
13
+
14
+ data = JSON.parse(ARGF.read)
15
+
16
+ data.each do |metric|
17
+ calc = Graphite::Tools::Regression.new(metric)
18
+ puts "#{metric['target']} : #{calc.x_intercept}"
19
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'active_support'
4
+ require 'graphite/tools'
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
+ calc = Graphite::Tools::WhisperCalc.new(ARGV[0])
22
+ bytes_per_metric = calc.to_i * options[:size_per_metric]
23
+ bytes_per_node = bytes_per_metric * options[:metrics]
24
+ total_bytes = bytes_per_node * options[:nodes]
25
+
26
+ puts ActiveSupport::NumberHelper.number_to_human_size(total_bytes)
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'graphite/tools/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'graphite-tools'
8
+ spec.version = Graphite::Tools::VERSION
9
+ spec.authors = ['Chris Beer']
10
+ spec.email = ['chris@cbeer.info']
11
+
12
+ spec.summary = 'Tools for working with graphite'
13
+ spec.homepage = 'https://github.com/cbeer/graphite-tools'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = 'exe'
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'activesupport'
21
+ spec.add_dependency 'linefit'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.9'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.2'
26
+ end
@@ -0,0 +1,10 @@
1
+ require 'graphite/tools/version'
2
+
3
+ module Graphite
4
+ ##
5
+ # Random utilities for working with graphite statistics
6
+ module Tools
7
+ require 'graphite/tools/whisper_calc'
8
+ require 'graphite/tools/regression'
9
+ end
10
+ end
@@ -0,0 +1,37 @@
1
+ require 'linefit'
2
+ module Graphite
3
+ module Tools
4
+ ##
5
+ # Regression analysis of graphite data
6
+ class Regression
7
+ attr_reader :data
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ end
12
+
13
+ def datapoints
14
+ d = @data['datapoints'].map { |(v, t)| [t, v] }
15
+ .reject { |_k, v| v.nil? }
16
+ Hash[*d.flatten]
17
+ end
18
+
19
+ def linefit
20
+ @linefit ||= begin
21
+ f = LineFit.new
22
+ f.setData(datapoints.keys, datapoints.values)
23
+ f
24
+ end
25
+ end
26
+
27
+ def forecast(*args)
28
+ linefit.forecast(*args)
29
+ end
30
+
31
+ def x_intercept(y_val = 0)
32
+ intercept, slope = linefit.coefficients
33
+ Time.at((y_val - intercept) / slope) if slope && slope < 0
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module Graphite
2
+ module Tools
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,45 @@
1
+ require 'active_support/core_ext/integer/time'
2
+
3
+ ##
4
+ # Calculator Carbon / Whisper storage requirements
5
+ module Graphite
6
+ module Tools
7
+ class WhisperCalc
8
+ attr_reader :aggregation
9
+
10
+ def initialize(aggregation)
11
+ @aggregation = aggregation
12
+ end
13
+
14
+ def to_h
15
+ Hash[aggregation.split(',').map { |x| x.split(':').map(&:strip) }]
16
+ end
17
+
18
+ def to_i
19
+ to_h.inject(0) do |i, (k, v)|
20
+ i + frequency_as_i(v) / frequency_as_i(k)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def frequency_as_i(v)
27
+ num, unit = v.scan(/(\d+)(.)$/).first
28
+ num = num.to_i
29
+
30
+ case unit
31
+ when 's'
32
+ num.seconds
33
+ when 'm'
34
+ num.minutes
35
+ when 'h'
36
+ num.hours
37
+ when 'd'
38
+ num.days
39
+ when 'y'
40
+ num.years
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graphite-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Beer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-11 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: linefit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ description:
84
+ email:
85
+ - chris@cbeer.info
86
+ executables:
87
+ - graphite-predict
88
+ - whisper-calc
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - exe/graphite-predict
101
+ - exe/whisper-calc
102
+ - graphite-tools.gemspec
103
+ - lib/graphite/tools.rb
104
+ - lib/graphite/tools/regression.rb
105
+ - lib/graphite/tools/version.rb
106
+ - lib/graphite/tools/whisper_calc.rb
107
+ homepage: https://github.com/cbeer/graphite-tools
108
+ licenses: []
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.5
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Tools for working with graphite
130
+ test_files: []