Skip to content

Commit

Permalink
增加jmx监控统计
Browse files Browse the repository at this point in the history
  • Loading branch information
夜色 committed Dec 23, 2016
1 parent 4e19454 commit f711b3b
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 7 deletions.
4 changes: 0 additions & 4 deletions mpush-boot/pom.xml
Expand Up @@ -21,10 +21,6 @@
<groupId>${mpush.groupId}</groupId>
<artifactId>mpush-core</artifactId>
</dependency>
<dependency>
<groupId>${mpush.groupId}</groupId>
<artifactId>mpush-monitor</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 4 additions & 0 deletions mpush-core/pom.xml
Expand Up @@ -27,5 +27,9 @@
<groupId>${mpush.groupId}</groupId>
<artifactId>mpush-common</artifactId>
</dependency>
<dependency>
<groupId>${mpush.groupId}</groupId>
<artifactId>mpush-monitor</artifactId>
</dependency>
</dependencies>
</project>
5 changes: 4 additions & 1 deletion mpush-core/src/main/java/com/mpush/core/push/PushCenter.java
Expand Up @@ -22,6 +22,9 @@
import com.mpush.api.service.BaseService;
import com.mpush.api.service.Listener;
import com.mpush.core.ack.AckTaskQueue;
import com.mpush.monitor.jmx.MBeanInfo;
import com.mpush.monitor.jmx.MBeanRegistry;
import com.mpush.monitor.jmx.mxbean.PushCenterBean;
import com.mpush.tools.config.CC;
import com.mpush.tools.thread.pool.ThreadPoolManager;
import org.slf4j.Logger;
Expand All @@ -45,6 +48,7 @@ public final class PushCenter extends BaseService {
private PushTaskExecutor executor;

private PushCenter() {
MBeanRegistry.getInstance().register(new PushCenterBean(taskNum), null);
}

public void addTask(PushTask task) {
Expand All @@ -65,7 +69,6 @@ protected void doStart(Listener listener) throws Throwable {
executor = new CustomJDKExecutor(ThreadPoolManager.I.getPushTaskTimer());
//executor = new NettyEventLoopExecutor();
}

AckTaskQueue.I.start();
logger.info("push center start success");
listener.onSuccess();
Expand Down
Expand Up @@ -10,7 +10,7 @@


public class MBeanRegistry {
public static final String DOMAIN = "com.mpush.MPushService";
public static final String DOMAIN = "com.mpush";
private static final Logger LOG = LoggerFactory.getLogger(MBeanRegistry.class);

private static MBeanRegistry instance = new MBeanRegistry();
Expand Down
@@ -0,0 +1,48 @@
/*
* (C) Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Contributors:
* ohun@live.cn (夜色)
*/

package com.mpush.monitor.jmx.mxbean;

import com.mpush.monitor.jmx.MBeanInfo;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
* Created by ohun on 2016/12/23.
*
* @author ohun@live.cn (夜色)
*/
public final class PushCenterBean implements PushCenterMXBean, MBeanInfo {
private final AtomicLong taskNum;

public PushCenterBean(AtomicLong taskNum) {
this.taskNum = taskNum;
}

@Override
public String getName() {
return "PushCenter";
}

@Override
public long getTaskNum() {
return taskNum.get();
}
}
@@ -0,0 +1,29 @@
/*
* (C) Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Contributors:
* ohun@live.cn (夜色)
*/

package com.mpush.monitor.jmx.mxbean;

/**
* Created by ohun on 2016/12/23.
*
* @author ohun@live.cn (夜色)
*/
public interface PushCenterMXBean {
long getTaskNum();
}
Expand Up @@ -31,7 +31,7 @@ public interface ServerMXBean {
String getClientPort();

/**
* @return the zookeeper server version
* @return the server version
*/
String getVersion();

Expand Down

0 comments on commit f711b3b

Please sign in to comment.