CloudWatch 使用 SDK 的 範例 SAP ABAP - AWS SDK 程式碼範例

文件範例儲存庫中有更多 AWS SDK可用的範例。 AWS SDK GitHub

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

CloudWatch 使用 SDK 的 範例 SAP ABAP

下列程式碼範例示範如何使用 AWS SDK的 SAP ABAP 搭配 來執行動作和實作常見案例 CloudWatch。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會示範如何呼叫個別服務函數,但您可以在其相關案例中查看內容中的動作。

案例是程式碼範例,示範如何透過呼叫服務內的多個函數或與其他 結合,來完成特定任務 AWS 服務。

每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。

動作

下列程式碼範例示範如何使用 DeleteAlarms

SDK 適用於 SAP ABAP
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

TRY. lo_cwt->deletealarms( it_alarmnames = it_alarm_names ). MESSAGE 'Alarms deleted.' TYPE 'I'. CATCH /aws1/cx_cwtresourcenotfound . MESSAGE 'Resource being accessed is not found.' TYPE 'E'. ENDTRY.
  • 如需API詳細資訊,請參閱DeleteAlarms中的 AWS SDK 以取得SAPABAPAPI參考

下列程式碼範例示範如何使用 DescribeAlarms

SDK 適用於 SAP ABAP
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

TRY. oo_result = lo_cwt->describealarms( " oo_result is returned for testing purposes. " it_alarmnames = it_alarm_names ). MESSAGE 'Alarms retrieved.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.
  • 如需API詳細資訊,請參閱DescribeAlarms中的 AWS SDK 以取得SAPABAPAPI參考

下列程式碼範例示範如何使用 DisableAlarmActions

SDK 適用於 SAP ABAP
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

"Disables actions on the specified alarm. " TRY. lo_cwt->disablealarmactions( it_alarmnames = it_alarm_names ). MESSAGE 'Alarm actions disabled.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.
  • 如需API詳細資訊,請參閱DisableAlarmActions中的 AWS SDK 以取得SAPABAPAPI參考

下列程式碼範例示範如何使用 EnableAlarmActions

SDK 適用於 SAP ABAP
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

"Enable actions on the specified alarm." TRY. lo_cwt->enablealarmactions( it_alarmnames = it_alarm_names ). MESSAGE 'Alarm actions enabled.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.
  • 如需API詳細資訊,請參閱EnableAlarmActions中的 AWS SDK 以取得SAPABAPAPI參考

下列程式碼範例示範如何使用 ListMetrics

SDK 適用於 SAP ABAP
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

"The following list-metrics example displays the metrics for Amazon CloudWatch." TRY. oo_result = lo_cwt->listmetrics( " oo_result is returned for testing purposes. " iv_namespace = iv_namespace ). DATA(lt_metrics) = oo_result->get_metrics( ). MESSAGE 'Metrics retrieved.' TYPE 'I'. CATCH /aws1/cx_cwtinvparamvalueex . MESSAGE 'The specified argument was not valid.' TYPE 'E'. ENDTRY.
  • 如需API詳細資訊,請參閱ListMetrics中的 AWS SDK 以取得SAPABAPAPI參考

下列程式碼範例示範如何使用 PutMetricAlarm

SDK 適用於 SAP ABAP
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

TRY. lo_cwt->putmetricalarm( iv_alarmname = iv_alarm_name iv_comparisonoperator = iv_comparison_operator iv_evaluationperiods = iv_evaluation_periods iv_metricname = iv_metric_name iv_namespace = iv_namespace iv_statistic = iv_statistic iv_threshold = iv_threshold iv_actionsenabled = iv_actions_enabled iv_alarmdescription = iv_alarm_description iv_unit = iv_unit iv_period = iv_period it_dimensions = it_dimensions ). MESSAGE 'Alarm created.' TYPE 'I'. CATCH /aws1/cx_cwtlimitexceededfault. MESSAGE 'The request processing has exceeded the limit' TYPE 'E'. ENDTRY.
  • 如需API詳細資訊,請參閱PutMetricAlarm中的 AWS SDK 以取得SAPABAPAPI參考

案例

以下程式碼範例顯示做法:

  • 建立警示。

  • 停用警示動作。

  • 描述警示。

  • 刪除警示。

SDK 適用於 SAP ABAP
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

DATA lt_alarmnames TYPE /aws1/cl_cwtalarmnames_w=>tt_alarmnames. DATA lo_alarmname TYPE REF TO /aws1/cl_cwtalarmnames_w. "Create an alarm" TRY. lo_cwt->putmetricalarm( iv_alarmname = iv_alarm_name iv_comparisonoperator = iv_comparison_operator iv_evaluationperiods = iv_evaluation_periods iv_metricname = iv_metric_name iv_namespace = iv_namespace iv_statistic = iv_statistic iv_threshold = iv_threshold iv_actionsenabled = iv_actions_enabled iv_alarmdescription = iv_alarm_description iv_unit = iv_unit iv_period = iv_period it_dimensions = it_dimensions ). MESSAGE 'Alarm created' TYPE 'I'. CATCH /aws1/cx_cwtlimitexceededfault. MESSAGE 'The request processing has exceeded the limit' TYPE 'E'. ENDTRY. "Create an ABAP internal table for the created alarm." CREATE OBJECT lo_alarmname EXPORTING iv_value = iv_alarm_name. INSERT lo_alarmname INTO TABLE lt_alarmnames. "Disable alarm actions." TRY. lo_cwt->disablealarmactions( it_alarmnames = lt_alarmnames ). MESSAGE 'Alarm actions disabled' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_disablealarm_exception). DATA(lv_disablealarm_error) = |"{ lo_disablealarm_exception->av_err_code }" - { lo_disablealarm_exception->av_err_msg }|. MESSAGE lv_disablealarm_error TYPE 'E'. ENDTRY. "Describe alarm using the same ABAP internal table." TRY. oo_result = lo_cwt->describealarms( " oo_result is returned for testing purpose " it_alarmnames = lt_alarmnames ). MESSAGE 'Alarms retrieved' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_describealarms_exception). DATA(lv_describealarms_error) = |"{ lo_describealarms_exception->av_err_code }" - { lo_describealarms_exception->av_err_msg }|. MESSAGE lv_describealarms_error TYPE 'E'. ENDTRY. "Delete alarm." TRY. lo_cwt->deletealarms( it_alarmnames = lt_alarmnames ). MESSAGE 'Alarms deleted' TYPE 'I'. CATCH /aws1/cx_cwtresourcenotfound . MESSAGE 'Resource being access is not found.' TYPE 'E'. ENDTRY.