MuranoCLI 2.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.rspec +2 -0
- data/.travis.yml +21 -0
- data/Gemfile +27 -0
- data/LICENSE.txt +19 -0
- data/MuranoCLI.gemspec +50 -0
- data/MuranoCLI.iss +50 -0
- data/README.markdown +208 -0
- data/Rakefile +188 -0
- data/TODO.taskpaper +122 -0
- data/bin/mr +8 -0
- data/bin/murano +84 -0
- data/docs/demo.md +109 -0
- data/lib/MrMurano/Account.rb +211 -0
- data/lib/MrMurano/Config-Migrate.rb +47 -0
- data/lib/MrMurano/Config.rb +286 -0
- data/lib/MrMurano/Mock.rb +63 -0
- data/lib/MrMurano/Product-1P-Device.rb +145 -0
- data/lib/MrMurano/Product-Resources.rb +195 -0
- data/lib/MrMurano/Product.rb +358 -0
- data/lib/MrMurano/ProjectFile.rb +349 -0
- data/lib/MrMurano/Solution-Cors.rb +46 -0
- data/lib/MrMurano/Solution-Endpoint.rb +177 -0
- data/lib/MrMurano/Solution-File.rb +150 -0
- data/lib/MrMurano/Solution-ServiceConfig.rb +140 -0
- data/lib/MrMurano/Solution-Services.rb +326 -0
- data/lib/MrMurano/Solution-Users.rb +129 -0
- data/lib/MrMurano/Solution.rb +59 -0
- data/lib/MrMurano/SubCmdGroupContext.rb +49 -0
- data/lib/MrMurano/SyncUpDown.rb +565 -0
- data/lib/MrMurano/commands/assign.rb +57 -0
- data/lib/MrMurano/commands/businessList.rb +45 -0
- data/lib/MrMurano/commands/completion.rb +152 -0
- data/lib/MrMurano/commands/config.rb +67 -0
- data/lib/MrMurano/commands/content.rb +130 -0
- data/lib/MrMurano/commands/cors.rb +30 -0
- data/lib/MrMurano/commands/domain.rb +17 -0
- data/lib/MrMurano/commands/gb.rb +33 -0
- data/lib/MrMurano/commands/init.rb +138 -0
- data/lib/MrMurano/commands/keystore.rb +157 -0
- data/lib/MrMurano/commands/logs.rb +78 -0
- data/lib/MrMurano/commands/mock.rb +63 -0
- data/lib/MrMurano/commands/password.rb +88 -0
- data/lib/MrMurano/commands/postgresql.rb +41 -0
- data/lib/MrMurano/commands/product.rb +14 -0
- data/lib/MrMurano/commands/productCreate.rb +39 -0
- data/lib/MrMurano/commands/productDelete.rb +33 -0
- data/lib/MrMurano/commands/productDevice.rb +84 -0
- data/lib/MrMurano/commands/productDeviceIdCmds.rb +86 -0
- data/lib/MrMurano/commands/productList.rb +45 -0
- data/lib/MrMurano/commands/productWrite.rb +27 -0
- data/lib/MrMurano/commands/show.rb +80 -0
- data/lib/MrMurano/commands/solution.rb +14 -0
- data/lib/MrMurano/commands/solutionCreate.rb +39 -0
- data/lib/MrMurano/commands/solutionDelete.rb +34 -0
- data/lib/MrMurano/commands/solutionList.rb +45 -0
- data/lib/MrMurano/commands/status.rb +92 -0
- data/lib/MrMurano/commands/sync.rb +60 -0
- data/lib/MrMurano/commands/timeseries.rb +115 -0
- data/lib/MrMurano/commands/tsdb.rb +271 -0
- data/lib/MrMurano/commands/usage.rb +23 -0
- data/lib/MrMurano/commands/zshcomplete.erb +112 -0
- data/lib/MrMurano/commands.rb +32 -0
- data/lib/MrMurano/hash.rb +20 -0
- data/lib/MrMurano/http.rb +153 -0
- data/lib/MrMurano/makePretty.rb +75 -0
- data/lib/MrMurano/schema/pf-v1.0.0.yaml +114 -0
- data/lib/MrMurano/schema/sf-v0.2.0.yaml +77 -0
- data/lib/MrMurano/schema/sf-v0.3.0.yaml +78 -0
- data/lib/MrMurano/template/mock.erb +9 -0
- data/lib/MrMurano/template/projectFile.murano.erb +81 -0
- data/lib/MrMurano/verbosing.rb +99 -0
- data/lib/MrMurano/version.rb +4 -0
- data/lib/MrMurano.rb +20 -0
- data/spec/Account-Passwords_spec.rb +242 -0
- data/spec/Account_spec.rb +272 -0
- data/spec/ConfigFile_spec.rb +50 -0
- data/spec/ConfigMigrate_spec.rb +89 -0
- data/spec/Config_spec.rb +409 -0
- data/spec/Http_spec.rb +204 -0
- data/spec/MakePretties_spec.rb +118 -0
- data/spec/Mock_spec.rb +53 -0
- data/spec/ProductBase_spec.rb +113 -0
- data/spec/ProductContent_spec.rb +162 -0
- data/spec/ProductResources_spec.rb +329 -0
- data/spec/Product_1P_Device_spec.rb +202 -0
- data/spec/Product_1P_RPC_spec.rb +175 -0
- data/spec/Product_spec.rb +153 -0
- data/spec/ProjectFile_spec.rb +324 -0
- data/spec/Solution-Cors_spec.rb +164 -0
- data/spec/Solution-Endpoint_spec.rb +581 -0
- data/spec/Solution-File_spec.rb +212 -0
- data/spec/Solution-ServiceConfig_spec.rb +202 -0
- data/spec/Solution-ServiceDevice_spec.rb +176 -0
- data/spec/Solution-ServiceEventHandler_spec.rb +385 -0
- data/spec/Solution-ServiceModules_spec.rb +465 -0
- data/spec/Solution-UsersRoles_spec.rb +207 -0
- data/spec/Solution_spec.rb +92 -0
- data/spec/SyncRoot_spec.rb +83 -0
- data/spec/SyncUpDown_spec.rb +495 -0
- data/spec/Verbosing_spec.rb +279 -0
- data/spec/_workspace.rb +27 -0
- data/spec/cmd_assign_spec.rb +51 -0
- data/spec/cmd_business_spec.rb +59 -0
- data/spec/cmd_common.rb +72 -0
- data/spec/cmd_config_spec.rb +68 -0
- data/spec/cmd_content_spec.rb +71 -0
- data/spec/cmd_cors_spec.rb +50 -0
- data/spec/cmd_device_spec.rb +96 -0
- data/spec/cmd_domain_spec.rb +32 -0
- data/spec/cmd_init_spec.rb +30 -0
- data/spec/cmd_keystore_spec.rb +97 -0
- data/spec/cmd_password_spec.rb +62 -0
- data/spec/cmd_status_spec.rb +239 -0
- data/spec/cmd_syncdown_spec.rb +86 -0
- data/spec/cmd_syncup_spec.rb +62 -0
- data/spec/cmd_usage_spec.rb +36 -0
- data/spec/fixtures/.mrmuranorc +9 -0
- data/spec/fixtures/ProjectFiles/invalid.yaml +9 -0
- data/spec/fixtures/ProjectFiles/only_meta.yaml +24 -0
- data/spec/fixtures/ProjectFiles/with_routes.yaml +27 -0
- data/spec/fixtures/SolutionFiles/0.2.0.json +20 -0
- data/spec/fixtures/SolutionFiles/0.2.0_invalid.json +18 -0
- data/spec/fixtures/SolutionFiles/0.2.json +21 -0
- data/spec/fixtures/SolutionFiles/0.3.0.json +20 -0
- data/spec/fixtures/SolutionFiles/0.3.0_invalid.json +19 -0
- data/spec/fixtures/SolutionFiles/0.3.json +20 -0
- data/spec/fixtures/SolutionFiles/basic.json +20 -0
- data/spec/fixtures/SolutionFiles/secret.json +6 -0
- data/spec/fixtures/configfile +9 -0
- data/spec/fixtures/dumped_config +42 -0
- data/spec/fixtures/mrmuranorc_deleted_bob +8 -0
- data/spec/fixtures/mrmuranorc_tool_bob +3 -0
- data/spec/fixtures/product_spec_files/example.exoline.spec.yaml +116 -0
- data/spec/fixtures/product_spec_files/example.murano.spec.yaml +14 -0
- data/spec/fixtures/product_spec_files/gwe.exoline.spec.yaml +21 -0
- data/spec/fixtures/product_spec_files/gwe.murano.spec.yaml +16 -0
- data/spec/fixtures/product_spec_files/lightbulb-no-state.yaml +11 -0
- data/spec/fixtures/product_spec_files/lightbulb.yaml +14 -0
- data/spec/fixtures/roles-three.yaml +11 -0
- data/spec/fixtures/syncable_content/assets/icon.png +0 -0
- data/spec/fixtures/syncable_content/assets/index.html +0 -0
- data/spec/fixtures/syncable_content/assets/js/script.js +0 -0
- data/spec/fixtures/syncable_content/modules/table_util.lua +58 -0
- data/spec/fixtures/syncable_content/routes/manyRoutes.lua +11 -0
- data/spec/fixtures/syncable_content/routes/singleRoute.lua +5 -0
- data/spec/fixtures/syncable_content/services/devdata.lua +18 -0
- data/spec/fixtures/syncable_content/services/timers.lua +4 -0
- data/spec/spec_helper.rb +119 -0
- metadata +498 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
require 'csv'
|
|
2
|
+
require 'MrMurano/Solution-ServiceConfig'
|
|
3
|
+
|
|
4
|
+
module MrMurano
|
|
5
|
+
class Timeseries < ServiceConfig
|
|
6
|
+
def initialize
|
|
7
|
+
super
|
|
8
|
+
@serviceName = 'timeseries'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def query(query)
|
|
12
|
+
call(:query, :post, {:q=>query})
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def write(writestr)
|
|
16
|
+
call(:write, :post, { :query=>writestr })
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def command(cmd)
|
|
20
|
+
call(:command, :post, { :q=>cmd})
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
command :timeseries do |c|
|
|
27
|
+
c.syntax = %{murano timeseries}
|
|
28
|
+
c.summary = %{About Timeseries}
|
|
29
|
+
c.description = %{These commands are deprecated.
|
|
30
|
+
|
|
31
|
+
The timeseries sub-commands let you interact directly with the Timeseries
|
|
32
|
+
instance in a solution. This allows for easier debugging, being able to
|
|
33
|
+
quickly try out different queries or write test data.}
|
|
34
|
+
|
|
35
|
+
c.action do |args, options|
|
|
36
|
+
::Commander::UI.enable_paging
|
|
37
|
+
say MrMurano::SubCmdGroupHelp.new(c).get_help
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
command 'timeseries query' do |c|
|
|
42
|
+
c.syntax = %{murano timeseries query <query string>}
|
|
43
|
+
c.summary = %{Query the timeseries database}
|
|
44
|
+
c.description = %{This command is deprecated.
|
|
45
|
+
|
|
46
|
+
Query the timeseries database}
|
|
47
|
+
c.option '-o', '--output FILE', %{Download to file instead of STDOUT}
|
|
48
|
+
c.option '--[no-]json', %{Display results as raw json}
|
|
49
|
+
c.option '--[no-]csv', %{Display results as CSV}
|
|
50
|
+
|
|
51
|
+
c.action do |args,options|
|
|
52
|
+
options.defalts :json=>false, :csv=>false
|
|
53
|
+
sol = MrMurano::Timeseries.new
|
|
54
|
+
ret = sol.query args.join(' ')
|
|
55
|
+
|
|
56
|
+
$cfg['tool.outformat'] = 'json' if options.json
|
|
57
|
+
$cfg['tool.outformat'] = 'best csv' if options.csv
|
|
58
|
+
|
|
59
|
+
io=nil
|
|
60
|
+
if options.output then
|
|
61
|
+
io = File.open(options.output, 'w')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
sol.outf(ret, io) do |dd, ios|
|
|
65
|
+
(ret[:results] or []).each do |res|
|
|
66
|
+
(res[:series] or []).each do |ser|
|
|
67
|
+
sol.tabularize({
|
|
68
|
+
:title=>ser[:name],
|
|
69
|
+
:headers=>ser[:columns],
|
|
70
|
+
:rows=>ser[:values]
|
|
71
|
+
}, ios)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
io.close unless io.nil?
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
alias_command :tsq, 'timeseries query'
|
|
80
|
+
|
|
81
|
+
command 'timeseries write' do |c|
|
|
82
|
+
c.syntax = %{murano timeseries <write string>}
|
|
83
|
+
c.summary = %{Write data into the timeseries database}
|
|
84
|
+
c.description = %{This command is deprecated.
|
|
85
|
+
|
|
86
|
+
Write data into the timeseries database}
|
|
87
|
+
c.option '--[no-]json', %{Display results as raw json}
|
|
88
|
+
c.action do |args,options|
|
|
89
|
+
options.defalts :json=>false
|
|
90
|
+
$cfg['tool.outformat'] = 'json' if options.json
|
|
91
|
+
sol = MrMurano::Timeseries.new
|
|
92
|
+
ret = sol.write args.join(' ')
|
|
93
|
+
sol.outf ret
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
alias_command :tsw, 'timeseries write'
|
|
97
|
+
|
|
98
|
+
command 'timeseries command' do |c|
|
|
99
|
+
c.syntax = %{murano timeseries command <db command>}
|
|
100
|
+
c.summary = %{Execute a non-query command in the database}
|
|
101
|
+
c.description = %{This command is deprecated.
|
|
102
|
+
|
|
103
|
+
Execute a non-query command in the database}
|
|
104
|
+
c.option '--[no-]json', %{Display results as raw json}
|
|
105
|
+
c.action do |args,options|
|
|
106
|
+
options.defalts :json=>false
|
|
107
|
+
$cfg['tool.outformat'] = 'json' if options.json
|
|
108
|
+
sol = MrMurano::Timeseries.new
|
|
109
|
+
ret = sol.command args.join(' ')
|
|
110
|
+
sol.outf ret
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
# vim: set ai et sw=2 ts=2 :
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
require 'MrMurano/Solution-ServiceConfig'
|
|
3
|
+
require 'MrMurano/SubCmdGroupContext'
|
|
4
|
+
|
|
5
|
+
module MrMurano
|
|
6
|
+
module ServiceConfigs
|
|
7
|
+
class Tsdb < ServiceConfig
|
|
8
|
+
def initialize
|
|
9
|
+
super
|
|
10
|
+
@serviceName = 'tsdb'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def write(data)
|
|
14
|
+
call(:write, :post, data)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def query(query)
|
|
18
|
+
call(:query, :post, query)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def listTags
|
|
22
|
+
call(:listTags)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def listMetrics
|
|
26
|
+
call(:listMetrics)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def str_to_timestamp(str)
|
|
31
|
+
if str =~ /^\d+(u|ms|s)?$/ then
|
|
32
|
+
str
|
|
33
|
+
else
|
|
34
|
+
dt = DateTime.parse(str)
|
|
35
|
+
(dt.to_time.to_f * 1000000).to_i
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
command 'tsdb write' do |c|
|
|
43
|
+
c.syntax = %{murano tsdb write [options] <metric=value>|@<tag=value> … }
|
|
44
|
+
c.summary = %{write data}
|
|
45
|
+
c.description = %{Write data
|
|
46
|
+
|
|
47
|
+
TIMESTAMP is microseconds since unix epoch, or can be suffixed with units.
|
|
48
|
+
Units are u (microseconds), ms (milliseconds), s (seconds)
|
|
49
|
+
|
|
50
|
+
Also, many date-time formats can be parsed and will be converted to microseconds
|
|
51
|
+
}
|
|
52
|
+
c.option '--when TIMESTAMP', %{When this data happened. (defaults to now)}
|
|
53
|
+
# TODO: add option to take data from STDIN.
|
|
54
|
+
c.example 'murano tsdb write hum=45 lux=12765 @sn=44', %{Write two metrics (hum and lux) with a tag (sn)}
|
|
55
|
+
|
|
56
|
+
c.action do |args, options|
|
|
57
|
+
sol = MrMurano::ServiceConfigs::Tsdb.new
|
|
58
|
+
|
|
59
|
+
# we have hash of tags, hash of metrics, optional timestamp.
|
|
60
|
+
metrics = {}
|
|
61
|
+
tags = {}
|
|
62
|
+
args.each do |item|
|
|
63
|
+
key, value = item.split('=', 2)
|
|
64
|
+
if key[0] == '@' then
|
|
65
|
+
tags[key[1..-1]] = value.to_s #tags are always strings.
|
|
66
|
+
else
|
|
67
|
+
value = value.to_i if value == value.to_i.to_s
|
|
68
|
+
metrics[key] = value
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
data = {:tags=>tags, :metrics=>metrics}
|
|
73
|
+
if not options.when.nil? and options.when != 'now' then
|
|
74
|
+
data[:ts] = sol.str_to_timestamp(options.when)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
ret = sol.write(data)
|
|
78
|
+
if ret != {} then
|
|
79
|
+
sol.error ret
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
command 'tsdb query' do |c|
|
|
85
|
+
c.syntax = %{murano tsdb query [options] <metric>|@<tag=value> …}
|
|
86
|
+
c.summary = %{query data}
|
|
87
|
+
c.description =%{Query data from the TSDB.
|
|
88
|
+
|
|
89
|
+
FUNCS is a comma seperated list of the aggregate functions.
|
|
90
|
+
Currently: avg, min, max, count, sum. For string metrics, only count.
|
|
91
|
+
|
|
92
|
+
FILL is null, none, any integer, previous
|
|
93
|
+
|
|
94
|
+
DURATION is an integer with time unit to indicate relative time before now.
|
|
95
|
+
Units are u (microseconds), ms (milliseconds), s (seconds), m (minutes),
|
|
96
|
+
h (hours), d (days), w (weeks)
|
|
97
|
+
|
|
98
|
+
TIMESTAMP is microseconds since unix epoch, or can be suffixed with units.
|
|
99
|
+
Units are u (microseconds), ms (milliseconds), s (seconds)
|
|
100
|
+
|
|
101
|
+
Also, many date-time formats can be parsed and will be converted to microseconds
|
|
102
|
+
}
|
|
103
|
+
c.option '--start_time TIMESTAMP', %{Start time range}
|
|
104
|
+
c.option '--end_time TIMESTAMP', %{End time range; defaults to now}
|
|
105
|
+
c.option '--relative_start DURATION', %{Start time relative from now}
|
|
106
|
+
c.option '--relative_end DURATION', %{End time relative from now}
|
|
107
|
+
c.option '--sampling_size DURATION', %{The size of time slots used for downsampling}
|
|
108
|
+
c.option '--limit NUM', Integer, %{Limit number of data points returned}
|
|
109
|
+
c.option '--epoch UNIT', ['u','ms','s'], %{Set size of returned timestamps}
|
|
110
|
+
c.option '--mode MODE', ['merge','split'], %{Merge or split each returned metric}
|
|
111
|
+
c.option '--fill FILL', %{Value to fill for time slots with no data points exist in merge mode}
|
|
112
|
+
c.option '--order_by ORDER', ['desc','asc'], %{Return results in ascending or descending time order}
|
|
113
|
+
c.option '--aggregate FUNCS', %{Aggregation functions to apply}
|
|
114
|
+
|
|
115
|
+
c.option '-o', '--output FILE', %{Download to file instead of STDOUT}
|
|
116
|
+
|
|
117
|
+
c.example 'murano tsdb query hum', 'Get all hum metric entries'
|
|
118
|
+
c.example 'murano tsdb query hum @sn=45', 'Get all hum metric entries for tag sn=45'
|
|
119
|
+
c.example 'murano tsdb query hum --limit 1', 'Get just the most recent entry'
|
|
120
|
+
c.example 'murano tsdb query hum --relative_start 1h', 'Get last hour of hum entries'
|
|
121
|
+
c.example 'murano tsdb query hum --relative_start -1h', 'Get last hour of hum entries'
|
|
122
|
+
c.example 'murano tsdb query hum --relative_start 2h --relative_end 1h', 'Get hum entries of two hours ago, but not the last hours'
|
|
123
|
+
c.example 'murano tsdb query hum --sampling_size 30m', 'Get one hum entry from each 30 minute chunk of time'
|
|
124
|
+
c.example 'murano tsdb query hum --sampling_size 30m --aggregate avg', 'Get average hum entry from each 30 minute chunk of time'
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
c.action do |args, options|
|
|
128
|
+
sol = MrMurano::ServiceConfigs::Tsdb.new
|
|
129
|
+
|
|
130
|
+
query = {}
|
|
131
|
+
tags = {}
|
|
132
|
+
metrics = []
|
|
133
|
+
args.each do |arg|
|
|
134
|
+
if arg =~ /=/ then
|
|
135
|
+
# a tag.
|
|
136
|
+
k,v = arg.split('=', 2)
|
|
137
|
+
k = k[1..-1] if k[0] == '@'
|
|
138
|
+
tags[k] = v
|
|
139
|
+
else
|
|
140
|
+
metrics << arg
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
query[:tags] = tags unless tags.empty?
|
|
144
|
+
query[:metrics] = metrics unless metrics.empty?
|
|
145
|
+
|
|
146
|
+
# A query without any metrics is invalid. So if the user didn't provide any,
|
|
147
|
+
# look up all of them (well, frist however many) and use that list.
|
|
148
|
+
if query[:metrics].nil? or query[:metrics].empty? then
|
|
149
|
+
ret = sol.listMetrics
|
|
150
|
+
query[:metrics] = ret[:metrics]
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
unless options.start_time.nil? then
|
|
154
|
+
query[:start_time] = sol.str_to_timestamp(options.start_time)
|
|
155
|
+
end
|
|
156
|
+
unless options.end_time.nil? then
|
|
157
|
+
query[:end_time] = sol.str_to_timestamp(options.end_time)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
unless options.relative_start.nil? then
|
|
161
|
+
o = options.relative_start
|
|
162
|
+
o = "-#{o}" unless o[0] == '-'
|
|
163
|
+
query[:relative_start] = o
|
|
164
|
+
end
|
|
165
|
+
unless options.relative_end.nil? then
|
|
166
|
+
o = options.relative_end
|
|
167
|
+
o = "-#{o}" unless o[0] == '-'
|
|
168
|
+
query[:relative_end] = o
|
|
169
|
+
end
|
|
170
|
+
query[:sampling_size] = options.sampling_size unless options.sampling_size.nil?
|
|
171
|
+
|
|
172
|
+
query[:limit] = options.limit unless options.limit.nil?
|
|
173
|
+
query[:epoch] = options.epoch unless options.epoch.nil?
|
|
174
|
+
query[:mode] = options.mode unless options.mode.nil?
|
|
175
|
+
query[:order_by] = options.order_by unless options.order_by.nil?
|
|
176
|
+
|
|
177
|
+
query[:fill] = options.fill unless options.fill.nil?
|
|
178
|
+
unless options.aggregate.nil? then
|
|
179
|
+
query[:aggregate] = options.aggregate.split(',')
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
io=nil
|
|
183
|
+
if options.output then
|
|
184
|
+
io = File.open(options.output, 'w')
|
|
185
|
+
end
|
|
186
|
+
sol.outf sol.query(query) do |dd, ios|
|
|
187
|
+
# If aggregated, then we need to break up the columns. since each is now a
|
|
188
|
+
# hash of the aggregated functions
|
|
189
|
+
unless options.aggregate.nil? then
|
|
190
|
+
dd[:values].map! do |row|
|
|
191
|
+
row.map do |value|
|
|
192
|
+
if value.kind_of? Hash then
|
|
193
|
+
query[:aggregate].map{|qa| value[qa.to_sym]}
|
|
194
|
+
else
|
|
195
|
+
value
|
|
196
|
+
end
|
|
197
|
+
end.flatten
|
|
198
|
+
end
|
|
199
|
+
dd[:columns].map! do |col|
|
|
200
|
+
if col == 'time' then
|
|
201
|
+
col
|
|
202
|
+
else
|
|
203
|
+
query[:aggregate].map{|qa| "#{col}.#{qa.to_s}"}
|
|
204
|
+
end
|
|
205
|
+
end.flatten!
|
|
206
|
+
end
|
|
207
|
+
sol.tabularize({
|
|
208
|
+
:headers=>dd[:columns],
|
|
209
|
+
:rows=>dd[:values]
|
|
210
|
+
}, ios)
|
|
211
|
+
end
|
|
212
|
+
io.close unless io.nil?
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
command 'tsdb list tags' do |c|
|
|
217
|
+
c.syntax = %{murano tsdb list tags [options]}
|
|
218
|
+
c.summary = %{List tags}
|
|
219
|
+
c.option '--values', %{Also return the known tag values}
|
|
220
|
+
|
|
221
|
+
c.action do |args, options|
|
|
222
|
+
options.default :values=>false
|
|
223
|
+
|
|
224
|
+
sol = MrMurano::ServiceConfigs::Tsdb.new
|
|
225
|
+
ret = sol.listTags
|
|
226
|
+
# TODO: handle looping if :next != nil
|
|
227
|
+
|
|
228
|
+
if options.values then
|
|
229
|
+
sol.outf(ret[:tags]) do |dd, ios|
|
|
230
|
+
data={}
|
|
231
|
+
data[:headers] = dd.keys
|
|
232
|
+
data[:rows] = dd.keys.map{|k| dd[k]}
|
|
233
|
+
len = data[:rows].map{|i| i.length}.max
|
|
234
|
+
data[:rows].each{|r| r.fill(nil, r.length, len - r.length)}
|
|
235
|
+
data[:rows] = data[:rows].transpose
|
|
236
|
+
sol.tabularize(data, ios)
|
|
237
|
+
end
|
|
238
|
+
else
|
|
239
|
+
sol.outf ret[:tags].keys
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
command 'tsdb list metrics' do |c|
|
|
247
|
+
c.syntax = %{murano tsdb list metrics}
|
|
248
|
+
c.summary = %{List metrics}
|
|
249
|
+
|
|
250
|
+
c.action do |args, options|
|
|
251
|
+
sol = MrMurano::ServiceConfigs::Tsdb.new
|
|
252
|
+
ret = sol.listMetrics
|
|
253
|
+
# TODO: handle looping if :next != nil
|
|
254
|
+
sol.outf ret[:metrics]
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
command :tsdb do |c|
|
|
259
|
+
c.syntax = %{murano tsdb}
|
|
260
|
+
c.summary = %{About TSDB}
|
|
261
|
+
c.description = %{The tsdb sub-commands let you interact directly with the TSDB instance in a
|
|
262
|
+
solution. This allows for easier debugging, being able to quickly try out
|
|
263
|
+
different queries or write test data.}
|
|
264
|
+
|
|
265
|
+
c.action do |args, options|
|
|
266
|
+
::Commander::UI.enable_paging
|
|
267
|
+
say MrMurano::SubCmdGroupHelp.new(c).get_help
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
# vim: set ai et sw=2 ts=2 :
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'MrMurano/Solution'
|
|
2
|
+
|
|
3
|
+
command :usage do |c|
|
|
4
|
+
c.syntax = %{murano usage}
|
|
5
|
+
c.summary = %{Get usage info for project}
|
|
6
|
+
c.description = %{Get usage info for project}
|
|
7
|
+
|
|
8
|
+
c.action do |args,options|
|
|
9
|
+
sol = MrMurano::Solution.new
|
|
10
|
+
sol.outf(sol.usage) do |dd,ios|
|
|
11
|
+
headers = ['', :Quota, :Daily, :Monthly, :Total]
|
|
12
|
+
rows = []
|
|
13
|
+
dd.each_pair do |key,value|
|
|
14
|
+
quota = value[:quota] or {}
|
|
15
|
+
usage = value[:usage] or {}
|
|
16
|
+
rows << [key, quota[:daily], usage[:calls_daily], usage[:calls_monthly], usage[:calls_total]]
|
|
17
|
+
end
|
|
18
|
+
sol.tabularize({:headers=>headers,:rows=>rows}, ios)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# vim: set ai et sw=2 ts=2 :
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#compdef <%= program :name %>
|
|
2
|
+
|
|
3
|
+
__<%= program :name %>_common_options=(
|
|
4
|
+
<% for option in @options -%>
|
|
5
|
+
<%- if flatswitches(option).count > 1 -%>
|
|
6
|
+
{<%= flatswitches(option).join(',') %>}<%= takesArg(option) %>:"<%= optionDesc option %>"
|
|
7
|
+
<%- else -%>
|
|
8
|
+
"<%= flatswitches(option).first %><%= takesArg(option) %>:<%= optionDesc option %>"
|
|
9
|
+
<%- end -%>
|
|
10
|
+
<% end %>
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
_<%= program :name %> () {
|
|
14
|
+
local curcontext="$curcontext" state line
|
|
15
|
+
typeset -A opt_args
|
|
16
|
+
|
|
17
|
+
# except this fails when a command only has one arg and then options.
|
|
18
|
+
_arguments -C \
|
|
19
|
+
':command:->command' \
|
|
20
|
+
'*::options:->options'
|
|
21
|
+
#echo "\n=$curcontext=$state=$words=\n"
|
|
22
|
+
case $state in
|
|
23
|
+
(command)
|
|
24
|
+
local -a list
|
|
25
|
+
list=(
|
|
26
|
+
<%- for name, subs in cmdTree -%>
|
|
27
|
+
<%- cmd = subs["\0cmd"] -%>
|
|
28
|
+
<%- if cmd.nil? -%>
|
|
29
|
+
<%= name %>:' '
|
|
30
|
+
<%-else-%>
|
|
31
|
+
<%= name %>:'<%= cmd.summary || cmd.description.lines[0] -%>'
|
|
32
|
+
<%-end-%>
|
|
33
|
+
<%-end-%>
|
|
34
|
+
)
|
|
35
|
+
_describe -t firstArg 'firstArg' list
|
|
36
|
+
_describe -t options 'global options' __<%= program :name %>_common_options
|
|
37
|
+
;;
|
|
38
|
+
(options)
|
|
39
|
+
case $line[1] in
|
|
40
|
+
<%- for name, subs in cmdTree -%>
|
|
41
|
+
(<%= name %>)
|
|
42
|
+
__<%=program :name%>-<%= name %>
|
|
43
|
+
;;
|
|
44
|
+
<%-end-%>
|
|
45
|
+
esac
|
|
46
|
+
;;
|
|
47
|
+
esac
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
<%- for name, subs in cmdTree -%>
|
|
51
|
+
<%- command = subs["\0cmd"]; subs = subs.reject{|k,_| k == "\0cmd"} -%>
|
|
52
|
+
__<%=program :name%>-<%= name %> () {
|
|
53
|
+
local curcontext="$curcontext" state line
|
|
54
|
+
typeset -A opt_args
|
|
55
|
+
|
|
56
|
+
_arguments -C \
|
|
57
|
+
':command:->command' \
|
|
58
|
+
'*::options:->options'
|
|
59
|
+
|
|
60
|
+
case $state in
|
|
61
|
+
(command)
|
|
62
|
+
<%- unless subs.empty? -%>
|
|
63
|
+
local -a subcommands
|
|
64
|
+
subcommands=(
|
|
65
|
+
<%- for sname, ssubs in subs -%>
|
|
66
|
+
<%- command = ssubs["\0cmd"] -%>
|
|
67
|
+
<%- if command.nil? then -%>
|
|
68
|
+
<%=sname%>:''
|
|
69
|
+
<%-else-%>
|
|
70
|
+
<%=sname%>:'<%= command.summary || command.description.lines[0] -%>'
|
|
71
|
+
<%-end-%>
|
|
72
|
+
<%-end-%>
|
|
73
|
+
)
|
|
74
|
+
_describe -t commands 'subcommand' subcommands
|
|
75
|
+
<%-end-%>
|
|
76
|
+
_describe -t options 'global options' __<%= program :name %>_common_options
|
|
77
|
+
<%- unless command.nil? or command.options.empty? then -%>
|
|
78
|
+
_arguments \
|
|
79
|
+
<%- for option in command.options -%>
|
|
80
|
+
<%- if flatswitches(option).count > 1 -%>
|
|
81
|
+
{<%= flatswitches(option).join(',') %>}<%= takesArg(option) %>"[<%= optionDesc option %>]: :" \
|
|
82
|
+
<%- else -%>
|
|
83
|
+
"<%= flatswitches(option).first %><%= takesArg(option) %>[<%= optionDesc option %>]: :" \
|
|
84
|
+
<%- end -%>
|
|
85
|
+
<%- end -%>
|
|
86
|
+
<%- end %>
|
|
87
|
+
;;
|
|
88
|
+
(options)
|
|
89
|
+
case $line[1] in
|
|
90
|
+
<%- for sname, ssubs in subs -%>
|
|
91
|
+
<%- command = ssubs["\0cmd"]; subs = ssubs.reject{|k,_| k == "\0cmd"} -%>
|
|
92
|
+
(<%=sname%>)
|
|
93
|
+
_describe -t options 'global options' __<%= program :name %>_common_options
|
|
94
|
+
<%- unless command.nil? or command.options.empty? then -%>
|
|
95
|
+
_arguments \
|
|
96
|
+
<%- for option in command.options -%>
|
|
97
|
+
<%- if flatswitches(option).count > 1 -%>
|
|
98
|
+
{<%= flatswitches(option).join(',') %>}<%= takesArg(option) %>"[<%= optionDesc option %>]: :" \
|
|
99
|
+
<%- else -%>
|
|
100
|
+
"<%= flatswitches(option).first %><%= takesArg(option) %>[<%= optionDesc option %>]: :" \
|
|
101
|
+
<%- end -%>
|
|
102
|
+
<%- end -%>
|
|
103
|
+
<%- end %>
|
|
104
|
+
;;
|
|
105
|
+
<%-end-%>
|
|
106
|
+
esac
|
|
107
|
+
;;
|
|
108
|
+
esac
|
|
109
|
+
}
|
|
110
|
+
<%- end -%>
|
|
111
|
+
|
|
112
|
+
# vim: set ai et sw=2 ts=2 :
|