forked from fafeidou/fast-cloud-nacos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
qinfuxiang
committed
Dec 3, 2021
1 parent
2ccf5f7
commit afd5af4
Showing
8 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
fast-source-code-analysis/code-metrics/src/main/java/fast/cloud/nacos/metrics/jmx/Hello.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package fast.cloud.nacos.metrics.jmx; | ||
|
||
public class Hello implements HelloMBean { | ||
private String name; | ||
|
||
private String age; | ||
|
||
@Override | ||
public void getTelephone() { | ||
System.out.println("get Telephone"); | ||
} | ||
|
||
@Override | ||
public void helloWorld() { | ||
System.out.println("hello world"); | ||
} | ||
|
||
@Override | ||
public void helloWorld(String str) { | ||
System.out.println("helloWorld:" + str); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
System.out.println("get name 123"); | ||
return name; | ||
} | ||
|
||
@Override | ||
public void setName(String name) { | ||
System.out.println("set name 123"); | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String getAge() { | ||
System.out.println("get age 123"); | ||
return age; | ||
} | ||
|
||
@Override | ||
public void setAge(String age) { | ||
System.out.println("set age 123"); | ||
this.age = age; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...rce-code-analysis/code-metrics/src/main/java/fast/cloud/nacos/metrics/jmx/HelloAgent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package fast.cloud.nacos.metrics.jmx; | ||
|
||
import javax.management.MBeanServer; | ||
import javax.management.ObjectName; | ||
import java.lang.management.ManagementFactory; | ||
|
||
/** | ||
* @author qinfuxiang | ||
*/ | ||
public class HelloAgent { | ||
|
||
public static void main(String[] args) throws Exception { | ||
MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | ||
ObjectName helloName = new ObjectName("jmxBean:name=hello"); | ||
//create mbean and register mbean | ||
Hello hello = new Hello(); | ||
hello.setName("123"); | ||
server.registerMBean(hello, helloName); | ||
Thread.currentThread().join(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...rce-code-analysis/code-metrics/src/main/java/fast/cloud/nacos/metrics/jmx/HelloMBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package fast.cloud.nacos.metrics.jmx; | ||
|
||
public interface HelloMBean | ||
{ | ||
public String getName(); | ||
|
||
public void setName(String name); | ||
|
||
public String getAge(); | ||
|
||
public void setAge(String age); | ||
|
||
public void helloWorld(); | ||
|
||
public void helloWorld(String str); | ||
|
||
public void getTelephone(); | ||
} |
28 changes: 28 additions & 0 deletions
28
...ode-metrics/src/main/java/fast/cloud/nacos/metrics/metric/DeadLockHealthCheckExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package fast.cloud.nacos.metrics.metric; | ||
|
||
import com.codahale.metrics.ConsoleReporter; | ||
import com.codahale.metrics.MetricRegistry; | ||
import com.codahale.metrics.health.HealthCheckRegistry; | ||
import com.codahale.metrics.health.jvm.ThreadDeadlockHealthCheck; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author qinfuxiang | ||
*/ | ||
public class DeadLockHealthCheckExample { | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
final HealthCheckRegistry healthService = new HealthCheckRegistry(); | ||
healthService.register("thread-dead-lock-hc", new ThreadDeadlockHealthCheck()); | ||
|
||
final MetricRegistry metricRegistry = new MetricRegistry(); | ||
ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry).build(); | ||
|
||
metricRegistry.gauge("thread-dead-lock-hc",() -> healthService::runHealthChecks); | ||
|
||
consoleReporter.start(10, TimeUnit.SECONDS); | ||
|
||
Thread.currentThread().join(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...code-metrics/src/main/java/fast/cloud/nacos/metrics/metric/JvmInstrumentationExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package fast.cloud.nacos.metrics.metric; | ||
|
||
import com.codahale.metrics.ConsoleReporter; | ||
import com.codahale.metrics.MetricRegistry; | ||
import com.codahale.metrics.jvm.ClassLoadingGaugeSet; | ||
import com.codahale.metrics.jvm.GarbageCollectorMetricSet; | ||
import com.codahale.metrics.jvm.ThreadStatesGaugeSet; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author qinfuxiang | ||
*/ | ||
public class JvmInstrumentationExample { | ||
public final static MetricRegistry metricRegistry = new MetricRegistry(); | ||
public final static ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry).build(); | ||
public static void main(String[] args) throws InterruptedException { | ||
consoleReporter.start(10, TimeUnit.SECONDS); | ||
metricRegistry.registerAll(new GarbageCollectorMetricSet()); | ||
metricRegistry.registerAll(new ThreadStatesGaugeSet()); | ||
metricRegistry.registerAll(new ClassLoadingGaugeSet()); | ||
Thread.currentThread().join(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...code-metrics/src/main/java/fast/cloud/nacos/metrics/metric/RestfulServiceHealthCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package fast.cloud.nacos.metrics.metric; | ||
|
||
import com.codahale.metrics.health.HealthCheck; | ||
|
||
/** | ||
* @author qinfuxiang | ||
*/ | ||
public class RestfulServiceHealthCheck extends HealthCheck { | ||
|
||
@Override | ||
protected Result check() throws Exception { | ||
return Result.healthy("The Restful service well."); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...trics/src/main/java/fast/cloud/nacos/metrics/metric/RestfulServiceHealthCheckExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package fast.cloud.nacos.metrics.metric; | ||
|
||
import com.codahale.metrics.ConsoleReporter; | ||
import com.codahale.metrics.MetricRegistry; | ||
import com.codahale.metrics.health.HealthCheckRegistry; | ||
import com.codahale.metrics.health.jvm.ThreadDeadlockHealthCheck; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author qinfuxiang | ||
*/ | ||
public class RestfulServiceHealthCheckExample { | ||
public static void main(String[] args) throws InterruptedException { | ||
final HealthCheckRegistry healthService = new HealthCheckRegistry(); | ||
healthService.register("thread-dead-lock-hc", new ThreadDeadlockHealthCheck()); | ||
healthService.register("restful-check-hc", new RestfulServiceHealthCheck()); | ||
|
||
final MetricRegistry metricRegistry = new MetricRegistry(); | ||
ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry).build(); | ||
|
||
metricRegistry.gauge("app-health-check",() -> healthService::runHealthChecks); | ||
|
||
consoleReporter.start(10, TimeUnit.SECONDS); | ||
|
||
Thread.currentThread().join(); | ||
} | ||
} |