Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance monitor module javadoc #3121

Merged
merged 1 commit into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
*/
ralf0131 marked this conversation as resolved.
Show resolved Hide resolved
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
ralf0131 marked this conversation as resolved.
Show resolved Hide resolved
*
* @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