metricsgeek 0.0.5 → 0.0.6
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.
- data/README.md +8 -0
- data/bin/metricsgeek +11 -6
- data/lib/metrics_downloader.rb +37 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -43,6 +43,10 @@ expands to
|
|
43
43
|
|
44
44
|
--from server1.dc,server2.dc,server3.dc,server5.dc,server8.dc,server9.dc,server10.dc,server11.dc
|
45
45
|
|
46
|
+
The above two features can be combined:
|
47
|
+
|
48
|
+
--from server[1..3,5,8].dc,server-prod-us-east[11..13].aws.com
|
49
|
+
|
46
50
|
Metrics selection
|
47
51
|
=================
|
48
52
|
You can use the --list_keys option together with --from to list all the metrics keys available for querying.
|
@@ -68,4 +72,8 @@ Or, to sum up the POST rate from metric com.abc.webservice.posts.m1 across the c
|
|
68
72
|
|
69
73
|
How to contribute
|
70
74
|
=================
|
75
|
+
You can run the test like this:
|
76
|
+
|
77
|
+
rspec metrics_downloader_spec.rb
|
78
|
+
|
71
79
|
Pull requests are welcome!
|
data/bin/metricsgeek
CHANGED
@@ -23,18 +23,23 @@ class Array
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def format(number)
|
26
|
-
"%7.3f" % [number]
|
26
|
+
"%7.3f" % [number] rescue number
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
if !opts[:from]
|
30
|
+
puts "You must specify --from. Use --help for options."
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
json_trees = MetricsDownloader.parse_json_from(MetricsDownloader.split_host_exprs(opts[:from]),
|
35
|
+
opts[:port], opts[:route],
|
36
|
+
opts[:timeout])
|
32
37
|
|
33
38
|
if opts[:list_keys]
|
34
|
-
MetricsParser.list_keys_for_hashes(json_trees).each { |key| puts key }
|
39
|
+
MetricsParser.list_keys_for_hashes(json_trees.values).each { |key| puts key }
|
35
40
|
else
|
36
41
|
keys = opts[:select].split(",")
|
37
|
-
host_key_value =
|
42
|
+
host_key_value = json_trees.map do |host, json_tree|
|
38
43
|
matching_key_values = MetricsParser.glob_key_values(json_tree, keys)
|
39
44
|
matching_key_values.map do |flatkey, value|
|
40
45
|
{:host => host, :key => flatkey, :value => value}
|
data/lib/metrics_downloader.rb
CHANGED
@@ -45,4 +45,41 @@ module MetricsDownloader
|
|
45
45
|
[host_expr]
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
# @param host_exprs A single string with multiple host expressions separated by commas
|
50
|
+
# Splits a comma-delimited string of host exprs. This is tricky since there may be commas within brackets
|
51
|
+
def self.split_host_exprs(host_exprs_str)
|
52
|
+
host_exprs = []
|
53
|
+
expr = ""
|
54
|
+
in_brackets = false
|
55
|
+
host_exprs_str.each_char do |c|
|
56
|
+
if c == "," && !in_brackets
|
57
|
+
host_exprs << expr
|
58
|
+
expr = ""
|
59
|
+
next
|
60
|
+
elsif c == "["
|
61
|
+
in_brackets = true
|
62
|
+
elsif c == "]"
|
63
|
+
in_brackets = false
|
64
|
+
end
|
65
|
+
expr << c
|
66
|
+
end
|
67
|
+
host_exprs << expr if expr != ""
|
68
|
+
host_exprs
|
69
|
+
end
|
70
|
+
|
71
|
+
# Parses JSON from a list of host expressions, as passed to expand_host_expr. Basically a combination
|
72
|
+
# of expand_host_expr, create_urls_from_host_params, and download_and_parse_json_from_urls.
|
73
|
+
#
|
74
|
+
# @param hosts A list of host expressions, as passed to expand_host_expr
|
75
|
+
# @param port The integer port to query
|
76
|
+
# @param route The string after / for getting metrics, defaults to "metricz/"
|
77
|
+
# @param timeout The timeout in seconds for fetching data
|
78
|
+
# @returns A hash { hostname => json_tree }
|
79
|
+
def self.parse_json_from(hosts, port, route = "metricz/", timeout = 5)
|
80
|
+
expanded_hosts = hosts.map { |expr| MetricsDownloader.expand_host_expr(expr) }.flatten
|
81
|
+
urls = MetricsDownloader.create_urls_from_host_params(expanded_hosts, port, route)
|
82
|
+
json_trees = MetricsDownloader.download_and_parse_json_from_urls(urls, timeout)
|
83
|
+
Hash[expanded_hosts.zip(json_trees)]
|
84
|
+
end
|
48
85
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metricsgeek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-03 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'Easily grok and analyze your application metrics from a cluster, in
|
15
15
|
real time, with this command line tool /
|