通过openfeign实现查询Prometheus的API获取监控指标

问题描述

需要实现通过openfeign从Prometheus的API中查询监控指标数据,对过程进行一下记录。

OpenFeign内容

① PrometheusOpenFeign内容

package com.changkong.monitor.openfeign;

import com.changkong.monitor.dto.prom.PrometheusLabelResponse;
import com.changkong.monitor.dto.prom.PrometheusQueryResponse;
import com.changkong.monitor.dto.prom.PrometheusRangeQueryResponse;
import com.changkong.monitor.dto.prom.PrometheusSeriesResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Prometheus
 */
@FeignClient(value = "prometheus", url = "http://localhost:9090", path = "/api/v1")
public interface PrometheusOpenFeign {


    /**
     * 查询prometheus指标
     *
     * @param query
     * @param time
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "/query")
    PrometheusQueryResponse promValue(@RequestParam("query") String query, @RequestParam("time") String time);

    /**
     * 查询prometheus区间指标
     *
     * @param query
     * @param start
     * @param end
     * @param step
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "/query_range")
    PrometheusRangeQueryResponse promRangeValue(
    @RequestParam("query") String query,
    @RequestParam("start") String start, @RequestParam("end") String end,
    @RequestParam(value = "step", required = false) String step);

    /**
     * 查询prometheus标签值
     *
     * @param searchLabel
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "/label/{searchLabel}/values")
    PrometheusLabelResponse labelValue(@PathVariable String searchLabel);

    /**
     * 根据表达式获取所有标签
     *
     * @param expr
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "/series")
    PrometheusSeriesResponse seriesValue(@RequestParam("match[]") String expr);
}

你可能感兴趣的:(prometheus,java,监控运维,prometheus,spring,boot,java)