You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2018/11/20 16:55:25 UTC

[3/7] tomee git commit: adding options and readme changes

adding options and readme changes


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/9e41727a
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/9e41727a
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/9e41727a

Branch: refs/heads/master
Commit: 9e41727aa042031e78e4ce977d5aef78436f9c65
Parents: 0744352
Author: ivanjunckes <ij...@tomitribe.com>
Authored: Tue Nov 20 13:24:09 2018 -0200
Committer: ivanjunckes <ij...@tomitribe.com>
Committed: Tue Nov 20 13:24:09 2018 -0200

----------------------------------------------------------------------
 examples/mp-metrics-counted/README.md           | 114 ++++++++++++++++++-
 .../java/org/superbiz/rest/WeatherService.java  |   4 +-
 .../org/superbiz/rest/WeatherServiceTest.java   |   1 +
 3 files changed, 112 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/9e41727a/examples/mp-metrics-counted/README.md
----------------------------------------------------------------------
diff --git a/examples/mp-metrics-counted/README.md b/examples/mp-metrics-counted/README.md
index 9dafe75..298519a 100644
--- a/examples/mp-metrics-counted/README.md
+++ b/examples/mp-metrics-counted/README.md
@@ -1,19 +1,121 @@
 # Microprofile Metrics
 This is an example on how to use microprofile metrics in TomEE.
 
-The command to run the application the application is:
+##### Run the application:
 
     mvn clean install tomee:run 
 
-Make a call to the greeting endpoint: 
+Within the application there is an enpoint that will give you weather status for the day and week.
 
-    http://localhost:8080/rest-mp-metrics/greeting
+##### For the day status call:
+
+    GET http://localhost:8080/rest-mp-metrics/wather/day/status
     
-Check the metrics in Prometheus format:
+##### Response:
+
+    Hi, today is a sunny day!
     
-    http://localhost:8080/rest-mp-metrics/metrics
+
+### Counted feature
+Microprofile metrics has a feature that can be used to count requests to a service.
+
+To use this feature you need to annotate the JAX-RS resource method with @Counted.
+
+    @Path("/weather")
+    @Produces(MediaType.APPLICATION_JSON)
+    @Consumes(MediaType.APPLICATION_JSON)
+    @ApplicationScoped
+    public class WeatherService {
+
+        @Path("/day/status")
+        @Counted(monotonic = true, name = "weather_day_status", absolute = true)
+        @GET
+        @Produces(MediaType.TEXT_PLAIN)
+        public String dayStatus() {
+            return "Hi, today is a sunny day!";
+        }
+    ...
+    }
+
+There are some configurations, as part of @Counted, that you need to know:
+
+**String name**
+Optional. Sets the name of the metric. If not explicitly given the name of the annotated object is used.
+
+**boolean absolute**
+If true, uses the given name as the absolute name of the metric. If false, prepends the package name and class name before the given name. Default value is false.
+
+**String displayName**
+Optional. A human readable display name for metadata.
+
+**String description**
+Optional. A description of the metric.
+
+**String[] tags**
+Optional. Array of Strings in the <key>=<value> format to supply special tags to a metric.
+
+**boolean reusable**
+Denotes if a metric with a certain name can be registered in more than one place. Does not apply to gauges.
+
+
+Check the counter metric doing a _GET_ request:
+
+##### Prometheus format:
+
+    GET http://localhost:8080/mp-metrics-counted/metrics/application/weather_day_status
     
+##### Response:
+     
+    # TYPE application:weather_day_status counter
+    application:weather_day_status 1.0
     
+  
+##### JSON Format:
+
+For json format add the header _Accept=application/json_ to the request. 
+  
+    {
+        "weather_day_status": {
+            "delegate": {},
+            "unit": "none",
+            "count": 1
+        }
+    }
+   
+#### Metric metadata
+A metric will have a metadata so you can know more information about it, like displayName, description, tags e etc.
+
+Check the metric metadata doing a _OPTIONS_ request:
+
+##### Request
+
+    OPTIONS http://localhost:8080/mp-metrics-counted/metrics/application/weather_day_status
+
+##### Response:
+
+    {
+        "weather_day_status": {
+            "unit": "none",
+            "displayName": "Weather Day Status",
+            "name": "weather_day_status",
+            "typeRaw": "COUNTER",
+            "description": "This metric shows the weather status of the day.",
+            "type": "counter",
+            "value": {
+                "unit": "none",
+                "displayName": "Weather Day Status",
+                "name": "weather_day_status",
+                "tagsAsString": "",
+                "typeRaw": "COUNTER",
+                "description": "This metric shows the weather status of the day.",
+                "type": "counter",
+                "reusable": false,
+                "tags": {}
+            },
+            "reusable": false,
+            "tags": ""
+        }
+    }
+
 
-     
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/9e41727a/examples/mp-metrics-counted/src/main/java/org/superbiz/rest/WeatherService.java
----------------------------------------------------------------------
diff --git a/examples/mp-metrics-counted/src/main/java/org/superbiz/rest/WeatherService.java b/examples/mp-metrics-counted/src/main/java/org/superbiz/rest/WeatherService.java
index 3475e7b..ec856fe 100644
--- a/examples/mp-metrics-counted/src/main/java/org/superbiz/rest/WeatherService.java
+++ b/examples/mp-metrics-counted/src/main/java/org/superbiz/rest/WeatherService.java
@@ -16,7 +16,9 @@ import javax.ws.rs.core.MediaType;
 public class WeatherService {
 
     @Path("/day/status")
-    @Counted(monotonic = true, name = "weather_day_status", absolute = true)
+    @Counted(monotonic = true, name = "weather_day_status", absolute = true,
+            displayName = "Weather Day Status",
+            description = "This metric shows the weather status of the day.")
     @GET
     @Produces(MediaType.TEXT_PLAIN)
     public String dayStatus() {

http://git-wip-us.apache.org/repos/asf/tomee/blob/9e41727a/examples/mp-metrics-counted/src/test/java/org/superbiz/rest/WeatherServiceTest.java
----------------------------------------------------------------------
diff --git a/examples/mp-metrics-counted/src/test/java/org/superbiz/rest/WeatherServiceTest.java b/examples/mp-metrics-counted/src/test/java/org/superbiz/rest/WeatherServiceTest.java
index a2a30b5..db78d03 100644
--- a/examples/mp-metrics-counted/src/test/java/org/superbiz/rest/WeatherServiceTest.java
+++ b/examples/mp-metrics-counted/src/test/java/org/superbiz/rest/WeatherServiceTest.java
@@ -45,6 +45,7 @@ public class WeatherServiceTest {
     @ArquillianResource
     private URL base;
 
+
     @Test
     public void testCountedPrometheus() {
         final String message = WebClient.create(base.toExternalForm())