Class: Wavefront::Cli::Write
Overview
Constant Summary
Wavefront::Constants::ALERT_FORMATS, Wavefront::Constants::DEFAULT_ALERT_FORMAT, Wavefront::Constants::DEFAULT_FORMAT, Wavefront::Constants::DEFAULT_HOST, Wavefront::Constants::DEFAULT_INFILE_FORMAT, Wavefront::Constants::DEFAULT_OBSOLETE_METRICS, Wavefront::Constants::DEFAULT_PERIOD_SECONDS, Wavefront::Constants::DEFAULT_PREFIX_LENGTH, Wavefront::Constants::DEFAULT_PROXY, Wavefront::Constants::DEFAULT_PROXY_PORT, Wavefront::Constants::DEFAULT_STRICT, Wavefront::Constants::EVENT_LEVELS, Wavefront::Constants::EVENT_STATE_DIR, Wavefront::Constants::FORMATS, Wavefront::Constants::GRANULARITIES
Instance Attribute Summary
#arguments, #options
Instance Method Summary
collapse
Methods included from Mixins
#interpolate_schema, #parse_time, #time_to_ms
#initialize, #load_profile
Constructor Details
This class inherits a constructor from Wavefront::Cli
Instance Method Details
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/wavefront/cli/write.rb', line 79
def prep_tags(tags)
return [] unless tags.is_a?(Array)
tags.map { |t| t.split('=') }.select { |e| e.length == 2 }
end
|
#run ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/wavefront/cli/write.rb', line 16
def run
valid_value?(options[:'<value>'])
valid_metric?(options[:'<metric>'])
ts = options[:time] ? parse_time(options[:time]) : false
[:proxy, :host].each do |h|
raise 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_i, options[:'<metric>'], write_opts)
end
|
#valid_host?(hostname) ⇒ Boolean
42
43
44
45
46
47
|
# File 'lib/wavefront/cli/write.rb', line 42
def valid_host?(hostname)
hostname.match(/^[\w\.\-]+$/) && hostname.length < 1024
end
|
#valid_metric?(metric) ⇒ Boolean
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/wavefront/cli/write.rb', line 62
def valid_metric?(metric)
begin
raise unless metric.is_a?(String) &&
metric.split('.').length > 1 &&
metric.match(/^[\w\-\._]+$/) &&
metric.length < 1024
rescue
fail Wavefront::Exception::InvalidMetricName
end
true
end
|
#valid_value?(value) ⇒ Boolean
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/wavefront/cli/write.rb', line 49
def valid_value?(value)
unless value.is_a?(Numeric) || value.match(/^-?\d*\.?\d*$/) ||
value.match(/^-?\d*\.?\d*e\d+$/)
raise Wavefront::Exception::InvalidMetricValue
end
true
end
|
#write_metric(value, name, opts) ⇒ Object
37
38
39
40
|
# File 'lib/wavefront/cli/write.rb', line 37
def write_metric(value, name, opts)
wf = Wavefront::Writer.new(opts)
wf.write(value, name, opts)
end
|