(实战)EMPluginForMySQL监控搜狐DBA王丹敬主题大纲•为什么选择开发EMPlugin?•EMPlugin能做些什么?•EMPlugin的开发流程及代码示例•EMPlugin的优点&缺点为什么选择开发EMPlugin?EMPlugin能做些什么?基于EM框架的功能-InformationPublisher’sReports基于EM框架的功能–ConfigurationManagement基于EM框架的功能–ConfigurationManagement基于EM框架的功能–Metric的使用(History)基于EM框架的功能–Metric的使用(Compare)基于EM框架的功能–Metric的使用基于EM框架的功能–邮件报警EMPlugin能做些什么?•Metric•Policy•Report&Chart•Link•……EMPlugin的开发流程定义TargetType&Metric&Properties•根据Oracle提供的DTD编写XML文件–《OracleEnterpriseManagerExtensibilityGuide》–$AGENT_HOME/sysman/admin/dtds/TargetMetadata.dtd–$AGENT_HOME/sysman/admin/dtds/TargetCollection.dtd–$AGENT_HOME/sysman/admin/metadata/*.xml–$AGENT_HOME/sysman/admin/default_collection/*.xml•metadata.xml–定义收集哪些metric,–定义metric的收集方法–定义metric是否在UI显示–……•collection.xml–定义metric的收集频率–报警阀值–……?xmlversion=1.0encoding=UTF-8?!DOCTYPETargetMetadataSYSTEM../dtds/TargetMetadata.dtdTargetMetadataMETA_VER=1.0TYPE=mysql_database_pluginDisplayLabelNLSID=mmd_nameMySQLDB/Label/DisplayMetric…/MetricMetric…/MetricMetric…/MetricMetric…/MetricMetric…/Metric......InstancePropertiesInstanceProperty…/InstanceProperty……DynamicProperties…/DynamicProperties……/InstancePropertiesmetadata.xml架构MetricNAME=ResponseIS_TEST_METRIC=FALSETYPE=TABLEDisplayLabelNLSID=mmd_ResponseResponse/Label/DisplayTableDescriptorColumnDescriptorNAME=StatusTYPE=STRINGIS_KEY=FALSEDisplayFOR_SUMMARY_UI=TRUELabelNLSID=mmd_Response_StatusStatus/LabelDescriptionNLSID=mmd_Response_Status_descCurrentStatusoftheServer/Description/Display/ColumnDescriptorColumnDescriptorNAME=TimingTYPE=NUMBERIS_KEY=FALSEDisplayFOR_SUMMARY_UI=TRUELabelNLSID=mmd_Response_TimingResponsetime(ms)/Label/Display/ColumnDescriptor/TableDescriptorQueryDescriptorFETCHLET_ID=OSLineTokenPropertyNAME=emdRootSCOPE=SYSTEMGLOBALemdRoot/PropertyPropertyNAME=scriptsDirSCOPE=SYSTEMGLOBALscriptsDir/PropertyPropertyNAME=perlBinSCOPE=SYSTEMGLOBALperlBin/PropertyPropertyNAME=hostSCOPE=INSTANCEOPTIONAL=TRUEhost/PropertyPropertyNAME=portSCOPE=INSTANCEOPTIONAL=TRUEport/PropertyPropertyNAME=unameSCOPE=INSTANCEOPTIONAL=TRUEuname/PropertyPropertyNAME=passSCOPE=INSTANCEOPTIONAL=TRUEpass/PropertyPropertyNAME=mysqlhomeSCOPE=INSTANCEmysqlhome/PropertyPropertyNAME=mydelimiterSCOPE=INSTANCEmydelimiter/PropertyPropertyNAME=commandSCOPE=GLOBAL%perlBin%/perl%scriptsDir%/emx/%TYPE%/response.pl%mysqlhome%%mydelimiter%%host%%port%%uname%%pass%/PropertyPropertyNAME=delimiterSCOPE=GLOBAL%mydelimiter%/PropertyPropertyNAME=startsWithSCOPE=GLOBALem_result=/PropertyPropertyNAME=errStartsWithSCOPE=GLOBALem_error=/PropertyPropertyNAME=em_metric_timeoutSCOPE=GLOBAL120/Property/QueryDescriptor/Metricmetadata.xml架构–定义Metric示例InstancePropertiesInstancePropertyNAME=showstatusOPTIONAL=FALSEDisplayLabelNLSID=mmd_iprop_showstatusShowStatus/Label/Display![CDATA[show/*!50002GLOBAL*/status;]]/InstanceProperty………………………………………………………………………………DynamicPropertiesNAME=Check_VersionPROP_LIST=versionFORMAT=ROWExecutionDescriptorGetTableNAME=For_Check_Version/GetViewNAME=v_Check_VersionFROM_TABLE=For_Check_VersionColumnNAME=v4//GetView/ExecutionDescriptor/DynamicProperties…………/InstancePropertiesmetadata.xml架构–定义InstanceProperties示例?xmlversion=1.0encoding=UTF-8?!DOCTYPETargetCollectionSYSTEM../dtds/TargetCollection.dtd?xml-stylesheettype=text/xslhref=mysql_database_plugin.xsl?TargetCollectionTYPE=mysql_database_pluginCollectionItemNAME=ResponseUPLOAD_ON_FETCH=TRUEScheduleIntervalScheduleINTERVAL=2TIME_UNIT=Min//ScheduleConditionCOLUMN_NAME=StatusCRITICAL=UpOPERATOR=NEMESSAGE=%target%isdown.CLEAR_MESSAGE=%target%isalive./………………/TargetCollectioncollection.xml架构收集Metric的方法•Fetchlets–OSCommand--推荐使用Perl–SQL–SNMP–URLTiming–DynamicMonitoringService(DMS)–HTTPData–URLXML–WBEM–JDBC–OJMX/SOAP•Receivelets–SNMPReceivelets–AdvancedQueueReceivelets–HTTPReceiveletsChart展示Report展示Report展示HomepageChartsTARGET_TYPE=mysql_database_pluginChartSetTopPaneChartTYPE=timeSeriesChartChartPropertyNAME=metricResponse/ChartPropertyChartPropertyNAME=columnTiming/ChartPropertyChartPropertyNAME=width375/ChartPropertyChartPropertyNAME=height150/ChartPropertyChartPropertyNAME=legendPositionsouth/ChartPropertyChartPropertyNAME=titleVisibletrue/ChartPropertyChartPropertyNAME=titleResponseTime(ms)/ChartPropertyChartPropertyNAME=subtitle/ChartPropertyChartPropertyNAME=destinationreportTab/ChartPropertyChartPropertyNAME=reportTitleMySQLHealthStatusReports/ChartProperty/Chart/TopPaneMiddlePane....../MiddlePane/ChartSet/HomepageCharts定义ChartBEGINDECLARE--作为create_report_definition的p_late_binding_target_types参数值l_target_typesMGMT_IP_TARGET_TYPES;--定义报表的guidl_report_guidRAW(16);--定义元素的guidl_element_guidRAW(16);--create_report_definition和add_element_to_report_def的p_parameters参数值l_param_valuesMGMT_IP_PARAM_VALUE_LIST;--序列变量l_curr_order应该连续增长,从1到报表中的元素总数……BEGIN--INITIALIZE