用千分尺查询数据 [英] querying data with micrometer

查看:141
本文介绍了用千分尺查询数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们拥有这个花哨的监控系统,我们的春季启动服务会将这些指标发布到带有千分尺的嵌入式DB上.有一个很好的grafana前端,但是问题是我们现在处于一个阶段,必须在其他服务中使用其中一些指标来进行推理. 整个系统是由我的前任建立的,而我目前对它的理解几乎为零.我可以添加和发布新的指标,但是我一生都无法得到它的任何帮助.

We have this fancy monitoring system to which our spring-boot services are posting metrics to an influx DB with micrometer. There's a nice grafana frontend, but the problem is that we're now at a stage where we have to have some of these metrics available in other services to reason on. The whole system was set up by my predecessor, and my current understanding of it is practically zero. I can add and post new metrics, but I can't for the life of me get anything out of it.

这是一个简短的示例: 我们的网关会为相机发布到其上的每个图像增加计数器.计数器的定义如下:

Here's a short example: Our gateway increments the counter for each image that a camera posts to it. The definition of the counter looks like this:

private val imageCounters = mutableMapOf<String, Counter>()
private val imageCounter = { camera: String ->
    imageCounters.getOrPut(camera) {
        registry.counter("gateway.image.counter", "camera", camera)
    }

并且计数器在这样的代码中递增:

And the counter is incremented in the code like this:

imageCounter("placeholder-id").increment()

现在,我们正在改善计费,计费服务需要知道某个摄像机通过网关的图像数量.因此,我尝试的第一件事自然是这样的:

Now we're improving our billing, and the billing service needs to know how many images for a certain camera went through the gateway. So naturally the first thing I try looks like this:

class MonitoringService(val metrics: MeterRegistry) {

    private val log = logger()
    private val imageCounters = mutableMapOf<String, Counter>()
    private val imageCounter = { camera: String ->
        imageCounters.getOrPut(camera) {
            metrics.counter("gateway.image.counter", "camera", camera)
        }
    }

    fun test() {
        val test = imageCounter("16004").count()
        val bugme = true
        log.info("influx test: $test")
    }
}

这有两个问题:首先,它总是返回零,所以很明显我做错了.我只是不知道那是什么. 其次,即使它返回一个合理的值,我也看不到一种按时间限制此值的方法(我通常需要当月上传的图像数).

There's two problems with this: First off it always returns zero, so obviously I'm doing it wrong. I just can't figure out what it is. Second, even if it would return a reasonable value, I don't see a way to limit this by time (I'll usually need the number of images uploaded during the current month).

让我担心的是,尽管我可以找到很多有关如何使用千分尺发布数据的文档,但似乎找不到任何有关如何查询的文档.测微计是否仅设计为发布监视数据,而不是查询数据? .getOrPut()方法将表明它可以同时执行这两种操作,但是就我所知,由于查询数据似乎没有记录,因此对我而言这可能是一个误解.

What worries me is that while I can find a lot of documentation on how to post data with micrometer, I can't seem to find any documentation on how to query. Is Micrometer only designed to post monitoring data, but not query it? the .getOrPut() method would indicate it can do both, but since querying data seems undocumented as far as I can tell, that might be a misconception on my part.

有一个Java的influx-db客户端,我将在接下来尝试,但是到最后,我不希望我的应用程序中的多个组件都做同样的事情,只是因为我不熟悉我继承的工具.

There is an influx-db client for Java, which I'll try next, but at the end of the day I don't want multiple components in my application doing the same thing just because I'm not familiar with the tools I inherited.

推荐答案

InfluxMeterRegistryStepMeterRegistry,因此从其创建的CounterStepCounter. StepCounter.increment()在当前步骤中增加计数,但StepCounter.count()将在上一步中返回计数.这就是为什么您已经多次调用increment()的情况下在count()上看到0的原因.您可以在下一步中看到它,默认步骤是1分钟,因此您必须等待1分钟才能看到它.

InfluxMeterRegistry is a StepMeterRegistry, so the created Counter from it is a StepCounter. StepCounter.increment() increments the count in the current step but StepCounter.count() will return the count in the previous step. That's why you're seeing 0 with count() although you've already invoked increment() several times. You can see it in the next step and the default step is 1 minute, so you have to wait for 1 minute to see it.

请参阅以下测试以了解其工作原理:

See the following test to get an idea on how it works: https://github.com/izeye/sample-micrometer-spring-boot/blob/influx/src/test/java/com/izeye/sample/InfluxMeterRegistryTests.java

这篇关于用千分尺查询数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