getting the metrics of an endpoint - java

I have an endpoint of my API, now I want to track that whenever a request is being made to my endpoint then how many were returning 200 and how many were returning 400 or other HTTP status code please advise how can I achieve the same in spring boot project, I am using spring boot actuators 2.
Suppose my endpoint is:
https://localhost:9090/users
So what I want is:
{
"404": 1,
"200": 6,
"409": 1
}

You can use /actuator/metrics/ to get all endPoints which are executed/called with their count, exception, outcome, status, total time, etc. For this case count, status is useful
For that, you have to add a dependency in pom.xml or similar in grade
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
Get Dependency
To get details of all endPoint which are executed/called (see outcome all endPoint)
localhost:8889/actuator/metrics/http.server.requests
To get details of particular endPoint (see outcome particular
endPoint)
localhost:8889/actuator/metrics/http.server.requests?tag=uri:<endPoint>
localhost:8889/actuator/metrics/http.server.requests?tag=uri:/users
To get the count of particular endPoint with Status Code (see outcome
particular endPoint with Status code)
localhost:8889/actuator/metrics/http.server.requests?tag=uri:/users&tag=status:200
outcome all endPoint
{
"name": "http.server.requests",
"description": null,
"baseUnit": "seconds",
"measurements": [
{
"statistic": "COUNT",
"value": 13
},
{
"statistic": "TOTAL_TIME",
"value": 0.42338
},
{
"statistic": "MAX",
"value": 0
}
],
"availableTags": [
{
"tag": "exception",
"values": [
"None"
]
},
{
"tag": "method",
"values": [
"GET"
]
},
{
"tag": "uri",
"values": [
"/actuator/metrics/{requiredMetricName}",
"/getCountByStatus"
]
},
{
"tag": "outcome",
"values": [
"CLIENT_ERROR",
"SUCCESS"
]
},
{
"tag": "status",
"values": [
"404",
"200"
]
}
]
}
see outcome particular endPoint
{
"name": "http.server.requests",
"description": null,
"baseUnit": "seconds",
"measurements": [
{
"statistic": "COUNT",
"value": 5
},
{
"statistic": "TOTAL_TIME",
"value": 0.1830878
},
{
"statistic": "MAX",
"value": 0
}
],
"availableTags": [
{
"tag": "exception",
"values": [
"None"
]
},
{
"tag": "method",
"values": [
"GET"
]
},
{
"tag": "outcome",
"values": [
"CLIENT_ERROR",
"SUCCESS"
]
},
{
"tag": "status",
"values": [
"404",
"200"
]
}
]
}
outcome particular endPoint with Status code
{
"name": "http.server.requests",
"description": null,
"baseUnit": "seconds",
"measurements": [
{
"statistic": "COUNT",
"value": 3
},
{
"statistic": "TOTAL_TIME",
"value": 0.034849
},
{
"statistic": "MAX",
"value": 0
}
],
"availableTags": [
{
"tag": "exception",
"values": [
"None"
]
},
{
"tag": "method",
"values": [
"GET"
]
},
{
"tag": "outcome",
"values": [
"SUCCESS"
]
}
]
}

Configure Spring boot actuator dependencies in your pom.xml file.
The metrics you required can be accessible by this endpoint localhost:8080/actuato/metrics
It will contains statistics like threads, heap memory, remaining memory etc.
For your case these two keys in that JSON response will be useful.
Guage and counter
Guage - will gives each API response time.
Counter - this will full fill your requirement like {
200:4,
400:1
}
Explaination :
Your API returns 200 status code 4 times and 400 status code 1 time.

Related

How to reach Value if value is in form of uuid in Postman

The response body is
{
"name": "1",
"widgets": {
"ijklmnop-abcd-1234-91f0-f51f1825b788": {
"id": "ijklmnop-abcd-1234-91f0-f51f1825b788",
"width": 1760,
"content": {
"params": {
"data": [
0
],
"aggregations": [
],
"valueTypes": [
"none"
]
}
}
},
"abcdefgh-5678-90ds-ae27-abae62385a55": {
"id": "abcdefgh-5678-90ds-ae27-abae62385a55",
"width": 1240,
"content": {
"params": {
"data": 1,
"values": [],
"timestamps": []
}
}
}
}
}
Here I want to extract as well as check id and other parameters inside abcdefgh-5678-90ds-ae27-abae62385a55(uuid) in the body?

Create N number of GCP compute instances using Rest api

