Implement the exposition of application metrics #2

Closed
opened 2020-12-11 09:37:25 +01:00 by claudio.atzori · 1 comment

Via the micrometer library. It can be integrated flawlessly in spingboot applications and you can follow the same approach used for the openaire-exporter app

https://code-repo.d4science.org/D-Net/dnet-openaire-exporter

In the pom.xml file

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>io.micrometer</groupId>
			<artifactId>micrometer-registry-prometheus</artifactId>
		</dependency>

relevant application properties

https://code-repo.d4science.org/D-Net/dnet-openaire-exporter/src/branch/master/src/main/resources/application.properties

management.endpoints.web.exposure.include   =   prometheus,health

management.endpoints.web.base-path                  =   /
management.endpoints.web.path-mapping.prometheus    =   metrics
management.endpoints.web.path-mapping.health        =   health

A special metric needed to show in the prometheus dashboard the application version declared in the pom.xml file (micrometer_info)

https://code-repo.d4science.org/D-Net/dnet-openaire-exporter/src/branch/master/src/main/java/eu/dnetlib/DNetOpenaireExporterBeanFactory.java

	@Value("pom.xml")
	private ClassPathResource pom;

	@PostConstruct
	public void init() {
		final MavenXpp3Reader reader = new MavenXpp3Reader();
		try {
			final Model model = reader.read(new InputStreamReader(pom.getInputStream()));

			log.info(String.format("registering metric for %s", model.getArtifactId()));
			Metrics.gauge("micrometer_info", Lists.newArrayList(
					new ImmutableTag("component", model.getGroupId()+":"+model.getArtifactId()),
					new ImmutableTag("version", model.getVersion()),
					new ImmutableTag("scmtag", model.getScm().getTag())), 1);
		} catch (IOException | XmlPullParserException e) {
			log.error(e);
		}
	}
Via the micrometer library. It can be integrated flawlessly in spingboot applications and you can follow the same approach used for the openaire-exporter app https://code-repo.d4science.org/D-Net/dnet-openaire-exporter In the pom.xml file ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency> ``` relevant application properties https://code-repo.d4science.org/D-Net/dnet-openaire-exporter/src/branch/master/src/main/resources/application.properties ``` management.endpoints.web.exposure.include = prometheus,health management.endpoints.web.base-path = / management.endpoints.web.path-mapping.prometheus = metrics management.endpoints.web.path-mapping.health = health ``` A special metric needed to show in the prometheus dashboard the application version declared in the pom.xml file (micrometer_info) https://code-repo.d4science.org/D-Net/dnet-openaire-exporter/src/branch/master/src/main/java/eu/dnetlib/DNetOpenaireExporterBeanFactory.java ``` @Value("pom.xml") private ClassPathResource pom; @PostConstruct public void init() { final MavenXpp3Reader reader = new MavenXpp3Reader(); try { final Model model = reader.read(new InputStreamReader(pom.getInputStream())); log.info(String.format("registering metric for %s", model.getArtifactId())); Metrics.gauge("micrometer_info", Lists.newArrayList( new ImmutableTag("component", model.getGroupId()+":"+model.getArtifactId()), new ImmutableTag("version", model.getVersion()), new ImmutableTag("scmtag", model.getScm().getTag())), 1); } catch (IOException | XmlPullParserException e) { log.error(e); } } ```
michele.artini was assigned by claudio.atzori 2020-12-11 09:37:25 +01:00
Author
Owner

Implemented, closing.

Implemented, closing.
Sign in to join this conversation.
No Label
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: D-Net/dnet-applications#2
No description provided.