Class: Echo_cli::Helper
- Inherits:
-
Object
- Object
- Echo_cli::Helper
- Defined in:
- lib/echo_cli/cli.rb
Instance Method Summary collapse
- #check_get_tags(metric) ⇒ Object
- #get_metric(metric) ⇒ Object
- #get_metric_name(metric) ⇒ Object
- #get_query(time_start, time_end, metric, tags) ⇒ Object
- #set_envs ⇒ Object
- #stfu ⇒ Object
- #unset_envs ⇒ Object
Instance Method Details
#check_get_tags(metric) ⇒ Object
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/echo_cli/cli.rb', line 394 def (metric) = "" if metric.include? "." = metric[metric.index(".")+1..-1] + "." metric = metric[0..metric.index(".")-1] toReturn = "" count = 1 while .include?(".") do toReturn = toReturn + "\"tag" + count.to_s + "\": \"" + [0...index(".")-1] + "\"" count = count + 1 = [.index(".")+1..-1] if .include?(".") toReturn = toReturn + ",\n" end end = toReturn end return end |
#get_metric(metric) ⇒ Object
417 418 419 420 421 422 423 |
# File 'lib/echo_cli/cli.rb', line 417 def get_metric(metric) metric = metric.gsub(/'/,"") if metric.include? ":" metric = metric[0..metric.index(":")-1] end return metric end |
#get_metric_name(metric) ⇒ Object
425 426 427 428 429 430 |
# File 'lib/echo_cli/cli.rb', line 425 def get_metric_name(metric) if metric.include?(".") metric = metric[0..metric.index(".")-1] end return metric end |
#get_query(time_start, time_end, metric, tags) ⇒ Object
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/echo_cli/cli.rb', line 432 def get_query(time_start, time_end, metric, ) opentsdb_query = "{ \"start\": " + time_start + ", \"end\": " + time_end + ", \"queries\": [ { \"aggregator\": \"sum\", \"metric\": \"" + metric + "\", \"tags\": {" + + "} } ] }" return opentsdb_query end |
#set_envs ⇒ Object
449 450 451 452 |
# File 'lib/echo_cli/cli.rb', line 449 def set_envs ENV["http_proxy"] = ENV["HTTP_PROXY"] ENV["https_proxy"] = ENV["HTTPS_PROXY"] end |
#stfu ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/echo_cli/cli.rb', line 376 def stfu begin orig_stderr = $stderr.clone orig_stdout = $stdout.clone $stderr.reopen File.new('/dev/null', 'w') $stdout.reopen File.new('/dev/null', 'w') retval = yield rescue Exception => e $stdout.reopen orig_stdout $stderr.reopen orig_stderr raise e ensure $stdout.reopen orig_stdout $stderr.reopen orig_stderr end retval end |
#unset_envs ⇒ Object
454 455 456 457 |
# File 'lib/echo_cli/cli.rb', line 454 def unset_envs ENV["http_proxy"] = ENV[""] ENV["https_proxy"] = ENV[""] end |