alerts

来源:互联网 发布:如何做淘宝客赚钱 编辑:程序博客网 时间:2024/05/17 13:41
了解数据库的日常操作,有助于我们提前发现可能会发生的问题
1.Server-Generated Alerts
Alerts are automatically generated when a problem occurs or whendata does not
match expected values for metrics, such as the following:
■ Physical Reads Per Second
■ User Commits Per Second
■ SQL Service Response Time



You can view and change threshold settings for the server alertmetrics using the SET_THRESHOLD  andGET_THRESHOLD  procedures of theDBMS_SERVER_ALERTS  
PL/SQL package.
The DBMS_AQ and DBMS_AQADM packages provide procedures foraccessing and reading alert messages in the alert queue.


1.Setting Threshold Levels
 set thresholds with theSET_THRESHOLD  procedure for CPU time for eachuser call for an instance:

DBMS_SERVER_ALERT.SET_THRESHOLD(
 DBMS_SERVER_ALERT.CPU_TIME_PER_CALL,DBMS_SERVER_ALERT.OPERATOR_GE, '8000',
 DBMS_SERVER_ALERT.OPERATOR_GE, '10000', 1, 2,'inst1',
 DBMS_SERVER_ALERT.OBJECT_TYPE_SERVICE,'main.regress.rdbms.dev.us.oracle.com');

In this example, a warning alert is issued when CPU time exceeds8000 microseconds for each user call and a criticalalert  is issued when CPU time exceeds 10,000microseconds for each user call. The arguments include:


■ CPU_TIME_PER_CALL specifies the metric identifier. For a list ofsupport metrics, see  Oracle Database PL/SQLPackages and Types Reference.

■ The observation period is set to 1 minute. This period specifiesthe number of minutes that the condition must deviate from thethreshold value before the alert is issued.

■ The number of consecutive occurrences is set to 2. This numberspecifies how
many times the metric value must violate the threshold valuesbefore the alert is generated.

■ The name of the instance is set to  inst1.

■ The constant  DBMS_ALERT.OBJECT_TYPE_SERVICEspecifies the object type on
which the threshold is set. In this example, the service nameismain.regress.rdbms.dev.us.oracle.com .



2.Retrieving Threshold Information
For example:
DECLARE
 warning_operator        BINARY_INTEGER;
 warning_value           VARCHAR2(60);
 critical_operator       BINARY_INTEGER;
 critical_value          VARCHAR2(60);
 observation_period      BINARY_INTEGER;
 consecutive_occurrences BINARY_INTEGER;
BEGIN
 DBMS_SERVER_ALERT.GET_THRESHOLD(
 DBMS_SERVER_ALERT.CPU_TIME_PER_CALL,warning_operator, warning_value,
   critical_operator, critical_value, observation_period,
   consecutive_occurrences, 'inst1',
 DBMS_SERVER_ALERT.OBJECT_TYPE_SERVICE,'main.regress.rdbms.dev.us.oracle.com');
 DBMS_OUTPUT.PUT_LINE('Warningoperator:      ' || warning_operator);
 DBMS_OUTPUT.PUT_LINE('Warningvalue:         ' || warning_value);
 DBMS_OUTPUT.PUT_LINE('Criticaloperator:     ' || critical_operator);
 DBMS_OUTPUT.PUT_LINE('Criticalvalue:        ' ||critical_value);    
 DBMS_OUTPUT.PUT_LINE('Observation_period:    ' || observation_period);
 DBMS_OUTPUT.PUT_LINE('Consecutive occurrences:'|| consecutive_occurrences);
END;
/

我们也可以查找特定的阀值的信息<DBA_THRESHOLDS>

SELECT metrics_name, warning_value, critical_value,consecutive_occurrences
   FROM DBA_THRESHOLDS
   WHERE metrics_name LIKE '%CPUTime%';


Viewing Alert Data
The following dictionary views provide information about serveralerts:
■ DBA_THRESHOLDS lists the threshold settings defined for theinstance.
■ DBA_OUTSTANDING_ALERTS describes theoutstanding  alerts in the database.
■ DBA_ALERT_HISTORY lists a history of alerts that have beencleared.
■ V$ALERT_TYPES  provides information such asgroup and type for each alert.
■ V$METRICNAME contains the names, identifiers, and otherinformation about the system metrics.
■ V$METRIC  and V$METRIC_HISTORY views contain system-lev el metric values in
memory.