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

CDI monitoring quickstart - 2nd try #11

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions quickstarts/cdi-monitoring/README.md
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.
42 changes: 42 additions & 0 deletions quickstarts/cdi-monitoring/pom.xml
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package io.silverware.demos.quickstarts.cdi.monitoring;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing license header.


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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.silverware.demos.quickstarts.cdi.monitoring;
Copy link
Contributor

Choose a reason for hiding this comment

The 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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.silverware.demos.quickstarts.cdi.monitoring;
Copy link
Contributor

Choose a reason for hiding this comment

The 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");
}
}
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>
Loading