简体   繁体   English

Kubernetes,Java和Grafana - 如何仅显示正在运行的容器?

[英]Kubernetes, Java and Grafana - How to display only the running containers?

I'm working on a setup where we run our Java services in docker containers hosted on a kubernetes platform. 我正在开发一个设置,我们在kubernetes平台上托管的docker容器中运行我们的Java服务。

On want to create a dashboard where I can monitor the heap usage of all instances of a service in my grafana. 想要创建一个仪表板,我可以在我的grafana中监视服务的所有实例的堆使用情况。 Writing metrics to statsd with the pattern: 使用模式将指标写入statsd:

<servicename>.<containerid>.<processid>.heapspace works well, I can see all heap usages in my chart. <servicename>.<containerid>.<processid>.heapspace运行良好,我可以看到我的图表中的所有堆使用情况。

After a redeployment, the container names change, so new values are added to the existing graph. 重新部署后,容器名称会更改,因此新值将添加到现有图表中。 My problem is, that the old lines continue to exist at the position of the last value received, but the containers are already dead. 我的问题是,旧行继续存在于收到的最后一个值的位置,但容器已经死了。

Is there any simple solution for this in grafana? 在grafana有这个简单的解决方案吗? Can I just say: if you didn't receive data for a metric for more than X seconds, abort the chart line? 我可以这样说:如果您没有收到超过X秒的指标数据,请中止图表行吗?

许多容器在14:00退出,但图表仍在继续

Update: Upgrading to the newest Grafana Version and Setting "null" as value for "Null value" in Stacking and Null Value didn't work. 更新:升级到最新的Grafana版本并将“null”设置为Stacking和Null Value中的“Null值”的值不起作用。

Maybe it's a problem with statsd? 也许这是statsd的问题?

I'm sending data to statsd in form of: 我正在以下列形式向statsd发送数据:

felix.javaclient.machine<number>-<pid>.heap:<heapvalue>|g

Is anything wrong with this? 这有什么不对吗?

This can happen for 2 reasons, because grafana is using the "connected" setting for null values, and/or (as is the case here) because statsd is sending the previously-seen value for the gauge when there are no updates in the current period. 这可能由于两个原因而发生,因为grafana使用“连接”设置来表示空值,和/或(如此处的情况)因为当当前没有更新时,statsd正在发送先前看到的值的值期。

Grafana Config Grafana Config

You'll want to make 2 adjustments to your graph config: 您需要对图表配置进行2次调整:

First, go to the "Display" tab and under "Stacking & Null value" change "Null value" to "null", that will cause Grafana to stop showing the lines when there is no data for a series. 首先,转到“显示”选项卡,在“堆叠和空值”下将“空值”更改为“空”,这将导致Grafana在没有系列数据时停止显示行。

Second, if you're using a legend you can go to the "Legend" tab and under "Hide series" check the "With only nulls" checkbox, that will cause items to only be displayed in the legend if they have a non-null value during the graph period. 其次,如果您正在使用图例,则可以转到“图例”选项卡,然后在“隐藏系列”下选中“仅使用空值”复选框,这将导致项目仅在图例中显示为非图形期间的空值。

statsd Config statsd配置

The statsd documentation for gauge metrics tells us: 仪表指标统计文档告诉我们:

If the gauge is not updated at the next flush, it will send the previous value. 如果在下次冲洗时未更新仪表,它将发送先前的值。 You can opt to send no metric at all for this gauge, by setting config.deleteGauges 通过设置config.deleteGauges ,您可以选择不为该仪表发送任何指标

So, the grafana changes alone aren't enough in this case, because the values in graphite aren't actually null (since statsd keeps sending the last reading). 因此,在这种情况下单独改变grafana是不够的,因为石墨中的值实际上不是空的(因为statsd不断发送最后的读数)。 If you change the statsd config to have deleteGauges: true then statsd won't send anything and graphite will contain the null values we expect. 如果您将statsd配置更改为deleteGauges deleteGauges: true则statsd将不会发送任何内容,而graphite将包含我们期望的空值。

Graphite Note 石墨注

As a side note, a setup like this will cause your data folder to grow continuously as you create new series each time a container is launched. 作为旁注,这样的设置将导致您的数据文件夹在每次启动容器时创建新系列时不断增长。 You'll definitely want to look into removing old series after some period of inactivity to avoid filling up the disk. 您肯定希望在一段时间不活动后删除旧系列以避免填满磁盘。 If you're using graphite with whisper that can be as simple as a cron task running find /var/lib/graphite/whisper/ -name '*.wsp' -mtime +30 -delete to remove whisper files that haven't been modified in the last 30 days. 如果你使用带有耳语的石墨,可以像运行find /var/lib/graphite/whisper/ -name '*.wsp' -mtime +30 -delete的cron任务一样简单,以删除未经过的耳语文件在过去30天内修改过。

To do this, I would use 要做到这一点,我会用

maximumAbove(transformNull(felix.javaclient.*.heap, 0), 0)

The transformNull will take any datapoint that is currently null, or unreported for that instant in time, and turn it into a 0 value. transformNull将获取当前为null或当前未报告的任何数据点,并将其转换为0值。

The maximumAbove will only display the series' that have a maximum value above 0 for the selected time period. maximumAbove仅显示所选时间段内最大值大于0的系列。

Using maximumAbove , you can see all history containers, if you wish to see only the currently running containers, you should use just that: currentAbove 使用maximumAbove ,您可以看到所有历史记录容器,如果您只想查看当前正在运行的容器,您应该只使用: currentAbove

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM