Class: Intranet::System::Responder
- Inherits:
-
AbstractResponder
- Object
- AbstractResponder
- Intranet::System::Responder
- Includes:
- Core::HamlWrapper
- Defined in:
- lib/intranet/system/responder.rb
Overview
The responder for the System monitor module of the Intranet.
Class Method Summary collapse
-
.module_homepage ⇒ String
The homepage of the module.
-
.module_name ⇒ String
Returns the name of the module.
-
.module_version ⇒ String
The version of the module, according to semantic versionning.
Instance Method Summary collapse
-
#css_dependencies ⇒ Array
Provides the list of Cascade Style Sheets (CSS) dependencies for this module.
-
#generate_page(path, query) ⇒ Array
Generates the HTML content associated to the given
path
andquery
. -
#in_menu? ⇒ Boolean
Specifies if the responder instance should be displayed in the main navigation menu or not.
-
#initialize(provider, in_menu = true) ⇒ Responder
constructor
Initializes a new System responder instance.
-
#js_dependencies ⇒ Array
Provides the list of Javascript files (JS) dependencies for this module.
-
#resources_dir ⇒ String
Specifies the absolute path to the resources directory for that module.
-
#title ⇒ String
The title of the System monitor module, as displayed on the web page.
Constructor Details
#initialize(provider, in_menu = true) ⇒ Responder
Initializes a new System responder instance.
37 38 39 40 |
# File 'lib/intranet/system/responder.rb', line 37 def initialize(provider, = true) @provider = provider @in_menu = end |
Class Method Details
.module_homepage ⇒ String
The homepage of the module.
29 30 31 |
# File 'lib/intranet/system/responder.rb', line 29 def self.module_homepage HOMEPAGE_URL end |
.module_name ⇒ String
Returns the name of the module.
17 18 19 |
# File 'lib/intranet/system/responder.rb', line 17 def self.module_name NAME end |
.module_version ⇒ String
The version of the module, according to semantic versionning.
23 24 25 |
# File 'lib/intranet/system/responder.rb', line 23 def self.module_version VERSION end |
Instance Method Details
#css_dependencies ⇒ Array
Provides the list of Cascade Style Sheets (CSS) dependencies for this module.
98 99 100 |
# File 'lib/intranet/system/responder.rb', line 98 def css_dependencies super + ['design/style.css'] end |
#generate_page(path, query) ⇒ Array
Generates the HTML content associated to the given path
and query
.
REST API Description:
Read-only access to system statistics under /api
using GET
method. Response is in JSON format with the following structure:
{
"hostname": "trantor",
"loadavg": [0.42,0.48,0.56],
"cpu": {
"model": "Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz",
"nb_cores": 4
},
"ram": { "total": 8243249152, "used": 3149385728 },
"swaps": {
"/dev/sdb1": { "total": 19999485952, "used": 0 }
},
"partitions": {
"/boot/efi": { "total": 509640704, "used": 135168 },
"/": { "total": 58306199552, "used": 11482054656 }
}
}
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/intranet/system/responder.rb', line 78 def generate_page(path, query) case path when %r{^/index\.html$} return 206, 'text/html', generate_home_html when %r{^/api$} return 200, 'application/json', @provider.stats.to_json when %r{^/i18n\.js$} return 200, 'text/javascript', generate_i18n_js end super(path, query) end |
#in_menu? ⇒ Boolean
Specifies if the responder instance should be displayed in the main navigation menu or not.
45 46 47 |
# File 'lib/intranet/system/responder.rb', line 45 def @in_menu end |
#js_dependencies ⇒ Array
Provides the list of Javascript files (JS) dependencies for this module.
104 105 106 |
# File 'lib/intranet/system/responder.rb', line 104 def js_dependencies super + ['i18n.js', 'design/jsystem.js'] end |
#resources_dir ⇒ String
Specifies the absolute path to the resources directory for that module.
51 52 53 |
# File 'lib/intranet/system/responder.rb', line 51 def resources_dir File.absolute_path(File.join('..', 'resources'), __dir__) end |
#title ⇒ String
The title of the System monitor module, as displayed on the web page.
92 93 94 |
# File 'lib/intranet/system/responder.rb', line 92 def title I18n.t('system.monitor') end |