Grafana日志插件不显示日志面板 [英] Grafana logs plugin doesn't show logs panel

查看:106
本文介绍了Grafana日志插件不显示日志面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个支持日志面板的Grafana插件.我正在遵循

要使日志面板正常工作,还需要做其他事情吗?这些说明声称,我只需要返回一个 time 类型的字段和一个 string 类型的字段,并在< plugin.json ,但这不起作用.

到目前为止,我唯一能找到的真正提示是关于MSSQL插件的另一个SO问题,这表明有关此功能的某些信息该插件中的将显示需要如何格式化数据,但是我不清楚从源头上了解到这可能是什么以及它与我现在所做的有何不同.

ETA:看起来像解决方案

我找出了答案的一部分.必须在 MutableDataFrame 中添加以下内容:

 元数据:{preferredVisualisationType:日志",}, 

使其激活"在探索中.但是我不认为这是完整的答案,因为按问题和在浏览"视图中所述,该视图仍在仪表板"面板中仍然损坏,但仍可以工作,但默认情况下不会拉出任何字段来显示;必须通过打开日志行并单击眼睛图标以使字段可见来手动将其打开.

ETA:好的,关于视图为何显示为损坏的其余答案是由于日志可视化如何决定要显示的数据.这是在文档中,但可能没有得到应有的清晰显示.它说:

如果一个数据框具有多个文本字段,则Grafana假定该数据框的第一个字段为实际的日志行.任何后续的文本字段均被视为检测到的字段.

因此,数据的格式需要采用某种方式,尤其是第一个字符串字段必须为"message"消息.显示.它看起来像上面一样,因为我在 content 之前放了 level .反转这些可使它按预期工作.

I'm trying to create a Grafana plugin that supports the logs panel. I'm following the directions from their website.

Unfortunately it doesn't seem to work. I've added "logs": true to plugin.json and am returning a field of type time called "time", a field of type string called "level", and a field of type string called "content", following along with their example. I'm returning essentially the same thing as the example shows.

export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
  constructor(instanceSettings: DataSourceInstanceSettings<MyDataSourceOptions>) {
    super(instanceSettings);
  }

  async query(options: DataQueryRequest<MyQuery>): Promise<DataQueryResponse> {
    // Return a constant for each query.
    const data = options.targets.map(target => {
      const query = defaults(target, defaultQuery);
      const frame = new MutableDataFrame({
        refId: query.refId,
        fields: [
          { name: 'time', type: FieldType.time },
          { name: 'level', type: FieldType.string },
          { name: 'content', type: FieldType.string },
        ],
      });
      frame.add({ time: 1615422190000, level: 'warn', content: 'hi' });
      frame.add({ time: 1615422191000, level: 'info', content: 'bye' });
      return frame;
    });

    return { data };
  }

  async testDatasource() {
    // Implement a health check for your data source.
    return {
      status: 'success',
      message: 'Success',
    };
  }
}

Yet in Grafana (running the latest stable version, 7.4.3) when I load my plugin I am unable to get the log panel in Explore and in the Dashboard query interface if I choose the log panel it displays the data but incorrectly:

Is there something else I need to do to make the log panel work? The instructions claim I just need to return a field of type time and a field of type string with "logs": true set in plugin.json, but that's not working.

The only real hint I can find so far is this other SO question about the MSSQL plugin, which suggests that maybe something about this function in that plugin would show how the data needs to be formatted, but it's not clear to me reading the source what that might be and how it's different from what I'm doing now.

ETA: Looks like this question asked something similar but the answer doesn't make it clear what the issue was since it seems in their case they were returning a result of the wrong type altogether.

解决方案

I figured out part of the answer. It's necessary to include the following in the MutableDataFrame:

meta: {
  preferredVisualisationType: 'logs',
},

to get it to "activate" in Explore. However I don't think this is the whole answer because the view is still broken in the Dashboard panel as described in the question and in the Explore view it kinda works but doesn't pull out any fields by default to display; they have to be manually turned on by opening the log line and clicking the eye icon to make a field visible.

ETA: Okay, the rest of the answer on why the view appears broken is because of how the logs visualization decides what data to show. It's in the docs but not called out perhaps as clearly as it should be. It says:

If a data frame has more than one text field, then Grafana assumes the first field in the data frame to be the actual log line. Any subsequent text fields are treated as detected fields.

So the format of the data needs to be a certain way, and in particular the first string field needs to be the "message" to display. It looks the way it does above because I put level before content. Reversing those makes it work as expected.

这篇关于Grafana日志插件不显示日志面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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