Skip to content

Commit

Permalink
Add monitor module javadoc (#3121)
Browse files Browse the repository at this point in the history
  • Loading branch information
lixiaojiee authored and ralf0131 committed Jan 3, 2019
1 parent 6aad8da commit 3bf77ab
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,21 @@
public abstract class AbstractMonitorFactory implements MonitorFactory {
private static final Logger logger = LoggerFactory.getLogger(AbstractMonitorFactory.class);

// lock for getting monitor center
/**
* The lock for getting monitor center
*/
private static final ReentrantLock LOCK = new ReentrantLock();

// monitor centers Map<RegistryAddress, Registry>
/**
* The monitor centers Map<RegistryAddress, Registry>
*/
private static final Map<String, Monitor> MONITORS = new ConcurrentHashMap<String, Monitor>();

private static final Map<String, CompletableFuture<Monitor>> FUTURES = new ConcurrentHashMap<String, CompletableFuture<Monitor>>();

/**
* The monitor create executor
*/
private static final ExecutorService executor = new ThreadPoolExecutor(0, 10, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new NamedThreadFactory("DubboMonitorCreator", true));

public static Collection<Monitor> getMonitors() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,28 @@ public class MonitorFilter implements Filter {

private static final Logger logger = LoggerFactory.getLogger(MonitorFilter.class);

/**
* The Concurrent counter
*/
private final ConcurrentMap<String, AtomicInteger> concurrents = new ConcurrentHashMap<String, AtomicInteger>();

/**
* The MonitorFactory
*/
private MonitorFactory monitorFactory;

public void setMonitorFactory(MonitorFactory monitorFactory) {
this.monitorFactory = monitorFactory;
}

// intercepting invocation
/**
* The invocation interceptor,it will collect the invoke data about this invocation and send it to monitor center
*
* @param invoker service
* @param invocation invocation.
* @return {@link Result} the invoke result
* @throws RpcException
*/
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
if (invoker.getUrl().hasParameter(Constants.MONITOR_KEY)) {
Expand All @@ -76,7 +89,16 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
}
}

// collect info
/**
* The collector logic, it will be handled by the default monitor
*
* @param invoker
* @param invocation
* @param result the invoke result
* @param remoteHost the remote host address
* @param start the timestamp the invoke begin
* @param error if there is an error on the invoke
*/
private void collect(Invoker<?> invoker, Invocation invocation, Result result, String remoteHost, long start, boolean error) {
try {
URL monitorUrl = invoker.getUrl().getUrlParameter(Constants.MONITOR_KEY);
Expand All @@ -91,6 +113,17 @@ private void collect(Invoker<?> invoker, Invocation invocation, Result result, S
}
}

/**
* Create statistics url
*
* @param invoker
* @param invocation
* @param result
* @param remoteHost
* @param start
* @param error
* @return
*/
private URL createStatisticsUrl(Invoker<?> invoker, Invocation invocation, Result result, String remoteHost, long start, boolean error) {
// ---- service statistics ----
long elapsed = System.currentTimeMillis() - start; // invocation cost
Expand All @@ -114,7 +147,6 @@ private URL createStatisticsUrl(Invoker<?> invoker, Invocation invocation, Resul
remoteKey = MonitorService.CONSUMER;
remoteValue = remoteHost;
}

String input = "", output = "";
if (invocation.getAttachment(Constants.INPUT_KEY) != null) {
input = invocation.getAttachment(Constants.INPUT_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,28 @@ public class DubboMonitor implements Monitor {

private static final Logger logger = LoggerFactory.getLogger(DubboMonitor.class);

/**
* The length of the array which is a container of the statistics
*/
private static final int LENGTH = 10;

/**
* The timer sends the statistics data to monitor center
* The timer for sending statistics
*/
private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(3, new NamedThreadFactory("DubboMonitorSendTimer", true));

/**
* The future that can cancel the <b>scheduledExecutorService</b>
*/
private final ScheduledFuture<?> sendFuture;

private final Invoker<MonitorService> monitorInvoker;

private final MonitorService monitorService;

/**
* The time interval for timer <b>scheduledExecutorService</b> to send data
*/
private final long monitorInterval;

private final ConcurrentMap<Statistics, AtomicReference<long[]>> statisticsMap = new ConcurrentHashMap<Statistics, AtomicReference<long[]>>();
Expand Down

0 comments on commit 3bf77ab

Please sign in to comment.