mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Maxim Thomas
03.30.2025 61dac86bceb9d727e1bd707982c41ab9467c6d5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2006-2010 Sun Microsystems, Inc.
 * Portions copyright 2013-2016 ForgeRock AS.
 */
package org.opends.server.replication.service;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
 
import org.opends.server.api.MonitorData;
import org.forgerock.opendj.server.config.server.MonitorProviderCfg;
import org.opends.server.api.MonitorProvider;
import org.opends.server.replication.service.ReplicationDomain.ImportExportContext;
 
/**
 * Class used to generate monitoring information for the replication.
 */
public class ReplicationMonitor extends MonitorProvider<MonitorProviderCfg>
{
  private final ReplicationDomain domain;
 
  /**
   * Create a new replication monitor.
   * @param domain the plugin which created the monitor
   */
  ReplicationMonitor(ReplicationDomain domain)
  {
    this.domain = domain;
  }
 
  /** {@inheritDoc} */
  @Override
  public void initializeMonitorProvider(MonitorProviderCfg configuration)
  {
    // no implementation needed.
  }
 
  /**
   * Retrieves the name of this monitor provider.  It should be unique among all
   * monitor providers, including all instances of the same monitor provider.
   *
   * @return  The name of this monitor provider.
   */
  @Override
  public String getMonitorInstanceName()
  {
    return "Directory server DS(" + domain.getServerId() + ") "
        + domain.getLocalUrl()
        + ",cn=" + domain.getBaseDN().toString().replace(',', '_').replace('=', '_')
        + ",cn=Replication";
  }
 
  @Override
  public MonitorData getMonitorData()
  {
    final MonitorData attributes = new MonitorData(41);
 
    attributes.add("domain-name", domain.getBaseDN());
    attributes.add("server-id", domain.getServerId());
    attributes.add("connected-to", domain.getReplicationServer());
    attributes.add("lost-connections", domain.getNumLostConnections());
 
    attributes.add("received-updates", domain.getNumRcvdUpdates());
    attributes.add("sent-updates", domain.getNumSentUpdates());
    attributes.add("replayed-updates", domain.getNumProcessedUpdates());
 
    // get window information
    attributes.add("max-rcv-window", domain.getMaxRcvWindow());
    attributes.add("current-rcv-window", domain.getCurrentRcvWindow());
    attributes.add("max-send-window", domain.getMaxSendWindow());
    attributes.add("current-send-window", domain.getCurrentSendWindow());
 
    attributes.add("server-state", domain.getServerState().toStringSet());
    attributes.add("ssl-encryption", domain.isSessionEncrypted());
    attributes.add("generation-id", domain.getGenerationID());
 
    // Add import/export monitoring attributes
    final ImportExportContext ieContext = domain.getImportExportContext();
    if (ieContext != null)
    {
      attributes.add("total-update", ieContext.importInProgress() ? "import" : "export");
      attributes.add("total-update-entry-count", ieContext.getTotalEntryCount());
      attributes.add("total-update-entry-left", ieContext.getLeftEntryCount());
    }
 
 
    // Add the concrete Domain attributes
    domain.addAdditionalMonitoring(attributes);
 
    /*
     * Add assured replication related monitoring fields
     * (see domain.getXXX() method comment for field meaning)
     */
    attributes.add("assured-sr-sent-updates", domain.getAssuredSrSentUpdates());
    attributes.add("assured-sr-acknowledged-updates", domain.getAssuredSrAcknowledgedUpdates());
    attributes.add("assured-sr-not-acknowledged-updates", domain.getAssuredSrNotAcknowledgedUpdates());
    attributes.add("assured-sr-timeout-updates", domain.getAssuredSrTimeoutUpdates());
    attributes.add("assured-sr-wrong-status-updates", domain.getAssuredSrWrongStatusUpdates());
    attributes.add("assured-sr-replay-error-updates", domain.getAssuredSrReplayErrorUpdates());
    addMonitorData(attributes,
        "assured-sr-server-not-acknowledged-updates",
        domain.getAssuredSrServerNotAcknowledgedUpdates());
    attributes.add("assured-sr-received-updates", domain.getAssuredSrReceivedUpdates());
    attributes.add("assured-sr-received-updates-acked", domain.getAssuredSrReceivedUpdatesAcked());
    attributes.add("assured-sr-received-updates-not-acked", domain.getAssuredSrReceivedUpdatesNotAcked());
    attributes.add("assured-sd-sent-updates", domain.getAssuredSdSentUpdates());
    attributes.add("assured-sd-acknowledged-updates", domain.getAssuredSdAcknowledgedUpdates());
    attributes.add("assured-sd-timeout-updates", domain.getAssuredSdTimeoutUpdates());
    addMonitorData(attributes, "assured-sd-server-timeout-updates", domain.getAssuredSdServerTimeoutUpdates());
 
    // Status related monitoring fields
    attributes.add("last-status-change-date", domain.getLastStatusChangeDate());
    attributes.add("status", domain.getStatus());
 
    return attributes;
  }
 
  private void addMonitorData(MonitorData attributes, String attrName, Map<Integer, Integer> serverIdToNb)
  {
    if (!serverIdToNb.isEmpty())
    {
      Collection<String> values = new ArrayList<>();
      for (Entry<Integer, Integer> entry : serverIdToNb.entrySet())
      {
        final Integer serverId = entry.getKey();
        final Integer nb = entry.getValue();
        values.add(serverId + ":" + nb);
      }
      attributes.add(attrName, values);
    }
  }
}