Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::resource_monitor_plugin_impl Class Reference

Public Member Functions

 resource_monitor_plugin_impl ()
 
void set_program_options (options_description &, options_description &cfg)
 
void plugin_initialize (const appbase::variables_map &options)
 
void plugin_startup ()
 
void plugin_shutdown ()
 
void monitor_directory (const bfs::path &path)
 

Detailed Description

Definition at line 40 of file resource_monitor_plugin.cpp.

Constructor & Destructor Documentation

◆ resource_monitor_plugin_impl()

sysio::resource_monitor_plugin_impl::resource_monitor_plugin_impl ( )
inline

Member Function Documentation

◆ monitor_directory()

void sysio::resource_monitor_plugin_impl::monitor_directory ( const bfs::path & path)
inline

Definition at line 132 of file resource_monitor_plugin.cpp.

132 {
133 dlog("${path} registered to be monitored", ("path", path.string()));
134 directories_registered.push_back(path);
135 }
#define dlog(FORMAT,...)
Definition logger.hpp:101
Here is the call graph for this function:

◆ plugin_initialize()

void sysio::resource_monitor_plugin_impl::plugin_initialize ( const appbase::variables_map & options)
inline

Definition at line 60 of file resource_monitor_plugin.cpp.

60 {
61 dlog("plugin_initialize");
62
63 auto interval = options.at("resource-monitor-interval-seconds").as<uint32_t>();
64 SYS_ASSERT(interval >= monitor_interval_min && interval <= monitor_interval_max, chain::plugin_config_exception,
65 "\"resource-monitor-interval-seconds\" must be between ${monitor_interval_min} and ${monitor_interval_max}", ("monitor_interval_min", monitor_interval_min) ("monitor_interval_max", monitor_interval_max));
66 space_handler.set_sleep_time(interval);
67 ilog("Monitoring interval set to ${interval}", ("interval", interval));
68
69 auto threshold = options.at("resource-monitor-space-threshold").as<uint32_t>();
70 SYS_ASSERT(threshold >= space_threshold_min && threshold <= space_threshold_max, chain::plugin_config_exception,
71 "\"resource-monitor-space-threshold\" must be between ${space_threshold_min} and ${space_threshold_max}", ("space_threshold_min", space_threshold_min) ("space_threshold_max", space_threshold_max));
72 space_handler.set_threshold(threshold, threshold - space_threshold_warning_diff);
73 ilog("Space usage threshold set to ${threshold}", ("threshold", threshold));
74
75 if (options.count("resource-monitor-not-shutdown-on-threshold-exceeded")) {
76 // If set, not shutdown
77 space_handler.set_shutdown_on_exceeded(false);
78 ilog("Shutdown flag when threshold exceeded set to false");
79 } else {
80 // Default will shut down
81 space_handler.set_shutdown_on_exceeded(true);
82 ilog("Shutdown flag when threshold exceeded set to true");
83 }
84
85 auto warning_interval = options.at("resource-monitor-warning-interval").as<uint32_t>();
86 SYS_ASSERT(warning_interval >= warning_interval_min && warning_interval <= warning_interval_max, chain::plugin_config_exception,
87 "\"resource-monitor-warning-interval\" must be between ${warning_interval_min} and ${warning_interval_max}", ("warning_interval_min", warning_interval_min) ("warning_interval_max", warning_interval_max));
88 space_handler.set_warning_interval(warning_interval);
89 ilog("Warning interval set to ${warning_interval}", ("warning_interval", warning_interval));
90 }
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
void set_threshold(uint32_t new_threshold, uint32_t new_warning_threshold)
void set_warning_interval(uint32_t new_warning_interval)
void set_shutdown_on_exceeded(bool new_shutdown_on_exceeded)
#define ilog(FORMAT,...)
Definition logger.hpp:118
unsigned int uint32_t
Definition stdint.h:126
Here is the call graph for this function:

◆ plugin_shutdown()

void sysio::resource_monitor_plugin_impl::plugin_shutdown ( )
inline

Definition at line 121 of file resource_monitor_plugin.cpp.

121 {
122 ilog("shutdown...");
123
124 ctx.stop();
125
126 // Wait for the thread to end
127 monitor_thread.join();
128
129 ilog("exit shutdown");
130 }

◆ plugin_startup()

void sysio::resource_monitor_plugin_impl::plugin_startup ( )
inline

Definition at line 93 of file resource_monitor_plugin.cpp.

93 {
94 ilog("Creating and starting monitor thread");
95
96 // By now all plugins are initialized.
97 // Find out filesystems containing the directories requested
98 // so far.
99 for ( auto& dir: directories_registered ) {
100 space_handler.add_file_system( dir );
101
102 // A directory like "data" contains subdirectories like
103 // "block". Those subdirectories can mount on different
104 // file systems. Make sure they are taken care of.
105 for (bfs::directory_iterator itr(dir); itr != bfs::directory_iterator(); ++itr) {
106 if (fc::is_directory(itr->path())) {
107 space_handler.add_file_system( itr->path() );
108 }
109 }
110 }
111
112 monitor_thread = std::thread( [this] {
113 fc::set_os_thread_name( "resmon" ); // console_appender uses 9 chars for thread name reporting.
114 space_handler.space_monitor_loop();
115
116 ctx.run();
117 } );
118 }
void add_file_system(const bfs::path &path_name)
bool is_directory(const path &p)
void set_os_thread_name(const string &name)
Here is the call graph for this function:

◆ set_program_options()

void sysio::resource_monitor_plugin_impl::set_program_options ( options_description & ,
options_description & cfg )
inline

Definition at line 47 of file resource_monitor_plugin.cpp.

47 {
48 cfg.add_options()
49 ( "resource-monitor-interval-seconds", bpo::value<uint32_t>()->default_value(def_interval_in_secs),
50 "Time in seconds between two consecutive checks of resource usage. Should be between 1 and 300" )
51 ( "resource-monitor-space-threshold", bpo::value<uint32_t>()->default_value(def_space_threshold),
52 "Threshold in terms of percentage of used space vs total space. If used space is above (threshold - 5%), a warning is generated. Unless resource-monitor-not-shutdown-on-threshold-exceeded is enabled, a graceful shutdown is initiated if used space is above the threshold. The value should be between 6 and 99" )
53 ( "resource-monitor-not-shutdown-on-threshold-exceeded",
54 "Used to indicate nodeop will not shutdown when threshold is exceeded." )
55 ( "resource-monitor-warning-interval", bpo::value<uint32_t>()->default_value(def_monitor_warning_interval),
56 "Number of resource monitor intervals between two consecutive warnings when the threshold is hit. Should be between 1 and 450" )
57 ;
58 }

The documentation for this class was generated from the following file: