metricDTOList) {
62 | if (ListUtil.isEmpty(metricDTOList)) {
63 | return;
64 | }
65 | String url = ConfigurationFactory.getInstance().getString(MonitorConst.CONFIG_KEY_URI, MonitorConst.DEFAULT_COLLECTOR_URI);
66 | BaseResult ret = HttpClientUtil.postJSONSafe(url, JSONUtil.toStr(metricDTOList));
67 | log.info("post to sea monitor server [count={},success={}]", metricDTOList.size(), ret.getSuccess());
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/message/simple/SimpleMessageProducer.java:
--------------------------------------------------------------------------------
1 | package com.github.seaframework.monitor.message.simple;
2 |
3 | import com.github.seaframework.monitor.dto.MetricDTO;
4 | import com.github.seaframework.monitor.message.MessageProducer;
5 | import com.google.common.collect.Queues;
6 | import lombok.extern.slf4j.Slf4j;
7 |
8 | import java.util.concurrent.BlockingQueue;
9 |
10 | /**
11 | * module name
12 | *
13 | * @author spy
14 | * @version 1.0 2020/3/27
15 | * @since 1.0
16 | */
17 | @Slf4j
18 | public class SimpleMessageProducer implements MessageProducer {
19 |
20 | private BlockingQueue queue;
21 | private int DEFAULT_QUEUE_SIZE = 5000;
22 |
23 | @Override
24 | public void init() {
25 |
26 | queue = Queues.newArrayBlockingQueue(DEFAULT_QUEUE_SIZE);
27 |
28 | Thread consumeThread = new Thread(new SimpleConsumerTask(queue));
29 | consumeThread.setName("sea-monitor-simple-message-consumer");
30 | consumeThread.start();
31 |
32 | }
33 |
34 | @Override
35 | public void push(MetricDTO dto) {
36 | try {
37 | if (queue.size() >= DEFAULT_QUEUE_SIZE) {
38 | log.warn("queue has reach to MAX SIZE[{}]", DEFAULT_QUEUE_SIZE);
39 | return;
40 | }
41 | queue.offer(dto);
42 | } catch (Exception e) {
43 | log.error("fail to push metric dto", e);
44 | }
45 | }
46 |
47 | @Override
48 | public void shutdown() {
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/mybatis/MybatisMonitorInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.github.seaframework.monitor.mybatis;
2 |
3 | import com.github.seaframework.monitor.SeaMonitor;
4 | import com.github.seaframework.monitor.common.MonitorConst;
5 | import com.github.seaframework.monitor.dto.MetricDTO;
6 | import com.github.seaframework.monitor.enums.CounterEnum;
7 | import com.github.seaframework.monitor.heartbeat.data.DataStats;
8 | import lombok.extern.slf4j.Slf4j;
9 | import org.apache.ibatis.cache.CacheKey;
10 | import org.apache.ibatis.executor.Executor;
11 | import org.apache.ibatis.mapping.BoundSql;
12 | import org.apache.ibatis.mapping.MappedStatement;
13 | import org.apache.ibatis.plugin.*;
14 | import org.apache.ibatis.session.ResultHandler;
15 | import org.apache.ibatis.session.RowBounds;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 | import java.util.Properties;
20 |
21 | /**
22 | * module name
23 | *
24 | * @author spy
25 | * @version 1.0 2020/4/27
26 | * @since 1.0
27 | */
28 | @Slf4j
29 | @Intercepts({
30 | @Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}),
31 | @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
32 | @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class})
33 | })
34 | public class MybatisMonitorInterceptor implements Interceptor {
35 |
36 | private static final int MAX_RECORD_SIZE = 5000;
37 | //10s
38 | private static final int MIN_COST_TIME = 1000 * 5;
39 |
40 | @Override
41 | public Object intercept(Invocation invocation) throws Throwable {
42 | if (log.isDebugEnabled()) {
43 | log.debug("mybatis monitor interceptor begin.");
44 | }
45 | long start = System.currentTimeMillis();
46 | Object returnValue;
47 | try {
48 | returnValue = invocation.proceed();
49 | dealReturnValue(returnValue);
50 | } catch (Exception e) {
51 | if (SeaMonitor.isEnabled()) {
52 | log.error("DB500");
53 | MetricDTO metricDTO = new MetricDTO();
54 | metricDTO.setMetric(MonitorConst.METRIC_DB_SQL_ERROR);
55 | metricDTO.setValue(1);
56 | metricDTO.setErrorFlag(true);
57 | metricDTO.setTraceIdFlag(true);
58 | SeaMonitor.logMetric(metricDTO);
59 |
60 | // for sql total
61 | DataStats dataStats = DataStats.currentStatsHolder();
62 | dataStats.logCount(CounterEnum.DB_SQL_ERROR_COUNT);
63 | }
64 | throw e;
65 | } finally {
66 | postCheck(start);
67 | }
68 |
69 | if (log.isDebugEnabled()) {
70 | log.debug("mybatis monitor interceptor end.");
71 | }
72 |
73 | return returnValue;
74 | }
75 |
76 | private void postCheck(long start) {
77 | if (!SeaMonitor.isEnabled()) {
78 | return;
79 | }
80 | long cost = System.currentTimeMillis() - start;
81 | if (cost > MIN_COST_TIME) {
82 | log.warn("DB502");
83 | MetricDTO metricDTO = new MetricDTO();
84 | metricDTO.setMetric(MonitorConst.METRIC_DB_SQL_COST);
85 | metricDTO.setValue(cost);
86 | metricDTO.setErrorFlag(true);
87 | metricDTO.setTraceIdFlag(true);
88 | SeaMonitor.logMetric(metricDTO);
89 | }
90 | }
91 |
92 | private void dealReturnValue(Object returnValue) {
93 | if (!SeaMonitor.isEnabled()) {
94 | return;
95 | }
96 | if (returnValue == null) {
97 | return;
98 | }
99 |
100 | if (returnValue instanceof ArrayList) {
101 | List data = (ArrayList) returnValue;
102 | if (data.size() >= MAX_RECORD_SIZE) {
103 | log.error("DB501");
104 | MetricDTO metricDTO = new MetricDTO();
105 | metricDTO.setMetric(MonitorConst.METRIC_DB_SQL_LARGE_RECORD_ERROR);
106 | metricDTO.setValue(1);
107 | metricDTO.setErrorFlag(true);
108 | metricDTO.setTraceIdFlag(true);
109 | SeaMonitor.logMetric(metricDTO);
110 | }
111 | }
112 |
113 | }
114 |
115 | @Override
116 | public Object plugin(Object target) {
117 |
118 | return Plugin.wrap(target, this);
119 | }
120 |
121 | @Override
122 | public void setProperties(Properties properties) {
123 |
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/samplers/PercentageBasedSampler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.github.seaframework.monitor.samplers;
18 |
19 | import java.util.BitSet;
20 | import java.util.Random;
21 | import java.util.concurrent.atomic.AtomicLong;
22 |
23 | /**
24 | * SofaTracerPercentageBasedSampler
25 | *
26 | * @author yangguanchao
27 | * @since 2017/06/19
28 | */
29 | public class PercentageBasedSampler implements Sampler {
30 |
31 | public static final String TYPE = "PercentageBasedSampler";
32 |
33 | private final AtomicLong counter = new AtomicLong(0);
34 | private final BitSet sampleDecisions;
35 | private final SamplerProperties configuration;
36 |
37 | public PercentageBasedSampler(SamplerProperties configuration) {
38 | int outOf100 = (int) (configuration.getPercentage());
39 | this.sampleDecisions = randomBitSet(100, outOf100, new Random());
40 | this.configuration = configuration;
41 | }
42 |
43 | @Override
44 | public SamplingStatus sample() {
45 | SamplingStatus samplingStatus = new SamplingStatus();
46 |
47 | if (this.configuration.getPercentage() == 0) {
48 | samplingStatus.setSampled(false);
49 | return samplingStatus;
50 | } else if (this.configuration.getPercentage() == 100) {
51 | samplingStatus.setSampled(true);
52 | return samplingStatus;
53 | }
54 | boolean result = this.sampleDecisions.get((int) (this.counter.getAndIncrement() % 100));
55 | samplingStatus.setSampled(result);
56 | return samplingStatus;
57 | }
58 |
59 | @Override
60 | public String getType() {
61 | return TYPE;
62 | }
63 |
64 | @Override
65 | public void close() {
66 | //do nothing
67 | }
68 |
69 | /**
70 | * Reservoir sampling algorithm borrowed from Stack Overflow.
71 | *
72 | * http://stackoverflow.com/questions/12817946/generate-a-random-bitset-with-n-1s
73 | *
74 | * @param size 大小
75 | * @param cardinality 基数
76 | * @param rnd 随机种子
77 | * @return BitSet
78 | */
79 | public static BitSet randomBitSet(int size, int cardinality, Random rnd) {
80 | BitSet result = new BitSet(size);
81 | int[] chosen = new int[cardinality];
82 | int i;
83 | for (i = 0; i < cardinality; ++i) {
84 | chosen[i] = i;
85 | result.set(i);
86 | }
87 | for (; i < size; ++i) {
88 | int j = rnd.nextInt(i + 1);
89 | if (j < cardinality) {
90 | result.clear(chosen[j]);
91 | result.set(i);
92 | chosen[j] = i;
93 | }
94 | }
95 | return result;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/samplers/Sampler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.github.seaframework.monitor.samplers;
18 |
19 |
20 | public interface Sampler {
21 |
22 | SamplingStatus sample();
23 |
24 | String getType();
25 |
26 | /**
27 | * Release any resources used by the sampler.
28 | */
29 | void close();
30 | }
31 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/samplers/SamplerProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.github.seaframework.monitor.samplers;
18 |
19 | /**
20 | * SamplerProperties
21 | *
22 | * @author yangguanchao
23 | * @since 2017/06/20
24 | */
25 | public class SamplerProperties {
26 | /**
27 | * Percentage of requests that should be sampled. E.g. 1.0 - 100% requests should be
28 | * sampled. The precision is whole-numbers only (i.e. there's no support for 1.0 of
29 | * the traces).
30 | */
31 | private float percentage = 100;
32 |
33 | /**
34 | * if use custom rule, you can implements Sample interface and provide this class name
35 | */
36 | private String ruleClassName;
37 |
38 | public float getPercentage() {
39 | return percentage;
40 | }
41 |
42 | public void setPercentage(float percentage) {
43 | this.percentage = percentage;
44 | }
45 |
46 | public String getRuleClassName() {
47 | return ruleClassName;
48 | }
49 |
50 | public void setRuleClassName(String ruleClassName) {
51 | this.ruleClassName = ruleClassName;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/samplers/SamplingStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package com.github.seaframework.monitor.samplers;
18 |
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 | public class SamplingStatus {
23 |
24 | private boolean isSampled = false;
25 |
26 | /***
27 | * 允许在 RootSpan 处放置 tags
28 | */
29 | private Map tags = new HashMap();
30 |
31 | public boolean isSampled() {
32 | return isSampled;
33 | }
34 |
35 | public void setSampled(boolean sampled) {
36 | isSampled = sampled;
37 | }
38 |
39 | public Map getTags() {
40 | return tags;
41 | }
42 |
43 | public void setTags(Map tags) {
44 | this.tags = tags;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/trace/TraceExtension.java:
--------------------------------------------------------------------------------
1 | package com.github.seaframework.monitor.trace;
2 |
3 | /**
4 | * module name
5 | *
6 | * @author spy
7 | * @version 1.0 2020/5/9
8 | * @since 1.0
9 | */
10 | public interface TraceExtension {
11 | /**
12 | * 返回tranceId
13 | *
14 | * @return
15 | */
16 | String getTraceId();
17 | }
18 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/trace/impl/DefaultTraceExtension.java:
--------------------------------------------------------------------------------
1 | package com.github.seaframework.monitor.trace.impl;
2 |
3 | import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext;
4 | import com.alipay.common.tracer.core.holder.SofaTraceContextHolder;
5 | import com.github.seaframework.core.loader.LoadLevel;
6 | import com.github.seaframework.monitor.trace.TraceExtension;
7 | import lombok.extern.slf4j.Slf4j;
8 |
9 | /**
10 | * module name
11 | *
12 | * @author spy
13 | * @version 1.0 2020/5/9
14 | * @since 1.0
15 | */
16 | @Slf4j
17 | @LoadLevel(name = "default")
18 | public class DefaultTraceExtension implements TraceExtension {
19 |
20 | @Override
21 | public String getTraceId() {
22 | try {
23 | SofaTracerSpanContext spanContext = SofaTraceContextHolder.getSofaTraceContext()
24 | .getCurrentSpan()
25 | .getSofaTracerSpanContext();
26 | return spanContext.getTraceId();
27 | } catch (Exception e) {
28 | log.error("fail to get span_id");
29 | }
30 |
31 | return "";
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/util/JMXUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.seaframework.monitor.util;
2 |
3 | import javax.management.*;
4 | import java.lang.management.ManagementFactory;
5 | import java.util.Set;
6 |
7 | public class JMXUtil {
8 |
9 | /**
10 | * 注册一个MBean
11 | */
12 | public static ObjectName register(String name, Object mbean) {
13 | try {
14 | ObjectName objectName = new ObjectName(name);
15 | MBeanServer mbeanServer = getMBeanServer();
16 | try {
17 | mbeanServer.registerMBean(mbean, objectName);
18 | } catch (InstanceAlreadyExistsException ex) {
19 | mbeanServer.unregisterMBean(objectName);
20 | mbeanServer.registerMBean(mbean, objectName);
21 | }
22 | return objectName;
23 | } catch (JMException e) {
24 | throw new IllegalArgumentException(name, e);
25 | }
26 | }
27 |
28 | /**
29 | * 取消一个MBean
30 | */
31 | public static void unregister(String name) {
32 | try {
33 | MBeanServer mbeanServer = getMBeanServer();
34 | mbeanServer.unregisterMBean(new ObjectName(name));
35 | } catch (JMException e) {
36 | throw new IllegalArgumentException(name, e);
37 | }
38 | }
39 |
40 | /**
41 | * 生成一个ObjectName,如果出错,返回null
42 | */
43 | public static ObjectName createObjectName(String pattern) {
44 | try {
45 | return new ObjectName(pattern);
46 | } catch (Exception ex) {
47 | // Ignore.
48 | }
49 |
50 | return null;
51 | }
52 |
53 | /**
54 | * 获取类型Pattern列表
55 | */
56 | public static ObjectName[] getObjectNames(ObjectName pattern) {
57 | ObjectName[] result = new ObjectName[0];
58 | Set objectNames = getMBeanServer().queryNames(pattern, null);
59 | if (objectNames != null && !objectNames.isEmpty()) {
60 | result = objectNames.toArray(new ObjectName[objectNames.size()]);
61 | }
62 | return result;
63 | }
64 |
65 | public static MBeanServer getMBeanServer() {
66 | MBeanServer mBeanServer = null;
67 | if (MBeanServerFactory.findMBeanServer(null).size() > 0) {
68 | mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
69 | } else {
70 | mBeanServer = ManagementFactory.getPlatformMBeanServer();
71 | }
72 | return mBeanServer;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/util/MonitorPushScheduler.java:
--------------------------------------------------------------------------------
1 | package com.github.seaframework.monitor.util;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 |
7 | import java.util.concurrent.Executors;
8 | import java.util.concurrent.ScheduledExecutorService;
9 | import java.util.concurrent.ThreadFactory;
10 |
11 | /**
12 | * module name
13 | *
14 | * @author spy
15 | * @version 1.0 2020/3/27
16 | * @since 1.0
17 | */
18 | @Slf4j
19 | public class MonitorPushScheduler {
20 |
21 | private static final Logger logger = LoggerFactory.getLogger(MonitorPushScheduler.class);
22 |
23 | private static final ScheduledExecutorService MonitorScheduler = Executors.newSingleThreadScheduledExecutor(
24 | new ThreadFactory() {
25 | @Override
26 | public Thread newThread(Runnable r) {
27 | return new Thread(r, "sea-monitor-push-scheduler");
28 | }
29 |
30 | });
31 |
32 |
33 | public static void init() {
34 | logger.info("MonitorPushScheduler start");
35 | // MonitorScheduler.scheduleAtFixedRate(new MonitorPushRunner(), MonitorConst.PUSH_PERIOD_TIME,
36 | // MonitorConst.PUSH_PERIOD_TIME, TimeUnit.SECONDS);
37 | }
38 |
39 | // static class MonitorPushRunner implements Runnable {
40 | //
41 | // @Override
42 | // public void run() {
43 | // try {
44 | // Map monitors = Maps.newHashMap();
45 | // FalconMonitor.generateBusinessMetrics(monitors);
46 | // MonitorSendUtil.send(monitors);
47 | // } catch (Exception e) {
48 | // logger.error("run MonitorPushRunner exception", e);
49 | // }
50 | // }
51 | // }
52 |
53 | public static void destroy() {
54 | MonitorScheduler.shutdownNow();
55 | }
56 |
57 | }
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/util/MonitorSendUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.seaframework.monitor.util;
2 |
3 | import com.github.seaframework.core.http.simple.HttpClientUtil;
4 | import com.github.seaframework.core.model.BaseResult;
5 | import lombok.extern.slf4j.Slf4j;
6 |
7 | /**
8 | * module name
9 | *
10 | * @author spy
11 | * @version 1.0 2020/3/27
12 | * @since 1.0
13 | */
14 | @Slf4j
15 | public class MonitorSendUtil {
16 | public void send(String url, Object obj) {
17 | BaseResult ret = HttpClientUtil.postJSONSafe(url, obj);
18 | if (!ret.getSuccess()) {
19 | log.warn("sea monitor send error.");
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/util/TagUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.seaframework.monitor.util;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 |
5 | /**
6 | * module name
7 | *
8 | * @author spy
9 | * @version 1.0 2020/3/24
10 | * @since 1.0
11 | */
12 | @Slf4j
13 | public class TagUtil {
14 |
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/util/ThreadPoolUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.seaframework.monitor.util;
2 |
3 | import com.github.seaframework.core.util.NumberUtil;
4 | import com.github.seaframework.monitor.vo.ThreadPoolStatus;
5 | import lombok.extern.slf4j.Slf4j;
6 |
7 | import java.math.RoundingMode;
8 | import java.util.concurrent.ThreadPoolExecutor;
9 |
10 | /**
11 | * module name
12 | *
13 | * @author spy
14 | * @version 1.0 2020/4/9
15 | * @since 1.0
16 | */
17 | @Slf4j
18 | public class ThreadPoolUtil {
19 |
20 |
21 | /**
22 | * get thread pool status
23 | *
24 | * @param tpe
25 | * @return
26 | */
27 | public static ThreadPoolStatus getStatus(ThreadPoolExecutor tpe) {
28 | ThreadPoolStatus status = new ThreadPoolStatus();
29 | if (tpe == null) {
30 | return status;
31 | }
32 |
33 | status.setMax(tpe.getMaximumPoolSize());
34 | status.setCore(tpe.getCorePoolSize());
35 | status.setLargest(tpe.getLargestPoolSize());
36 | status.setActive(tpe.getActiveCount());
37 | status.setTask(tpe.getTaskCount());
38 | status.setActivePercent(NumberUtil.divide(status.getActive(), status.getMax(), 3, RoundingMode.UP).doubleValue());
39 | return status;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/util/TraceUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.seaframework.monitor.util;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 |
5 | /**
6 | * module name
7 | *
8 | * @author spy
9 | * @version 1.0 2020/5/8
10 | * @since 1.0
11 | */
12 | @Slf4j
13 | public class TraceUtil {
14 |
15 | public static String getTraceId() {
16 | //TODO
17 | return "";
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/java/com/github/seaframework/monitor/vo/ThreadPoolStatus.java:
--------------------------------------------------------------------------------
1 | package com.github.seaframework.monitor.vo;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.EqualsAndHashCode;
6 | import lombok.NoArgsConstructor;
7 |
8 | /**
9 | * module name
10 | *
11 | * @author spy
12 | * @version 1.0 2020/4/9
13 | * @since 1.0
14 | */
15 |
16 | @Data
17 | @NoArgsConstructor
18 | @AllArgsConstructor
19 | @EqualsAndHashCode
20 | public class ThreadPoolStatus {
21 |
22 | private String poolName;
23 |
24 | private int max;
25 | private int core;
26 | private int largest;
27 | private int active;
28 | private long task;
29 | private double activePercent;
30 |
31 | // unused
32 | private int queueSize;
33 | }
34 |
--------------------------------------------------------------------------------
/sea-monitor/src/main/resources/META-INF/services/com.github.seaframework.monitor.trace.TraceExtension:
--------------------------------------------------------------------------------
1 | com.github.seaframework.monitor.trace.impl.DefaultTraceExtension
--------------------------------------------------------------------------------
/sea-monitor/src/main/resources/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seaframework/sea-monitor-all/0dcd0c06fc16f88020db8d7e3bfb38c405dd6945/sea-monitor/src/main/resources/README.md
--------------------------------------------------------------------------------
/sea-monitor/src/test/java/com/github/spy/sea/monitor/SeaMonitorTest.java:
--------------------------------------------------------------------------------
1 | package com.github.seaframework.monitor;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import com.github.seaframework.monitor.dto.MetricDTO;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.junit.After;
7 | import org.junit.Before;
8 | import org.junit.Test;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 | import java.util.concurrent.TimeUnit;
13 |
14 | /**
15 | * module name
16 | *
17 | * @author spy
18 | * @version 1.0 2020/3/24
19 | * @since 1.0
20 | */
21 | @Slf4j
22 | public class SeaMonitorTest {
23 |
24 | @Before
25 | public void before() throws Exception {
26 | SeaMonitor.enable();
27 | }
28 |
29 | @Test
30 | public void run16() throws Exception {
31 |
32 | // Tags tags = Tags.of(TagConst.INSTANCE, "11");
33 | //
34 | // tags.and(TagConst.INSTANCE, "11");
35 | //
36 | //
37 | // System.out.println(tags);
38 | }
39 |
40 |
41 | @Test
42 | public void run31() throws Exception {
43 | SeaMonitor.enable();
44 |
45 | SeaMonitor.logMetric("abc", 1);
46 | }
47 |
48 | @After
49 | public void after() throws Exception {
50 | TimeUnit.MINUTES.sleep(5);
51 | }
52 |
53 |
54 | @Test
55 | public void run51() throws Exception {
56 | MetricDTO dto = new MetricDTO();
57 |
58 | dto.setErrorFlag(false);
59 | dto.setMetric("metric.11");
60 | dto.setValue(1);
61 |
62 | Map extraMap = new HashMap<>();
63 | extraMap.put("key", "value");
64 | dto.setExtraMap(extraMap);
65 |
66 | System.out.println(JSON.toJSONString(dto));
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/sea-monitor/src/test/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | %d{HH:mm:ss.SSS} %level [%thread] [%class{36}.%M:%line] - %m %n
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/sea-monitor/src/test/resources/sea.monitor.properties:
--------------------------------------------------------------------------------
1 | #
2 | # current region
3 | sea.region=xinxiang
4 | # sea monitor
5 | sea.monitor.enabled=true
6 | # application name
7 | sea.monitor.endpoint=vs
8 | # sea monitor uri
9 | sea.monitor.uri=http://127.0.0.1:1988/v1/push
10 | # log mode
11 | # 0 report to remote server (by default)
12 | # 1 log to local log file
13 | sea.monitor.mode=0
14 | # trace_id default generate by sofa tracer.
15 | sea.monitor.trace=default
16 | # \u91C7\u6837\u7387
17 | sea.monitor.sample.percent=100
18 | # \u6D88\u8D39\u8005\u4E2A\u6570
19 | sea.monitor.consumer.count=1
20 | # \u53D1\u9001\u7684\u6700\u5927\u5143\u7D20\u4E2A\u6570
21 | sea.monitor.send.element.max.count=200
22 | # \u53D1\u9001\u95F4\u9694
23 | sea.monitor.send.period.time=20
--------------------------------------------------------------------------------