This project is a RESTful Student Management System built using Spring Boot, featuring full CRUD operations along with custom application metrics exposed to Prometheus using Spring Boot Actuator + Micrometer.
It demonstrates:
- Java Spring Boot development
- JPA/Hibernate database integration
- REST APIs for student operations
- Custom Micrometer counters and gauges
- Prometheus monitoring setup (Docker-compatible)
- Add a new student
- Update a student
- Fetch all students
- Fetch student by ID
- Delete student
- Custom Counter:
custom.metric.one - Custom Gauge:
custom.metric.two - Actuator + Micrometer metrics exposed at
/actuator/prometheus - Ready for Prometheus + Grafana dashboards
Prometheus config included for scraping metrics.
src/main/java/com/example/demo
│
├── DemoApplication.java
├── entity/
│ └── Student.java
├── repository/
│ └── StudentRepository.java
└── controller/
└── studentController.java
| Field | Type | Description |
|---|---|---|
| rollNo | int | Primary Key |
| name | String | Student name |
| percentage | float | Academic percentage |
| branch | String | Department |
| isPassed | Boolean | Passed/Failed flag |
this.myStudentCounter = Counter.builder("custom.metric.one")
.tags("status", "created")
.description("total number of students created - function one")
.register(meterRegistry);Incremented on every student creation:
this.myStudentCounter.increment();long val = repo.count();
Tags tags = Tags.of("status", "pending");
meterRegistry.gauge("custom.metric.two", tags, val);GET /students
GET /students/{id}
POST /students/add
Example Body:
{
"name": "Priya",
"percentage": 88.5,
"branch": "CSE",
"isPassed": true
}PUT /students/update/{id}
DELETE /students/delete/{id}
Add this inside prometheus.yml:
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_timeout: 10s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'todo-api'
metrics_path: '/actuator/prometheus'
scrape_interval: 3s
static_configs:
- targets: ['host.docker.internal:8080']
labels:
application: 'spring-actuator'git clone https://github.com/priyagupta20044/Java-API-and-Custom-Metrics-using-Spring-Bootmvn clean installmvn spring-boot:run| Type | URL |
|---|---|
| Application | http://localhost:8080 |
| Prometheus Metrics | http://localhost:8080/actuator/prometheus |
custom_metric_one_total{status="created"} 5.0
custom_metric_two{status="pending"} 12.0
Priya Gupta Java • Spring Boot • Machine Learning • Backend Development