How to create n number of instances in GCP using rest api.
in AWS java SDK, there is a method withMaxCount where we specify number of ec2 instances.
Similarly is there anything for GCP compute.
You can use REST API in loop to create instances.
Example request will look something like this:
{
"kind": "compute#instance",
"name": "INSTANCE-NAME",
"zone": "projects/PROJECT-NAME/zones/us-central1-a",
"machineType": "projects/PROJECT-NAME/zones/us-central1-a/machineTypes/e2-medium",
"displayDevice": {
"enableDisplay": false
},
"metadata": {
"kind": "compute#metadata",
"items": []
},
"tags": {
"items": []
},
"disks": [
{
"kind": "compute#attachedDisk",
"type": "PERSISTENT",
"boot": true,
"mode": "READ_WRITE",
"autoDelete": true,
"deviceName": "INSTANCE-NAME",
"initializeParams": {
"sourceImage": "projects/debian-cloud/global/images/debian-10-buster-v20210122",
"diskType": "projects/PROJECT-NAME/zones/us-central1-a/diskTypes/pd-standard",
"diskSizeGb": "10",
"labels": {}
},
"diskEncryptionKey": {}
}
],
"canIpForward": false,
"networkInterfaces": [
{
"kind": "compute#networkInterface",
"subnetwork": "regions/us-central1/subnetworks/default",
"accessConfigs": [
{
"kind": "compute#accessConfig",
"name": "External NAT",
"type": "ONE_TO_ONE_NAT",
"networkTier": "PREMIUM"
}
],
"aliasIpRanges": []
}
],
"description": "",
"labels": {},
"scheduling": {
"preemptible": false,
"onHostMaintenance": "MIGRATE",
"automaticRestart": true,
"nodeAffinities": []
},
"deletionProtection": false,
"reservationAffinity": {
"consumeReservationType": "ANY_RESERVATION"
},
"serviceAccounts": [
{
"email": "111111111111-compute#developer.gserviceaccount.com",
"scopes": [
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring.write",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/trace.append"
]
}
],
"shieldedInstanceConfig": {
"enableSecureBoot": false,
"enableVtpm": true,
"enableIntegrityMonitoring": true
},
"confidentialInstanceConfig": {
"enableConfidentialCompute": false
}
}
Replace it with your own project name and service account, and you can test it here.

Unable to get Actuator's measurements [ "statistic": "TOTAL_TIME" ] in Graphite server

I have a micro-service with spring-boot-2.2.4 with actuator. When I hit the /actuator/metrics/http.server.requests url, I'm getting below response.
{
"name": "http.server.requests",
"description": null,
"baseUnit": "milliseconds",
"measurements": [
{
"statistic": "COUNT",
"value": 77.0
},
{
"statistic": "TOTAL_TIME",
"value": 2272.891396
},
{
"statistic": "MAX",
"value": 0.0
}
],
"availableTags": [
{
"tag": "exception",
"values": [
"None"
]
},
{
"tag": "method",
"values": [
"GET"
]
},
{
"tag": "uri",
"values": [
"/queue/{queueId}",
"/actuator/metrics/{requiredMetricName}"
]
},
{
"tag": "outcome",
"values": [
"SUCCESS"
]
},
{
"tag": "status",
"values": [
"200"
]
}
]
}
In graphite server I'm able to get the count details but I'm unable to get the TOTAL_TIME metrics details. Can someone please help me to figure out this issue. Where can I get this TOTAL_TIME in graphite server UI.

GoCD - Downstream Pipelines are scheduled and asgined but not starting

