This project provides a org.mameli.model.service that fetches all endpoints and their corresponding methods of a Spring Boot application and retrieves metrics for each endpoint using Spring Actuator. The metrics are then compiled into a list and returned, giving an overview of all endpoints and their metrics.
- Java 17
- Spring Boot 3.3
-
Clone the repository:
git clone https://github.com/<your-username>/endpoint-metrics-org.mameli.model.service.git cd endpoint-metrics-org.mameli.model.service
-
Build the project:
./gradlew build
- Ensure your Spring Boot application is running and the Actuator endpoints are enabled. E.g. in application.yml:
management:
endpoints:
web:
exposure:
include: info, health, metrics, mappings
-
Inject the
EndpointMetricsService
into your controller or org.mameli.model.service where you need to fetch the endpoint metrics:@RestController class YourController(private val endpointMetricsService: EndpointMetricsService) { @GetMapping("/metrics") fun getMetrics(): List<EndpointMetrics> { return endpointMetricsService.getEndpointMetrics() } }
-
Scan the configuration of this package:
@ComponentScan(basePackages = ["com.your.packages", "org.mameli"])
-
Access the metrics via the defined endpoint, e.g.,
http://localhost:8080/metrics
.
To include this project as a dependency in your project, follow these steps:
-
Add the GitHub Packages repository and dependency to your
build.gradle
file:repositories { maven { url = uri("https://maven.pkg.github.com/<GitHub-Username>/<Repository-Name>") credentials { username = project.findProperty("gpr.user") ?: System.getenv("USERNAME") password = project.findProperty("gpr.token") ?: System.getenv("TOKEN") } } mavenCentral() } dependencies { implementation 'com.example:endpoint-metrics-org.mameli.model.service:1.0.0' }
-
Create a
gradle.properties
file with your GitHub credentials (or set them as environment variables):gpr.user=<GitHub-Username> gpr.token=<GitHub-Personal-Access-Token>
Here is an example of how to set up the build.gradle
file:
repositories {
maven {
url = uri("https://maven.pkg.github.com/your-username/endpoint-metrics-org.mameli.model.service")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
password = project.findProperty("gpr.token") ?: System.getenv("TOKEN")
}
}
mavenCentral()
}
dependencies {
implementation 'com.example:endpoint-metrics-org.mameli.model.service:1.0.0'
}