1

我有一个仪表板,其中包含一些变量(在本例中:类别和 URL):

{
  "templating": {
    "list": [
      {
        "allValue": null,
        "current": {
          "selected": false,
          "text": "default",
          "value": "default"
        },
        "datasource": "Influx-SP",
        "definition": "",
        "error": null,
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "category",
        "options": [],
        "query": "SHOW TAG VALUES WITH KEY = \"category\"",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "datasource": "Influx-SP",
        "definition": "",
        "error": null,
        "hide": 0,
        "includeAll": false,
        "label": "group",
        "multi": false,
        "name": "group",
        "options": [],
        "query": "SHOW TAG VALUES WITH KEY = \"group\" WHERE \"category\" =~ /$category/",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {
          "selected": false,
          "text": "_",
          "value": "_"
        },
        "datasource": "Influx-SP",
        "definition": "",
        "error": null,
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "page",
        "options": [],
        "query": "SHOW TAG VALUES WITH KEY = \"page\" WHERE \"group\" =~ /$group/ AND \"category\" =~ /$category/",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {
          "selected": false,
          "text": "chrome",
          "value": "chrome"
        },
        "datasource": "Influx-SP",
        "definition": "",
        "error": null,
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "browser",
        "options": [],
        "query": "SHOW TAG VALUES WITH KEY = \"browser\" WHERE \"group\" =~ /$group/ AND \"page\"  =~ /$page/ AND \"category\" =~ /$category/",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {
          "selected": false,
          "text": "native",
          "value": "native"
        },
        "datasource": "Influx-SP",
        "definition": "",
        "error": null,
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "connectivity",
        "options": [],
        "query": "SHOW TAG VALUES WITH KEY = \"connectivity\" WHERE \"group\" =~ /$group/ AND \"page\"  =~ /$page/ AND \"browser\" =~ /$browser/ AND \"category\" =~ /$category/",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      }
    ]
  }
}

现在我想让用户查看特定网址的测量值。目前,该字段group显示所有 URL,用户可以看到所有 url 的列表,无论他是否应该看到它(当然,这是因为查询SHOW TAG VALUES WITH KEY = \"group\" WHERE \"category\" =~ /$category/ 返回所有条目)。

所以我想获得一些最佳实践来解决这个问题。不幸的是,文档并没有帮助我:-(

4

1 回答 1

1

Grafana 不提供此类功能。我们实现这种情况的方式是在某些数据源(例如 SQL)中为每个实体配置用户访问权限,然后查询它以显示用户特定的类别/url/等。

可以根据用户的电子邮件/登录名/id 进行此配置,您只能在 Grafana v7.1+ 中将其“抓取”为变量:

  • ${__user.id} 是当前用户的 ID
  • ${__user.login} 是当前用户的登录句柄
  • ${__user.email} 是当前用户的电子邮件

参考: https ://grafana.com/docs/grafana/latest/variables/variable-types/global-variables/#__user

于 2021-01-22T15:21:18.960 回答