package eu.dnetlib.metrics;

import io.micrometer.prometheus.PrometheusMeterRegistry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Alessia Bardi on 2019-06-21.
 *
 * @author Alessia Bardi
 */
@Controller
@RequestMapping(value = "/prom")
public final class PrometheusEndpoint {

	private static final Log log = LogFactory.getLog(PrometheusEndpoint.class);

	@Autowired
	private PrometheusMeterRegistry registry;

	@RequestMapping(method = RequestMethod.GET, produces = "text/plain;charset=UTF-8")
	@ResponseBody
	public String getStudents() {
		log.info("/prometheus [GET]");
		return registry.scrape();
	}
}
