001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2006-2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.replication.plugin; 028 029 import java.util.ArrayList; 030 import java.util.LinkedHashSet; 031 032 import org.opends.server.admin.std.server.MonitorProviderCfg; 033 import org.opends.server.api.MonitorProvider; 034 import org.opends.server.core.DirectoryServer; 035 import org.opends.server.types.Attribute; 036 import org.opends.server.types.AttributeType; 037 import org.opends.server.types.AttributeValue; 038 039 /** 040 * Class used to generate monitoring information for the replication. 041 */ 042 public class ReplicationMonitor extends MonitorProvider<MonitorProviderCfg> 043 { 044 private ReplicationDomain domain; // the replication plugin 045 046 /** 047 * Create a new replication monitor. 048 * @param domain the plugin which created the monitor 049 */ 050 public ReplicationMonitor(ReplicationDomain domain) 051 { 052 super("Replication monitor " + domain.getBaseDN().toString()); 053 this.domain = domain; 054 } 055 056 /** 057 * {@inheritDoc} 058 */ 059 @Override() 060 public void initializeMonitorProvider(MonitorProviderCfg configuration) 061 { 062 // no implementation needed. 063 } 064 065 /** 066 * Retrieves the name of this monitor provider. It should be unique among all 067 * monitor providers, including all instances of the same monitor provider. 068 * 069 * @return The name of this monitor provider. 070 */ 071 @Override 072 public String getMonitorInstanceName() 073 { 074 return "Replication plugin " + domain.getBaseDN().toString(); 075 } 076 077 /** 078 * Retrieves a set of attributes containing monitor data that should be 079 * returned to the client if the corresponding monitor entry is requested. 080 * 081 * @return A set of attributes containing monitor data that should be 082 * returned to the client if the corresponding monitor entry is 083 * requested. 084 */ 085 @Override 086 public ArrayList<Attribute> getMonitorData() 087 { 088 ArrayList<Attribute> attributes = new ArrayList<Attribute>(); 089 090 /* get the base dn */ 091 Attribute attr = new Attribute("base-dn", domain.getBaseDN().toString()); 092 attributes.add(attr); 093 094 /* get the base dn */ 095 attr = new Attribute("connected-to", domain.getReplicationServer()); 096 attributes.add(attr); 097 098 /* get number of lost connections */ 099 addMonitorData(attributes, "lost-connections", 100 domain.getNumLostConnections()); 101 102 /* get number of received updates */ 103 addMonitorData(attributes, "received-updates", domain.getNumRcvdUpdates()); 104 105 /* get number of updates sent */ 106 addMonitorData(attributes, "sent-updates", domain.getNumSentUpdates()); 107 108 /* get number of changes in the pending list */ 109 addMonitorData(attributes, "pending-updates", 110 domain.getPendingUpdatesCount()); 111 112 /* get number of changes replayed */ 113 addMonitorData(attributes, "replayed-updates", 114 domain.getNumProcessedUpdates()); 115 116 /* get number of changes successfully */ 117 addMonitorData(attributes, "replayed-updates-ok", 118 domain.getNumReplayedPostOpCalled()); 119 120 /* get number of modify conflicts */ 121 addMonitorData(attributes, "resolved-modify-conflicts", 122 domain.getNumResolvedModifyConflicts()); 123 124 /* get number of naming conflicts */ 125 addMonitorData(attributes, "resolved-naming-conflicts", 126 domain.getNumResolvedNamingConflicts()); 127 128 /* get number of unresolved naming conflicts */ 129 addMonitorData(attributes, "unresolved-naming-conflicts", 130 domain.getNumUnresolvedNamingConflicts()); 131 132 /* get server-id */ 133 addMonitorData(attributes, "server-id", 134 domain.getServerId()); 135 136 /* get window information */ 137 addMonitorData(attributes, "max-rcv-window", domain.getMaxRcvWindow()); 138 addMonitorData(attributes, "current-rcv-window", 139 domain.getCurrentRcvWindow()); 140 addMonitorData(attributes, "max-send-window", 141 domain.getMaxSendWindow()); 142 addMonitorData(attributes, "current-send-window", 143 domain.getCurrentSendWindow()); 144 145 /* get the Server State */ 146 final String ATTR_SERVER_STATE = "server-state"; 147 AttributeType type = 148 DirectoryServer.getDefaultAttributeType(ATTR_SERVER_STATE); 149 LinkedHashSet<AttributeValue> values = new LinkedHashSet<AttributeValue>(); 150 for (String str : domain.getServerState().toStringSet()) 151 { 152 values.add(new AttributeValue(type,str)); 153 } 154 attr = new Attribute(type, ATTR_SERVER_STATE, values); 155 attributes.add(attr); 156 157 attributes.add(new Attribute("ssl-encryption", 158 String.valueOf(domain.isSessionEncrypted()))); 159 160 attributes.add(new Attribute("generation-id", 161 String.valueOf(domain.getGenerationId()))); 162 163 return attributes; 164 165 } 166 167 /** 168 * Add an attribute with an integer value to the list of monitoring 169 * attributes. 170 * 171 * @param attributes the list of monitoring attributes 172 * @param name the name of the attribute to add. 173 * @param value The integer value of he attribute to add. 174 */ 175 private void addMonitorData(ArrayList<Attribute> attributes, 176 String name, int value) 177 { 178 Attribute attr; 179 AttributeType type; 180 LinkedHashSet<AttributeValue> values; 181 type = DirectoryServer.getDefaultAttributeType(name); 182 values = new LinkedHashSet<AttributeValue>(); 183 values.add(new AttributeValue(type, String.valueOf(value))); 184 attr = new Attribute(type, name, values); 185 attributes.add(attr); 186 } 187 188 /** 189 * Retrieves the length of time in milliseconds that should elapse between 190 * calls to the <CODE>updateMonitorData()</CODE> method. A negative or zero 191 * return value indicates that the <CODE>updateMonitorData()</CODE> method 192 * should not be periodically invoked. 193 * 194 * @return The length of time in milliseconds that should elapse between 195 * calls to the <CODE>updateMonitorData()</CODE> method. 196 */ 197 @Override 198 public long getUpdateInterval() 199 { 200 /* we don't wont to do polling on this monitor */ 201 return 0; 202 } 203 204 /** 205 * Performs any processing periodic processing that may be desired to update 206 * the information associated with this monitor. Note that best-effort 207 * attempts will be made to ensure that calls to this method come 208 * <CODE>getUpdateInterval()</CODE> milliseconds apart, but no guarantees will 209 * be made. 210 */ 211 @Override 212 public void updateMonitorData() 213 { 214 // As long as getUpdateInterval() returns 0, this will never get called 215 } 216 }