A resource tag is a named key-value dimension attached to a metric. It classifies measurements so you can filter a broad count into a useful subset, such as HTTP requests with status 404 or tacos containing flour tortillas. section 15.2.4 section 15.3.3
Use tags to refine metric queries:
- Inspect available tag names and values on a metric such as http.server.requests. section 15.2.4
- Filter with a tag=value request parameter, such as status:404. section 15.2.4
- Combine tags, such as status:404 and uri:/**, to narrow the measurements further. section 15.2.4
- Expect available tag values to shrink as filters remove nonmatching measurements. section 15.2.4
Counting tacos by ingredient
A custom metric can use ingredient as the tag name and an ingredient ID as its value. Each time a taco is created, the counter for every ingredient is incremented. Querying tacocloud?tag=ingredient:FLTO then reports the count for flour tortillas instead of the combined count for all ingredients. section 15.3.3
Listing 15.6 TacoMetrics registers metrics around taco ingredients
package tacos.actuator;
import java.util.List;
import org.springframework.data.rest.core.event.AbstractRepositoryEventListener;
import org.springframework.stereotype.Component;
import io.micrometer.core.instrument.MeterRegistry;
import tacos.Ingredient;
import tacos.Taco;
@Component
public class TacoMetrics extends AbstractRepositoryEventListener<Taco> {
private MeterRegistry meterRegistry;
public TacoMetrics(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
}
@Override
protected void onAfterCreate(Taco taco) {
List<Ingredient> ingredients = taco.getIngredients();
for (Ingredient ingredient : ingredients) {
meterRegistry.counter("tacocloud",
"ingredient", ingredient.getId()).increment();
}
}
}
See the complete TacoMetrics implementation, including MeterRegistry injection, repository-event handling, and tagged counter creation. section 15.3.3





