001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2006-2010 Sun Microsystems, Inc. 015 * Portions copyright 2013-2016 ForgeRock AS. 016 */ 017package org.opends.server.replication.service; 018 019import java.util.ArrayList; 020import java.util.Collection; 021import java.util.Map; 022import java.util.Map.Entry; 023 024import org.opends.server.api.MonitorData; 025import org.forgerock.opendj.server.config.server.MonitorProviderCfg; 026import org.opends.server.api.MonitorProvider; 027import org.opends.server.replication.service.ReplicationDomain.ImportExportContext; 028 029/** 030 * Class used to generate monitoring information for the replication. 031 */ 032public class ReplicationMonitor extends MonitorProvider<MonitorProviderCfg> 033{ 034 private final ReplicationDomain domain; 035 036 /** 037 * Create a new replication monitor. 038 * @param domain the plugin which created the monitor 039 */ 040 ReplicationMonitor(ReplicationDomain domain) 041 { 042 this.domain = domain; 043 } 044 045 /** {@inheritDoc} */ 046 @Override 047 public void initializeMonitorProvider(MonitorProviderCfg configuration) 048 { 049 // no implementation needed. 050 } 051 052 /** 053 * Retrieves the name of this monitor provider. It should be unique among all 054 * monitor providers, including all instances of the same monitor provider. 055 * 056 * @return The name of this monitor provider. 057 */ 058 @Override 059 public String getMonitorInstanceName() 060 { 061 return "Directory server DS(" + domain.getServerId() + ") " 062 + domain.getLocalUrl() 063 + ",cn=" + domain.getBaseDN().toString().replace(',', '_').replace('=', '_') 064 + ",cn=Replication"; 065 } 066 067 @Override 068 public MonitorData getMonitorData() 069 { 070 final MonitorData attributes = new MonitorData(41); 071 072 attributes.add("domain-name", domain.getBaseDN()); 073 attributes.add("server-id", domain.getServerId()); 074 attributes.add("connected-to", domain.getReplicationServer()); 075 attributes.add("lost-connections", domain.getNumLostConnections()); 076 077 attributes.add("received-updates", domain.getNumRcvdUpdates()); 078 attributes.add("sent-updates", domain.getNumSentUpdates()); 079 attributes.add("replayed-updates", domain.getNumProcessedUpdates()); 080 081 // get window information 082 attributes.add("max-rcv-window", domain.getMaxRcvWindow()); 083 attributes.add("current-rcv-window", domain.getCurrentRcvWindow()); 084 attributes.add("max-send-window", domain.getMaxSendWindow()); 085 attributes.add("current-send-window", domain.getCurrentSendWindow()); 086 087 attributes.add("server-state", domain.getServerState().toStringSet()); 088 attributes.add("ssl-encryption", domain.isSessionEncrypted()); 089 attributes.add("generation-id", domain.getGenerationID()); 090 091 // Add import/export monitoring attributes 092 final ImportExportContext ieContext = domain.getImportExportContext(); 093 if (ieContext != null) 094 { 095 attributes.add("total-update", ieContext.importInProgress() ? "import" : "export"); 096 attributes.add("total-update-entry-count", ieContext.getTotalEntryCount()); 097 attributes.add("total-update-entry-left", ieContext.getLeftEntryCount()); 098 } 099 100 101 // Add the concrete Domain attributes 102 domain.addAdditionalMonitoring(attributes); 103 104 /* 105 * Add assured replication related monitoring fields 106 * (see domain.getXXX() method comment for field meaning) 107 */ 108 attributes.add("assured-sr-sent-updates", domain.getAssuredSrSentUpdates()); 109 attributes.add("assured-sr-acknowledged-updates", domain.getAssuredSrAcknowledgedUpdates()); 110 attributes.add("assured-sr-not-acknowledged-updates", domain.getAssuredSrNotAcknowledgedUpdates()); 111 attributes.add("assured-sr-timeout-updates", domain.getAssuredSrTimeoutUpdates()); 112 attributes.add("assured-sr-wrong-status-updates", domain.getAssuredSrWrongStatusUpdates()); 113 attributes.add("assured-sr-replay-error-updates", domain.getAssuredSrReplayErrorUpdates()); 114 addMonitorData(attributes, 115 "assured-sr-server-not-acknowledged-updates", 116 domain.getAssuredSrServerNotAcknowledgedUpdates()); 117 attributes.add("assured-sr-received-updates", domain.getAssuredSrReceivedUpdates()); 118 attributes.add("assured-sr-received-updates-acked", domain.getAssuredSrReceivedUpdatesAcked()); 119 attributes.add("assured-sr-received-updates-not-acked", domain.getAssuredSrReceivedUpdatesNotAcked()); 120 attributes.add("assured-sd-sent-updates", domain.getAssuredSdSentUpdates()); 121 attributes.add("assured-sd-acknowledged-updates", domain.getAssuredSdAcknowledgedUpdates()); 122 attributes.add("assured-sd-timeout-updates", domain.getAssuredSdTimeoutUpdates()); 123 addMonitorData(attributes, "assured-sd-server-timeout-updates", domain.getAssuredSdServerTimeoutUpdates()); 124 125 // Status related monitoring fields 126 attributes.add("last-status-change-date", domain.getLastStatusChangeDate()); 127 attributes.add("status", domain.getStatus()); 128 129 return attributes; 130 } 131 132 private void addMonitorData(MonitorData attributes, String attrName, Map<Integer, Integer> serverIdToNb) 133 { 134 if (!serverIdToNb.isEmpty()) 135 { 136 Collection<String> values = new ArrayList<>(); 137 for (Entry<Integer, Integer> entry : serverIdToNb.entrySet()) 138 { 139 final Integer serverId = entry.getKey(); 140 final Integer nb = entry.getValue(); 141 values.add(serverId + ":" + nb); 142 } 143 attributes.add(attrName, values); 144 } 145 } 146}