Class: Wavefront::Cli::Write
Overview
Constant Summary
Wavefront::Constants::ALERT_FORMATS, Wavefront::Constants::DASH_FORMATS, Wavefront::Constants::DEFAULT_ALERT_FORMAT, Wavefront::Constants::DEFAULT_DASH_FORMAT, Wavefront::Constants::DEFAULT_FORMAT, Wavefront::Constants::DEFAULT_HOST, Wavefront::Constants::DEFAULT_INFILE_FORMAT, Wavefront::Constants::DEFAULT_OBSOLETE_METRICS, Wavefront::Constants::DEFAULT_OPTS, Wavefront::Constants::DEFAULT_PERIOD_SECONDS, Wavefront::Constants::DEFAULT_PREFIX_LENGTH, Wavefront::Constants::DEFAULT_PROXY, Wavefront::Constants::DEFAULT_PROXY_PORT, Wavefront::Constants::DEFAULT_SOURCE_FORMAT, Wavefront::Constants::DEFAULT_STRICT, Wavefront::Constants::EVENT_LEVELS, Wavefront::Constants::EVENT_STATE_DIR, Wavefront::Constants::FORMATS, Wavefront::Constants::GRANULARITIES, Wavefront::Constants::SOURCE_FORMATS
Instance Attribute Summary
#arguments, #noop, #options
Instance Method Summary
collapse
Methods included from Mixins
#call_delete, #call_get, #call_post, #hash_to_qs, #interpolate_schema, #load_file, #parse_time, #time_to_ms, #uri_concat
#initialize
Constructor Details
This class inherits a constructor from Wavefront::Cli
Instance Method Details
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/wavefront/cli/write.rb', line 85
def prep_tags(tags)
return [] unless tags.is_a?(Array)
tags.map { |t| t.split('=') }.select { |e| e.length == 2 }
end
|
#run ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/wavefront/cli/write.rb', line 22
def run
valid_value?(options[:'<value>'])
valid_metric?(options[:'<metric>'])
ts = options[:time] ? parse_time(options[:time]) : false
[:proxy, :host].each do |h|
fail Wavefront::Exception::InvalidHostname unless valid_host?(h)
end
write_opts = {
agent_host: options[:proxy],
host_name: options[:host],
metric_name: options[:'<metric>'],
point_tags: prep_tags(options[:tag]),
timestamp: ts,
noop: options[:noop]
}
write_metric(options[:'<value>'].to_f, options[:'<metric>'], write_opts)
end
|
#valid_host?(hostname) ⇒ Boolean
48
49
50
51
52
53
|
# File 'lib/wavefront/cli/write.rb', line 48
def valid_host?(hostname)
hostname.match(/^[\w\.\-]+$/) && hostname.length < 1024
end
|
#valid_metric?(metric) ⇒ Boolean
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/wavefront/cli/write.rb', line 68
def valid_metric?(metric)
begin
fail unless metric.is_a?(String) &&
metric.split('.').length > 1 &&
metric.match(/^[\w\-\._]+$/) &&
metric.length < 1024
rescue
raise Wavefront::Exception::InvalidMetricName
end
true
end
|
#valid_value?(value) ⇒ Boolean
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/wavefront/cli/write.rb', line 55
def valid_value?(value)
unless value.is_a?(Numeric) || value.match(/^-?\d*\.?\d*$/) ||
value.match(/^-?\d*\.?\d*e\d+$/)
fail Wavefront::Exception::InvalidMetricValue
end
true
end
|
#validate_opts ⇒ Object
15
16
17
18
19
20
|
# File 'lib/wavefront/cli/write.rb', line 15
def validate_opts
abort 'Please supply a proxy endpoint.' unless options[:proxy]
end
|
#write_metric(value, name, opts) ⇒ Object
43
44
45
46
|
# File 'lib/wavefront/cli/write.rb', line 43
def write_metric(value, name, opts)
wf = Wavefront::Writer.new(opts)
wf.write(value, name, opts)
end
|