-
Notifications
You must be signed in to change notification settings - Fork 12
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
CDI monitoring quickstart - 2nd try #11
Open
tborcin
wants to merge
1
commit into
SilverThings:devel
Choose a base branch
from
tborcin:devel
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+474
−222
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Sample quickstart for cdi-microservice monitoring. Keep in mind that after minute expires every recorded value, but metrics calculated from this values persist. | ||
|
||
First you need to build a quickstart: | ||
``` | ||
mvn clean package | ||
``` | ||
|
||
Then run quickstart: | ||
``` | ||
java -jar target/cdi-monitoring-*.jar | ||
``` | ||
|
||
By default there are two microservices in this example. One of them is being monitored and second one is not. | ||
|
||
Monitored microservice can be invoked by: | ||
``` | ||
curl http://localhost:8080/silverware/rest/monitoring/monitored_service | ||
``` | ||
|
||
Not monitored microservice: | ||
``` | ||
curl http://localhost:8080/silverware/rest/monitoring/notmonitored_service | ||
``` | ||
|
||
Recorded metrics: | ||
``` | ||
curl http://localhost:8080/silverware/rest/monitoring/show_metrics | ||
``` | ||
|
||
All recorded values: | ||
``` | ||
curl http://localhost:8080/silverware/rest/monitoring/show_values | ||
``` | ||
|
||
Number of values recorded for every microservice: | ||
``` | ||
curl http://localhost:8080/silverware/rest/monitoring/show_values_size | ||
``` | ||
|
||
Quickstart also exposes measured metrics into JMX by default. All you have to do is connect to this process with JMX console and find method getMetrics of JMXPublisherBean. Notice that you still have to invoke monitored service in order to get some measured metrics. |
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,42 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.silverware.demos.quickstarts</groupId> | ||
<artifactId>quickstarts-parent</artifactId> | ||
<version>2.1-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>cdi-monitoring</artifactId> | ||
<packaging>jar</packaging> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.silverware</groupId> | ||
<artifactId>microservices</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.silverware</groupId> | ||
<artifactId>monitoring</artifactId> | ||
<version>2.1-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.silverware</groupId> | ||
<artifactId>rest-client-microservice-provider</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.silverware</groupId> | ||
<artifactId>http-server-microservice-provider</artifactId> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>${version.maven.dependency.plugin}</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
63 changes: 63 additions & 0 deletions
63
...-monitoring/src/main/java/io/silverware/demos/quickstarts/cdi/monitoring/MetricsRest.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,63 @@ | ||
package io.silverware.demos.quickstarts.cdi.monitoring; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import io.silverware.microservices.annotations.Microservice; | ||
import io.silverware.microservices.annotations.MicroserviceReference; | ||
import io.silverware.microservices.monitoring.MetricsAggregator; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
/** | ||
* @author Tomas Borcin | [email protected] | created: 9/25/16. | ||
*/ | ||
@Microservice | ||
@Path("/monitoring") | ||
public class MetricsRest { | ||
|
||
@Inject | ||
@MicroserviceReference | ||
private MonitoredMicroservice monitoredMicroservice; | ||
|
||
@Inject | ||
@MicroserviceReference | ||
private NotMonitoredMicroservice notMonitoredMicroservice; | ||
|
||
@Path("monitored_service") | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String callMonitoredService() { | ||
return this.monitoredMicroservice.hello(); | ||
} | ||
|
||
@Path("notmonitored_service") | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String callNotMonitoredService() { | ||
return this.notMonitoredMicroservice.hello(); | ||
} | ||
|
||
@Path("show_metrics") | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public JsonObject showMetrics() { | ||
return new JsonObject(MetricsAggregator.getMetrics()); | ||
} | ||
|
||
@Path("show_values") | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String showValues() { | ||
return MetricsAggregator.getValues(); | ||
} | ||
|
||
@Path("show_values_size") | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String showValuesSize() { | ||
return MetricsAggregator.getValuesSize(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...g/src/main/java/io/silverware/demos/quickstarts/cdi/monitoring/MonitoredMicroservice.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,49 @@ | ||
package io.silverware.demos.quickstarts.cdi.monitoring; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing license header. |
||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.event.Observes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import io.silverware.microservices.annotations.Microservice; | ||
import io.silverware.microservices.providers.cdi.MicroservicesStartedEvent; | ||
|
||
/** | ||
* @author Tomas Borcin | [email protected] | created: 9/25/16. | ||
*/ | ||
@Microservice | ||
@Path("/monitored_hello_service") | ||
public class MonitoredMicroservice { | ||
|
||
private static final Logger log = LogManager.getLogger(MonitoredMicroservice.class); | ||
|
||
public MonitoredMicroservice() { | ||
log.info("Monitored microservice constructor"); | ||
} | ||
|
||
@PostConstruct | ||
public void onInit() { | ||
log.info("Monitored microservice PostConstruct " + this.getClass().getName()); | ||
} | ||
|
||
@Path("hello") | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello() { | ||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
return "Monitored microservice hello method\n"; | ||
} | ||
|
||
public void eventObserver(@Observes MicroservicesStartedEvent event) { | ||
log.info("Monitored microservice MicroservicesStartedEvent"); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...rc/main/java/io/silverware/demos/quickstarts/cdi/monitoring/NotMonitoredMicroservice.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,51 @@ | ||
package io.silverware.demos.quickstarts.cdi.monitoring; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing license header. |
||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.event.Observes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import io.silverware.microservices.annotations.Microservice; | ||
import io.silverware.microservices.monitoring.annotations.NotMonitored; | ||
import io.silverware.microservices.providers.cdi.MicroservicesStartedEvent; | ||
|
||
/** | ||
* @author Tomas Borcin | [email protected] | created: 9/25/16. | ||
*/ | ||
@Microservice | ||
@Path("/notmonitored_hello_service") | ||
public class NotMonitoredMicroservice { | ||
|
||
private static final Logger log = LogManager.getLogger(NotMonitoredMicroservice.class); | ||
|
||
public NotMonitoredMicroservice() { | ||
log.info("NotMonitored microservice constructor"); | ||
} | ||
|
||
@PostConstruct | ||
public void onInit() { | ||
log.info("NotMonitored microservice PostConstruct " + this.getClass().getName()); | ||
} | ||
|
||
@Path("hello") | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@NotMonitored | ||
public String hello() { | ||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
return "NotMonitored microservice hello method\n"; | ||
} | ||
|
||
public void eventObserver(@Observes MicroservicesStartedEvent event) { | ||
log.info("NotMonitored microservice MicroservicesStartedEvent"); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
quickstarts/cdi-monitoring/src/main/resources/META-INF/beans.xml
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,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | ||
</beans> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing license header.