Prometheus 计算每天发送到特定 Spring 控制器端点的请求

Prometheus count request per day to a specific Spring controller endpoint

如何查看特定控制器端点在一天或 x 时段内收到的命中数。

我有一个非常基本的演示应用程序。我的控制器看起来像这样。

@RestController
@RequestMapping("/person")
@RequiredArgsConstructor
public class PersonController {

  private final PersonService personService;

  @GetMapping(path = "all")
  public List<Person> getAllPerson() {
    return personService.getAllPersons();
  }

  // etc

我已经配置好prometheus并拥有它运行。

如您所见,我有一张图表显示了总的 logback 事件。

如果想显示 GET http://localhost:8080/person/all 命中的次数,查询会是什么样子。

http_server_requests_seconds_counthttp_server_requests_seconds_sum 指标将包含所需的详细信息。

例如,

http_server_requests_seconds_count{application="xyz",exception="None",method="GET",status="200",uri="/admin/info",} 94078.0
http_server_requests_seconds_sum{application="xyz",exception="None",method="GET",status="200",uri="/admin/info",} 96.108260294

提示:如果启用了 prometheus 管理端点,则可以在 http://example.com/{actuator|admin}/prometheus

中查看 prometheus 指标