Expanding on the idea of @Oliver I'm adding a sample java class which exposes the currently used application version, git branch and git commit id to the Prometheus metrics endpoint after the application is started/ready.
This assumes that you have a spring boot app with prometheus metrics enabled as an actuator endpoint.
@Component
@RequiredArgsConstructor
public class PrometheusCustomMetricsService implements ApplicationListener<ApplicationReadyEvent> {
private static final int FIXED_VALUE = 1;
@Value("${info.project.version}")
private String applicationVersion;
private final MeterRegistry meterRegistry;
private final GitProperties gitProperties;
@Override
public void onApplicationEvent(@NonNull ApplicationReadyEvent event) {
registerApplicationInfoGauge();
}
private void registerApplicationInfoGauge() {
Tag versionTag = new ImmutableTag("application_version", applicationVersion);
Tag branchTag = new ImmutableTag("branch", gitProperties.getBranch());
Tag commitIdTag = new ImmutableTag("commit_id", gitProperties.getShortCommitId());
meterRegistry.gauge("application_info",
List.of(versionTag, branchTag, commitIdTag),
new AtomicInteger(FIXED_VALUE));
}
}
Your custom metric should show up something like this in the prometheus endpoint:
application_info{application_version="1.2.3",branch="SOME-BRANCH-123",commit_id="123456"} NaN
I wouldn't worry about the value of the application_info gauge being NaN
as we don't need the value and only use it as a way to send over the tags.