Alerts are notifications that report the system resource allocation problems such as approaching or exceeding certain limits. Alerts are usually used for monitoring of the Container health, predicting its performance, or collecting information that can be used to optimize the Container performance. Use the alertmBinding
class to check if a Container has alerts of any kind currently raised and to retrieve the alert data if it does.
The alert levels are described in the table below.
Alert level |
ID |
Description |
Green |
0 |
Normal operation. This alert is raised when one of the higher-level alerts is canceled. |
Yellow |
1 |
Moderately dangerous situation. The specified parameter is coming close (within 10%) to its soft limit barrier. |
Red |
2 |
Critical situation. The parameter exceeded its soft limit or came very close to the hard limit. Depending on the parameter type, either some process can be killed at any time now, or the next resource allocation request can be refused. |
Black |
3 |
The worst-case scenario. The hard limit was reached, the requested resource allocation was refused or some process overusing the resource was killed. Once raised, the black alert remains in effect for 5 minutes. |
A Virtuozzo Container may have multiple alerts raised at any given time. The following function demonstrates how you can check if a Container has any alerts currently raised, and to retrieve the alert information if it does. The function accepts the list of Containers for which to check and retrieve the alert information.
/// <summary>
/// Sample function GetAlerts.
/// Retrieves the system alert information for the specified Container.
/// </summary>
/// <param name="ve_eid">
/// Server ID of the Container to get the alerts for.
/// </param>
/// <returns>A string containing the alert information.</returns>
///
public string GetAlerts(string[] ve_eid)
{
string list_result = "";
try {
// Instantiate the proxy class
alertmBinding alertm = (alertmBinding)binder.InitBinding(typeof(alertmBinding));
// The main input object.
get_alerts get_alerts_input = new get_alerts();
// Set Container list.
get_alerts_input.eid_list = ve_eid;
// Get the alert information.
foreach (eventType al_event in alertm.get_alerts(get_alerts_input)) {
list_result += "Data: \n";
// Get the alert data.
resource_alertType res_data = (resource_alertType)al_event.data.event_data;
// Read the alert data.
list_result += " Class: " + res_data.@class + "\n" +
// Get counter.
" Counter: " + res_data.counter + "\n" +
// Get eid.
" Eid: " + res_data.eid + "\n" +
// Get instance.
" Instance: " + res_data.instance + "\n" +
// Get type.
" Type: " + res_data.type.ToString() + "\n" +
// Get current value.
" Cur: " + res_data.cur + "\n" +
// Get hard limit.
" Hard: " + res_data.hard + "\n" +
// Get soft limit.
" Soft: " + res_data.soft + "\n" +
// Get event name.
"Name: " + al_event.info.name + "\n" +
// Get count.
"Count: " + al_event.count.ToString() + "\n" +
// Get event category.
"Category: " + al_event.category + "\n" +
// Get event message.
"Message: " + System.Text.ASCIIEncoding.ASCII.GetString(al_event.info.message) + "\n" +
// Get parameters
"Parameters: ";
/* Call the helper function to extract the
* event message parameter values.
*/
GetParams(al_event.info.parameter, ref list_result);
}
}
catch (Exception e) {
list_result += "Exception: " + e.Message;
}
return list_result;
}
/// <summary>
/// Sample function GetParams.
/// This is a helper function that extracts the
/// alert message parameter values.
/// </summary>
/// <param name="parameter">The name of the parameter.</param>
/// <param name="list">
/// Output. Values.
/// </param>
///
void GetParams(infoType[] parameter, ref string list)
{
string ss = " ";
foreach (infoType param in parameter) {
list += ss + "Message: " + System.Text.ASCIIEncoding.ASCII.GetString(param.message) +
" Info name: " + param.name + "\n";
if (param.parameter != null) {
GetParams(param.parameter, ref list);
}
}
}