Bagikan melalui


How to: Programmatically Monitor Replication (RMO Programming)

Replication Monitor is a graphical tool that allows you to monitor replication topology. You can access the same monitoring data programmatically by using Replication Management Objects (RMO). RMO classes enable you to program the following tasks:

To monitor a subscription to a merge publication at the Subscriber

  1. Create a connection to the Subscriber by using the ServerConnection class.

  2. Create an instance of the MergeSubscriberMonitor class, and set the Publisher, Publication, PublisherDB, SubscriberDB properties for the subscription, and set the ConnectionContext property to the ServerConnection created in step 1.

  3. Call one of the following methods to return information on Merge Agent sessions for this subscription:

    • GetSessionsSummary() - returns an array of MergeSessionSummary objects with information on up to the last five Merge Agent sessions. Note the SessionID() value for any sessions of interest.

    • GetSessionsSummary(Int32) - returns an array of MergeSessionSummary objects with information on Merge Agent sessions that have occurred during the past number of hours passed in as the hours parameter (up to the last five sessions). Note the SessionID() value for any sessions of interest.

    • GetLastSessionSummary - returns a MergeSessionSummary object with information on the last Merge Agent session. Note the SessionID() value for this session.

    • GetSessionsSummaryDataSet - returns a DataSet object with information on up to the last five Merge Agent sessions, one in each row. Note the value of the Session_id column for any sessions of interest.

    • GetLastSessionSummaryDataRow - returns a DataRow object with information on the last Merge Agent session. Note the value of the Session_id column for this session.

  4. (Optional) Call RefreshSessionSummary(MergeSessionSummary%) to refresh the data for the MergeSessionSummary object passed as mss, or call RefreshSessionSummary(DataRow%) to refresh the data in the DataRow object passed as drRefresh.

  5. Using the session ID obtained in step 3, call one of the following methods to return information on the details of a particular session:

To monitor replication properties for all publications at a Distributor

  1. Create a connection to the Distributor by using the ServerConnection class.

  2. Create an instance of the ReplicationMonitor class.

  3. Set the ConnectionContext property to the ServerConnection created in step 1.

  4. Call the LoadProperties method to get the properties of the object.

  5. Execute one or more of the following methods to return replication information for all Publishers that use this Distributor.

To monitor publication properties for a specific Publisher at the Distributor

  1. Create a connection to the Distributor by using the ServerConnection class.

  2. Get a PublisherMonitor object in one of these ways.

  3. Execute one or more of the following methods to return replication information for all publications that belong to this Publisher.

To monitor properties for a specific publication at the Distributor

  1. Create a connection to the Distributor by using the ServerConnection class.

  2. Get a PublicationMonitor object in one of these ways.

  3. Execute one or more of the following methods to return information about this publication.

To monitor transactional commands that are waiting to be applied at the Subscriber

  1. Create a connection to the Distributor by using the ServerConnection class.

  2. Get a PublicationMonitor object in one of these ways.

  3. Execute the TransPendingCommandInfo method, which returns a PendingCommandInfo object.

  4. Use the properties of this PendingCommandInfo object to determine the estimated number of pending commands and the length of time it will take to complete the delivery of these commands.

To set the monitor warning thresholds for a publication

  1. Create a connection to the Distributor by using the ServerConnection class.

  2. Get a PublicationMonitor object in one of these ways.

  3. Execute the EnumMonitorThresholds method. Note the current threshold settings in the returned ArrayList of MonitorThreshold objects.

  4. Execute the ChangeMonitorThreshold method. Pass the following parameters:

    • metricID - an Int32 value that represents the monitoring threshold metric from the following table:

      Value

      Description

      1

      expiration - monitors for imminent expiration of subscriptions to transactional publications.

      2

      latency - monitors for the performance of subscriptions to transactional publications.

      4

      mergeexpiration - monitors for imminent expiration of subscriptions to merge publications.

      5

      mergeslowrunduration - monitors the duration of merge synchronizations over low-bandwidth (dialup) connections.

      6

      mergefastrunduration - monitors the duration of merge synchronizations over high-bandwidth (LAN) connections.

      7

      mergefastrunspeed - monitors the synchronization rate of merge synchronizations over high-bandwidth (LAN) connections.

      8

      mergeslowrunspeed - monitors the synchronization rate of merge synchronizations over low-bandwidth (dialup) connections.

    • enable - Boolean value that indicates whether the metric is enabled for the publication.

    • thresholdValue - integer value that sets the threshold.

    • shouldAlert - integer that indicates whether this threshold should generate an alert.