I´m running the GO-CD Server and Agents as Alpine Docker containers on a linux machine
I´m adding several pipelines through the json config plugin. The Server seems to start the first Pipeline and upload all the materials. Then he triggers 2 downstream pipes who´ll fetch the materials.
The 2 Downstream pipelines are beeing scheduled and asingned to an agent but they are not starting.
I´ve stopped the stages to see if the error was still comming and they stopped too.
2018-08-29 15:34:28,029 ERROR [85#MessageListener for WorkFinder] JMSMessageListenerAdapter:77 - Exception thrown in message handling by listener com.thoughtworks.go.server.messaging.scheduling.WorkFinder#2c731a16
java.lang.NullPointerException: null
2018-08-29 15:34:36,919 ERROR [85#MessageListener for WorkFinder] JMSMessageListenerAdapter:77 - Exception thrown in message handling by listener com.thoughtworks.go.server.messaging.scheduling.WorkFinder#2c731a16
java.lang.NullPointerException: null
2018-08-29 15:34:38,040 ERROR [85#MessageListener for WorkFinder] JMSMessageListenerAdapter:77 - Exception thrown in message handling by listener com.thoughtworks.go.server.messaging.scheduling.WorkFinder#2c731a16
java.lang.NullPointerException: null
Thats how the some of the pipelines are configured in the repository
{
"format_version" : 3,
"group": "group1",
"name": "Test-Pipeline-Stage",
"label_template": "${COUNT}",
"enable_pipeline_locking" : false,
"parameters": [],
"materials": [
{
"type": "git",
"url": ""
}
],
"stages": [
{
"name": "Test",
"fetch_materials": true,
"never_cleanup_artifacts": false,
"clean_working_directory": false,
"approval" : null,
"jobs": [{
"name": "RunUnittestAndCoverage",
"run_instance_count" : "all",
"environment_variables": [],
"timeout": 1,
"tabs": [
{
"name": "coverage",
"path": "coverage/coverage.html/index.html"
}
],
"artifacts": [
{
"source":"project.tar.gz",
"destination":"project_source",
"type":"build"
},
{
"source": "test_result.xml",
"destination": "testoutput",
"type": "test"
},
{
"source": "coverage.html",
"destination": "coverage",
"type": "build"
},
{
"source": "coverage.xml",
"destination": "coverage",
"type": "build"
}
],
"tasks":[
{
"type": "exec",
"run_if": "passed",
"on_cancel": null,
"command":"tox"
},
{
"type":"exec",
"run_if": "passed",
"on_cancel": null,
"command":"/usr/bin/xmllint",
"arguments": [
"--format",
"test_resulto.xml",
"--output",
"test_result.xml"
]
},
{
"type":"exec",
"run_if": "passed",
"on_cancel": null,
"command": "/bin/ls",
"arguments":[
"-al"
]
},
{
"type":"exec",
"run_if": "passed",
"on_cancel": null,
"command": "/bin/tar",
"arguments":[
"-cvzf",
"project.tar.gz",
"/godata/pipelines/Test-Pipeline-Stage"
]
}
]
}
]
}
]
}
{
"format_version" : 3,
"group": "group1",
"name": "Docker-Deployment-Pipeline-Stage",
"label_template": "${COUNT}",
"enable_pipeline_locking" : false,
"parameters": [],
"materials": [
{
"type": "dependency",
"pipeline": "Build-Pipeline-Stage",
"stage": "BuildPythonProduct",
"name": "project_source"
},
{
"type": "dependency",
"pipeline": "Analyse-Pipeline-Stage",
"stage":"Analyse",
"name":"analyse_result"
}
],
"stages":[
{
"name": "BuildDockerImage",
"fetch_materials": true,
"never_cleanup_artifacts": false,
"clean_working_directory": false,
"approval" : null,
"jobs":[
{
"name": "BuildImage",
"run_instance_count" : "all",
"environment_variables": [],
"timeout": 1,
"tasks": [
{
"type": "fetch",
"artifact_origin": "gocd",
"run_if": "any",
"pipeline": "Build-Pipeline-Stage",
"stage": "BuildPythonProduct",
"job": "BuildAndUpLoadWheel",
"is_source_a_file": true,
"source": "docker/Dockerfile",
"destination": ""
},
{
"type": "fetch",
"artifact_origin": "gocd",
"run_if": "any",
"pipeline": "Build-Pipeline-Stage",
"stage": "BuildPythonProduct",
"job": "BuildAndUpLoadWheel",
"is_source_a_file": true,
"source": "docker/production.ini",
"destination": ""
},
{
"type":"exec",
"run_if": "passed",
"on_cancel": null,
"command":"/usr/bin/docker",
"arguments": [
"build",
"-t",
"project_creator",
"."
]
}
]
}
]
}
]
}

Generalised solution to edit a json for SCIM apis using the attributes and excludedAttributes

Below is the original response:
{
"emails": [
{
"type": "work",
"value": "bjensen#example.com"
}
],
"id": "2819c223-7f76-453a-919d-413861904646",
"phoneNumbers": [
{
"type": "work",
"value": "555-555-8377"
},
{
"type": "business",
"value": "555-555-8377"
}
],
"schemas": [
"urn:scim:schemas:core:1.0"
],
"userName": "bjensen"
}
And in the above response I would pass excludedAttributes=phoneNumbers.type and the response should be like below:
{
"emails": [
{
"type": "work",
"value": "bjensen#example.com"
}
],
"id": "2819c223-7f76-453a-919d-413861904646",
"phoneNumbers": [
{
"value": "555-555-8377"
},
{
"value": "555-555-8377"
}
],
"schemas": [
"urn:scim:schemas:core:1.0"
],
"userName": "bjensen"
}

Categories

Resources