prometheus自定义指标02

编程

1、写测试代码,端口6060

package com.example.demo.controller;

import com.example.demo.entity.User;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.client.RestTemplate;

import java.util.Random;

import java.util.concurrent.TimeUnit;

@RestController

public class TestController {

@PostMapping("/order")

public User getUser() {

User user = new User();

user.setId(1L);

try {

TimeUnit.MILLISECONDS.sleep(new Random().nextInt(10) * 100);

} catch (InterruptedException e) { }

return user;

}

public static void main(String[] args) {

RestTemplate restTemplate = new RestTemplate();

while (true) {

String url = "http://localhost:6060/order";

if (new Random().nextInt(10) > 3) {

url = "http://localhost:5050/order";

}

String result = restTemplate.postForObject(url, null, String.class);

System.out.println(result);

}

}

}

访问:http://localhost:6060/actuator/prometheus

结果如下(访问了接口,才有数据):

 

2、新建一个Dashboard

3、选择图表

4、编辑图表

5、在DataSouce选择数据源,输入查询条件

以上是 prometheus自定义指标02 的全部内容, 来源链接: utcz.com/z/511871.html

回到顶部