Class: Sensu::Server::Tessen
- Inherits:
-
Object
- Object
- Sensu::Server::Tessen
- Defined in:
- lib/sensu/server/tessen.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#options ⇒ Object
Returns the value of attribute options.
-
#redis ⇒ Object
Returns the value of attribute redis.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#timers ⇒ Object
readonly
Returns the value of attribute timers.
Instance Method Summary collapse
-
#create_data ⇒ Hash
Create data to be sent to the Tessen service.
-
#enabled? ⇒ TrueClass, FalseClass
Determine if Tessen is enabled (opt-in).
-
#get_client_count {|count| ... } ⇒ Object
Get the Sensu client count for the installation.
-
#get_install_id ⇒ Object
Get the Sensu installation ID.
-
#get_server_count {|count| ... } ⇒ Object
Get the Sensu server count for the installation.
-
#get_version_info ⇒ Object
Get the Sensu version info for the local Sensu service.
-
#initialize(options = {}) ⇒ Tessen
constructor
Create a new instance of Tessen.
-
#run ⇒ Object
Run Tessen, scheduling data reports (every 6h).
-
#schedule_data_reports ⇒ Object
Schedule data reports, sending data to the Tessen service immediately and then every 6 hours after that.
-
#send_data(&block) ⇒ Object
Send data to the Tessen service.
-
#stop ⇒ Object
Stop Tessen, cancelling and clearing timers.
-
#tessen_api_request(data) ⇒ Object
Make a Tessen service API request.
Constructor Details
#initialize(options = {}) ⇒ Tessen
Create a new instance of Tessen. The instance variable ‘@timers` is use to track EventMachine timers for stopping/shutdown.
16 17 18 19 20 21 22 |
# File 'lib/sensu/server/tessen.rb', line 16 def initialize(={}) @timers = [] @settings = [:settings] @logger = [:logger] @redis = [:redis] = @settings.to_hash.fetch(:tessen, {}) end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/sensu/server/tessen.rb', line 7 def logger @logger end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/sensu/server/tessen.rb', line 7 def end |
#redis ⇒ Object
Returns the value of attribute redis.
7 8 9 |
# File 'lib/sensu/server/tessen.rb', line 7 def redis @redis end |
#settings ⇒ Object
Returns the value of attribute settings.
7 8 9 |
# File 'lib/sensu/server/tessen.rb', line 7 def settings @settings end |
#timers ⇒ Object (readonly)
Returns the value of attribute timers.
8 9 10 |
# File 'lib/sensu/server/tessen.rb', line 8 def timers @timers end |
Instance Method Details
#create_data ⇒ Hash
Create data to be sent to the Tessen service.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/sensu/server/tessen.rb', line 69 def create_data get_install_id do |install_id| get_client_count do |client_count| get_server_count do |server_count| identity_key = .fetch(:identity_key, "") flavour, version = get_version_info = Time.now.to_i data = { :tessen_identity_key => identity_key, :install => { :id => install_id, :sensu_flavour => flavour, :sensu_version => version }, :metrics => { :points => [ { :name => "client_count", :value => client_count, :timestamp => }, { :name => "server_count", :value => server_count, :timestamp => } ] } } yield data end end end end |
#enabled? ⇒ TrueClass, FalseClass
Determine if Tessen is enabled (opt-in).
27 28 29 30 31 32 33 34 35 |
# File 'lib/sensu/server/tessen.rb', line 27 def enabled? enabled = [:enabled] == true unless enabled note = "tessen collects anonymized data to help inform the sensu team about installations" note << " - you can opt-in via configuration: {\"tessen\": {\"enabled\": true}}" @logger.info("the tessen call-home mechanism is not enabled", :note => note) end enabled end |
#get_client_count {|count| ... } ⇒ Object
Get the Sensu client count for the installation. This count currently includes proxy clients.
120 121 122 123 124 |
# File 'lib/sensu/server/tessen.rb', line 120 def get_client_count @redis.scard("clients") do |count| yield count.to_i end end |
#get_install_id ⇒ Object
Get the Sensu installation ID. The ID is randomly generated and stored in Redis. This ID provides context and allows multiple Sensu servers to report data for the same installation.
107 108 109 110 111 112 113 |
# File 'lib/sensu/server/tessen.rb', line 107 def get_install_id @redis.setnx("tessen:install_id", rand(36**12).to_s(36)) do |created| @redis.get("tessen:install_id") do |install_id| yield install_id end end end |
#get_server_count {|count| ... } ⇒ Object
Get the Sensu server count for the installation.
130 131 132 133 134 |
# File 'lib/sensu/server/tessen.rb', line 130 def get_server_count @redis.scard("servers") do |count| yield count.to_i end end |
#get_version_info ⇒ Object
Get the Sensu version info for the local Sensu service.
137 138 139 140 141 142 143 |
# File 'lib/sensu/server/tessen.rb', line 137 def get_version_info if defined?(Sensu::Enterprise::VERSION) ["enterprise", Sensu::Enterprise::VERSION] else ["core", Sensu::VERSION] end end |
#run ⇒ Object
Run Tessen, scheduling data reports (every 6h).
38 39 40 |
# File 'lib/sensu/server/tessen.rb', line 38 def run schedule_data_reports end |
#schedule_data_reports ⇒ Object
Schedule data reports, sending data to the Tessen service immediately and then every 6 hours after that.
52 53 54 55 56 57 |
# File 'lib/sensu/server/tessen.rb', line 52 def schedule_data_reports send_data @timers << EM::PeriodicTimer.new(21600) do send_data end end |
#send_data(&block) ⇒ Object
Send data to the Tessen service.
60 61 62 63 64 |
# File 'lib/sensu/server/tessen.rb', line 60 def send_data(&block) create_data do |data| tessen_api_request(data, &block) end end |
#stop ⇒ Object
Stop Tessen, cancelling and clearing timers.
43 44 45 46 47 48 |
# File 'lib/sensu/server/tessen.rb', line 43 def stop @timers.each do |timer| timer.cancel end @timers.clear end |
#tessen_api_request(data) ⇒ Object
Make a Tessen service API request.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/sensu/server/tessen.rb', line 148 def tessen_api_request(data) @logger.debug("sending data to the tessen call-home service", { :data => data, :options => }) connection = {} connection[:proxy] = [:proxy] if [:proxy] = {:body => Sensu::JSON.dump(data)} http = EM::HttpRequest.new("https://tessen.sensu.io/v1/data", connection).post() http.callback do @logger.debug("tessen call-home service response", :status => http.response_header.status) yield if block_given? end http.errback do @logger.debug("tessen call-home service error", :error => http.error) yield if block_given? end end |