Class: Store::Store

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/store/store.rb

Overview

Parent Store class. Contains mostly defaults

Direct Known Subclasses

Errorstore, Flatfile, Graphite, Idn, Newrelic, Simple, Vaultaire

Constant Summary

Constants included from Helpers

Helpers::REDIS_KEY

Instance Method Summary collapse

Methods included from Helpers

#data_sanitize, #delete_metrics_cache, #get_json, #init_lib, #init_source, #init_store, #interpolate, #is_up?, #json_metrics, #json_metrics_list, #keysplit, #mandatory_param, #optional_param, #origin_settings, #redis_conn, #top_tail_pad

Constructor Details

#initialize(origin, settings) ⇒ Store

Store given settings into more user friendly forms


6
7
8
9
# File 'lib/store/store.rb', line 6

def initialize origin, settings
	@settings = settings
	@origin_id = origin
end

Instance Method Details

#get_metricObject

Stub for child class override

Raises:

  • (NotImplemented)

22
23
24
# File 'lib/store/store.rb', line 22

def get_metric
	raise NotImplemented
end

#get_metric_urlObject

Stub for child class override

Raises:

  • (NotImplemented)

12
13
14
# File 'lib/store/store.rb', line 12

def get_metric_url
	raise NotImplemented
end

#get_metrics_listObject

Stub for child class override

Raises:

  • (NotImplemented)

17
18
19
# File 'lib/store/store.rb', line 17

def get_metrics_list
	raise NotImplemented
end

#hidden_keysObject

A list of store settings keys that should NEVER have their settings written out to the interface.


71
72
73
# File 'lib/store/store.rb', line 71

def hidden_keys
	["password"]
end

#live?Boolean

Default: all child stores can be queried for 'live' updating of data. Override in child class if this is not the case

Returns:

  • (Boolean)

33
34
35
# File 'lib/store/store.rb', line 33

def live?
	true
end

#metadata(m) ⇒ Object

Default: the metadata for a metric is itself. Override in child class if this is not your way


39
40
41
# File 'lib/store/store.rb', line 39

def  m
	m
end

#metadata_table(m) ⇒ Object

Default: make a nice table. Override in child class for something more fancy


27
28
29
# File 'lib/store/store.rb', line 27

def  m
	'<p align="left">'+m.gsub(SEP, "<br>")+"</p>"
end

#refresh_metrics_cache(_alias = nil) ⇒ Object

Default: Query a list of metrics for the store, and save them to redis Override in child class if your metric list is too big, or not redis-ready


45
46
47
48
49
50
51
52
53
# File 'lib/store/store.rb', line 45

def refresh_metrics_cache _alias=nil
        metrics = get_metrics_list
        
		r = redis_conn
        
		metrics.each {|m|
                r.set "#{REDIS_KEY}:#{@origin_id}:#{m}", 1
        }
end

#search_metrics(q, args = {}) ⇒ Object

Default: search redis (populated via `refresh_metrics_cache` for metrics Override in child class to something dynamic if you do not leverage redis

Raises:


57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/store/store.rb', line 57

def search_metrics q, args={}
        raise Store::Error, "Unable to connect to #{@origin_id} backend at #{@base_url}" unless is_up?

		# TODO Pending redis pagination logic
        return [] if args[:page] and args[:page].to_i > 1

        r = redis_conn
        keys = r.keys "#{REDIS_KEY}:#{@origin_id}#{q}"
        keys.map!{|x|x.split(":").last}
        keys.map!{|x| "#{@origin_id}#{SEP}#{x}"}
        keys
end

#supress_settingsObject

When parsing the settings file for the settings modal, suppress certain information


76
77
78
79
80
81
82
83
# File 'lib/store/store.rb', line 76

def supress_settings
	hide = hidden_keys.map{|k| k.to_sym}
	sett = @settings.store_settings.to_a.map do |k,v|
		v = "*********" if hide.include? k
		[k,v]
	end
	sett
end