Spring AI LLM Cost Monitoring — A Token Dashboard in One Line with Actuator
Learn how to see in numbers and graphs how many tokens your Spring AI chatbot and RAG service uses, how slow it is, and how often it fails. Using just Actuator, which Spring developers are familiar with, you’ll extract the metrics Spring AI is already recording and build dashboards with Prometheus + Grafana.
428 learners
Level Basic
Course period Unlimited
News
1 articles
Hello, this is Lee Do-won (Kenneth).
We’ve added Section 16, “Spring AI Observability — Monitoring LLM Services with Actuator,” to “Practical LLM Service Development for Spring Developers.” Existing students can start learning right away.
Why did we add this section?
In Sections 1–15, we built a "working LLM service" using ChatClient, RAG, and tool calls. But once you launch the service, the questions change.
"How much does this cost per month?"
"I hear responses sometimes take 10 seconds. Where’s the slowdown?"With an LLM service, costs vary with every request, responses can take several seconds, and failures can originate outside our code. Even when everything looks normal—zero errors, Health UP, and HTTP 200—a failure where input tokens suddenly multiply won’t be caught by conventional web monitoring.
Section 16 wraps up by turning the service we’ve built so far into an production-ready LLM service.
What Section 16 Covers
Actuator and Spring AI metrics: Interpret the token, latency, and error metrics generated simply by adding the dependencies.
Prometheus + Grafana dashboard: Build panels for tokens per minute, p95 latency, and error rate. We’ll also cover why it’s important to look at p95 rather than the average.
Distributed tracing (Jaeger): Follow a single RAG or Tool request through the Span tree as it flows from Advisor → vector search → model call → Tool, and use the traceId in error logs to find where it failed.
Prompt Logging and Security: Risks of logging prompts and responses, and separating development and production profiles
Custom cost metric: Create an ObservationHandler that converts tokens into costs in Korean won. We also cover the issue of tokens being counted twice when calling a Tool.
LLM HealthIndicator: A health check that doesn’t call the model, with a 30-second cache and a 2-second timeout
Alert rules and three failure scenarios: Trigger an invalid API key, a model server outage, and a “failure that looks normal” where input tokens jump about 4x because of a single topK setting, then catch them with dashboards and alerts.
Practice Environment and Provided Materials
Reference versions: Spring Boot 3.5 · Spring AI 1.0.x
Model: OpenAI or Ollama (free). You can follow along to the end even without an API key.
Provided materials
Hands-on project
section16-observabilityA Prometheus · Grafana · Jaeger setup that launches with a single
docker composecommandGrafana dashboard JSON (automatically provisioned), alert rules file
Load testing scripts (Bash · PowerShell)
Step-by-step course materials and slides
Because the dashboard and alert rules use Spring AI standard metric names, you can apply them directly to your own project.
Please check before enrolling
Docker Desktop is required. Before starting the hands-on exercises, please first make sure
docker compose up -dworks.Load testing with OpenAI incurs real costs. If you're concerned about the expense, use Ollama mode.
Windows users can use
load-test.ps1.
If you get stuck while taking the course, please post in the Q&A board. Questions like "The dashboard is empty" or "I can’t see my app in Jaeger" are welcome, too. We’ve included a "When You Get Stuck" table at the end of each lecture in the course materials, so you may want to check there first.
If you leave feedback on the new section in a course review, I’ll incorporate it into the next update.
Thank you.
Sincerely, Lee Do-won

