capistrano-stats 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/capistrano-stats.gemspec +28 -0
- data/lib/capistrano-stats.rb +25 -0
- data/lib/capistrano-stats/metric-collector.rb +104 -0
- data/lib/capistrano-stats/metric-message.rb +49 -0
- data/lib/capistrano-stats/version.rb +5 -0
- data/tasks/metrics.rake +7 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70df68cdce71eefd709dc7330eb7abb04b9d3022
|
4
|
+
data.tar.gz: 039b7a83c79c5c49637c787e73c1be8c04ced66b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c215b955620a7f74bb0d6afe240e0faffde1ff7f9e70d273fcef9dfd91a8906ec23e0a4204b715ab28c5b90952f49fdbdc13c7474a4caf01b22b5db5a47edea
|
7
|
+
data.tar.gz: 95ba78d756baca86714a34de24855589157e93fed9fa0f54ccc310ade71e37e4da42ae8975dcd9b99caad99680f86cfeaef7faf0708f7037b0ba00739a70ec8c
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano-stats/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "capistrano-stats"
|
8
|
+
gem.version = Capistrano::Stats::VERSION
|
9
|
+
gem.authors = ["Lee Hambley"]
|
10
|
+
gem.email = ["lee.hambley@gmail.com"]
|
11
|
+
gem.description = %q{Collects anonymous usage statistics about Capistrano to aid with platform support and ruby version targeting.}
|
12
|
+
gem.summary = %q{Official metrics to help the development direction of Capistrano}
|
13
|
+
gem.homepage = "http://metrics.capistranorb.com/"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
|
18
|
+
gem.licenses = ['MIT']
|
19
|
+
|
20
|
+
gem.post_install_message = <<-eos
|
21
|
+
Capistrano will ask you the next time you run it if you would like to share
|
22
|
+
anonymous usage statistics with the maintainance team to help guide our
|
23
|
+
development efforts. We emplore you to opt-in, but we understand if your
|
24
|
+
privacy is important to you in this regard.
|
25
|
+
eos
|
26
|
+
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path('../capistrano-stats/metric-collector', __FILE__)
|
2
|
+
require File.expand_path('../capistrano-stats/metric-message', __FILE__)
|
3
|
+
require File.expand_path('../capistrano-stats/version', __FILE__)
|
4
|
+
|
5
|
+
require 'capistrano/version'
|
6
|
+
|
7
|
+
unless Capistrano.const_defined?('VERSION')
|
8
|
+
Capistrano::VERSION = Capistrano::Version
|
9
|
+
end
|
10
|
+
|
11
|
+
case Capistrano::VERSION.to_s.to_i
|
12
|
+
when 2
|
13
|
+
Capistrano::Configuration.instance.load do
|
14
|
+
namespace :metrics do
|
15
|
+
task :collect do
|
16
|
+
Capistrano::MetricCollector.new(Dir.pwd).collect
|
17
|
+
end
|
18
|
+
end
|
19
|
+
on :start, 'metrics:collect'
|
20
|
+
end
|
21
|
+
when 3
|
22
|
+
load File.expand_path('../../tasks/metrics.rake', __FILE__)
|
23
|
+
else
|
24
|
+
warn "Unsupported Capistrano Version"
|
25
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'digest'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module Capistrano
|
6
|
+
|
7
|
+
class MetricCollector
|
8
|
+
|
9
|
+
attr_reader :pwd
|
10
|
+
|
11
|
+
def initialize(pwd)
|
12
|
+
@pwd = Pathname.new(pwd)
|
13
|
+
end
|
14
|
+
|
15
|
+
def enabled?
|
16
|
+
ask_to_enable unless File.exists?(sentry_file)
|
17
|
+
File.read(sentry_file).chomp == "true"
|
18
|
+
end
|
19
|
+
|
20
|
+
def collect
|
21
|
+
socket = UDPSocket.new
|
22
|
+
message.anonymize! unless enabled?
|
23
|
+
socket.send(message.to_s, 0, *destination)
|
24
|
+
rescue SocketError
|
25
|
+
warn "There was a problem tracking statistics, please report to https://github.com/capistrano/stats"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def destination
|
31
|
+
target = ENV.fetch('CAPISTRANO_METRICS', 'metrics.capistranorb.com:1200')
|
32
|
+
host, port = target.split(':')
|
33
|
+
|
34
|
+
if port == ""
|
35
|
+
raise StandardError.new("Invalid port: \"%s\"" % port)
|
36
|
+
else
|
37
|
+
port = port.to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
[host, port]
|
41
|
+
end
|
42
|
+
|
43
|
+
def anon_project_hash
|
44
|
+
git_remote = `git config --get-regex 'remote\..*\.url'`.chomp.split(' ').last
|
45
|
+
@anon_project_hash = "not-git"
|
46
|
+
unless git_remote.to_s == ""
|
47
|
+
@anon_project_hash = Digest::MD5.hexdigest(git_remote)[0..7]
|
48
|
+
end
|
49
|
+
@anon_project_hash
|
50
|
+
end
|
51
|
+
|
52
|
+
def ask_to_enable
|
53
|
+
return false unless $stdin.tty?
|
54
|
+
show_prompt
|
55
|
+
result = ask_to_confirm("Do you want to enable statistics? (y/N): ")
|
56
|
+
show_thank_you_note(result)
|
57
|
+
write_setting(result)
|
58
|
+
end
|
59
|
+
|
60
|
+
def show_prompt
|
61
|
+
puts <<-EOF
|
62
|
+
Would you like to enable statistics? Here is an example message we would
|
63
|
+
send:
|
64
|
+
|
65
|
+
#{message}
|
66
|
+
|
67
|
+
EOF
|
68
|
+
end
|
69
|
+
|
70
|
+
def show_thank_you_note(result)
|
71
|
+
puts(result ? "Thank you, you may wish to add .capistrano/ to your source
|
72
|
+
control database to avoid future prompts" : "Your preferences have
|
73
|
+
been saved.")
|
74
|
+
end
|
75
|
+
|
76
|
+
def message
|
77
|
+
@message ||= MetricMessage.new({
|
78
|
+
:payload => anon_project_hash,
|
79
|
+
:ruby_version => RUBY_VERSION,
|
80
|
+
:ruby_platform => RUBY_PLATFORM,
|
81
|
+
})
|
82
|
+
@message
|
83
|
+
end
|
84
|
+
|
85
|
+
def sentry_file
|
86
|
+
@pwd.join('.capistrano', 'metrics')
|
87
|
+
end
|
88
|
+
|
89
|
+
def ask_to_confirm(prompt)
|
90
|
+
$stdout.write(prompt)
|
91
|
+
$stdout.flush
|
92
|
+
$stdin.gets.chomp.downcase[0] == ?y ? true : false
|
93
|
+
end
|
94
|
+
|
95
|
+
def write_setting(value)
|
96
|
+
Dir.mkdir(sentry_file.dirname) rescue nil
|
97
|
+
File.open(sentry_file, "wb") do |f|
|
98
|
+
f.write(value)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
|
5
|
+
class MetricMessage
|
6
|
+
|
7
|
+
VERSION = 1
|
8
|
+
SERIALIZE_ATTRIBUTES = [
|
9
|
+
:version,
|
10
|
+
:datetime,
|
11
|
+
:ruby_version,
|
12
|
+
:ruby_platform,
|
13
|
+
:capistrano_version,
|
14
|
+
:payload
|
15
|
+
]
|
16
|
+
|
17
|
+
def initialize(attributes = {})
|
18
|
+
@attributes = attributes.merge({
|
19
|
+
:version => VERSION,
|
20
|
+
:datetime => Time.now.iso8601,
|
21
|
+
:capistrano_version => capistrano_version,
|
22
|
+
})
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
@attributes.values_at(*SERIALIZE_ATTRIBUTES).join("|")
|
27
|
+
end
|
28
|
+
|
29
|
+
def anonymize!
|
30
|
+
@attributes.each do |attr, value|
|
31
|
+
@attributes[attr] = 'anonymous' unless attr == :version
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def capistrano_version
|
38
|
+
if Capistrano.const_defined?('VERSION')
|
39
|
+
Capistrano::VERSION
|
40
|
+
elsif Capistrano.const_defined?('Version')
|
41
|
+
Capistrano::Version
|
42
|
+
else
|
43
|
+
"unknown"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/tasks/metrics.rake
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-stats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Hambley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Collects anonymous usage statistics about Capistrano to aid with platform
|
14
14
|
support and ruby version targeting.
|
@@ -17,7 +17,13 @@ email:
|
|
17
17
|
executables: []
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
|
-
files:
|
20
|
+
files:
|
21
|
+
- capistrano-stats.gemspec
|
22
|
+
- lib/capistrano-stats.rb
|
23
|
+
- lib/capistrano-stats/metric-collector.rb
|
24
|
+
- lib/capistrano-stats/metric-message.rb
|
25
|
+
- lib/capistrano-stats/version.rb
|
26
|
+
- tasks/metrics.rake
|
21
27
|
homepage: http://metrics.capistranorb.com/
|
22
28
|
licenses:
|
23
29
|
- MIT
|