带有石墨的 grafana 仪表板

Posted

技术标签:

【中文标题】带有石墨的 grafana 仪表板【英文标题】:grafana dashboard with graphite 【发布时间】:2014-11-08 07:05:23 【问题描述】:

我无法让 grafana 从石墨中获取指标。似乎错误来自石墨本身,需要graphite-api

我是否绝对需要安装并运行 graphite-api 才能完成这项工作?

感谢您的帮助。

使用 curl 我可以获得所有指标树,但浏览器仍然给我一个指标查询失败错误。也许我应该在这里复制并粘贴我的所有配置。

石墨 nginx 配置:

server 
listen     443;
ssl on;
ssl_certificate /etc/pki/tls/certs/dev.mydomain.net.crt;
ssl_certificate_key /etc/pki/tls/certs/dev.mydomain.net.key;

server_name  graphite.mydomain.net;

#charset koi8-r;
rewrite_log off;
access_log  /srv/www/graphite/access.log  main;
error_log   /srv/www/graphite/error.log debug;

# Proxy to Uchiwa on localhost:3000
#
location / 
    proxy_pass http://graphite:8000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;

    if ($http_origin ~*  "^http://metro.mydomain.net:80$")
    set $cors "true";
           
    if ($request_method = 'OPTIONS') 
    set $cors "$corsoptions";  
    

    if ($request_method = 'GET') 
    set $cors "$corsget";  
    

    if ($request_method = 'POST') 
    set $cors "$corspost";
    

    if ($cors = 'true') 
    add_header  "Access-Control-Allow-Origin" "$http_origin";
    add_header  "Access-Control-Allow-Credentials" "true";
    add_header  "Access-Control-Allow-Methods" "GET, POST, OPTIONS";
    add_header  "Access-Control-Allow-Headers" "Authorization, origin, accept";
    

    if ($cors = "trueoptions") 
    add_header 'Access-Control-Allow-Origin' "$http_origin";
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Type' 'text/plain charset=UTF-8';
    add_header 'Content-Length' 0;

    return 204;
    

    if ($cors = "truepost") 
    add_header 'Access-Control-Allow-Origin' "$http_origin";
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    

    if ($cors = "trueget") 
    add_header 'Access-Control-Allow-Origin' "$http_origin";
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    


  

grafana nginx 配置:

server 
#listen     443;
listen     80;
#ssl on;
#ssl_certificate /etc/pki/tls/certs/dev.mydomain.net.crt;
#ssl_certificate_key /etc/pki/tls/certs/dev.mydomain.net.key;

server_name  metro.mydomain.net;
root   /var/www/html/grafana;
index index.html
client_max_body_size 30M;

#charset koi8-r;
rewrite_log off;
access_log  /var/www/html/grafana.access.log  main;
error_log   /var/www/html/grafana.error.log debug;

grafana config.js:

   // Graphite & Elasticsearch example setup
   datasources: 
  graphite: 
    default: true,
    type: 'graphite',
    url:  "http://graphite.mydomain.net:8000",
    render_method: 'GET',
  ,
 /* elasticsearch: 
    type: 'elasticsearch',
    url: "http://my.elastic.server.com:9200",
    index: 'grafana-dash',
    grafanaDB: true,
  */
,

我无法在此处复制和粘贴日志,因为它们包含链接,并且该网站告诉我我应该至少有 10 个声誉才能发布超过 2 个链接。虽然它们不是真正的链接,只是我服务器上的 url,我不知道如何将它们转换为纯文本以便我可以发布。然后我必须删除所有日志消息才能编辑我的问题。

请帮帮我????

谢谢。

问候

【问题讨论】:

【参考方案1】:

我没有更新帖子。我成功地用graphite-web设置了我的grafana ui。问题是无法通过 js 使用跨域,而且我的浏览器(客户端)与我的 grafana/graphite 不在同一台机器上。 我所做的是将 grafana url 本身放入 config.js 的数据源中,并将其在本地重定向到我的本地石墨域。这是我的 nginx 和 grafana/graphite 配置:

石墨 nginx 配置:

server 
listen     443;
ssl on;
ssl_certificate /etc/pki/tls/certs/dev.mydomain.net.crt; 
ssl_certificate_key /etc/pki/tls/certs/dev.mydomain.net.key;

server_name  graphite.mydomain.net;

#charset koi8-r;
rewrite_log off;
access_log  /srv/www/graphite/access.log  main;
error_log   /srv/www/graphite/error.log debug;

#
location / 
proxy_pass http://graphite:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;

if ($http_origin ~*  "^https://metro.mydomain.net:443$")
set $cors "true";
       
if ($request_method = 'OPTIONS') 
set $cors "$corsoptions";  


if ($request_method = 'GET') 
set $cors "$corsget";  


if ($request_method = 'POST') 
set $cors "$corspost";


if ($cors = 'true') 
add_header  "Access-Control-Allow-Origin" "$http_origin";
add_header  "Access-Control-Allow-Credentials" "true";
add_header  "Access-Control-Allow-Methods" "GET, POST, OPTIONS";
add_header  "Access-Control-Allow-Headers" "Authorization, origin, accept";


if ($cors = "trueoptions") 
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;

return 204;


if ($cors = "truepost") 
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';


if ($cors = "trueget") 
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
     
   

grafana nginx 配置:

server 
listen     443;
ssl on;
ssl_certificate /etc/pki/tls/certs/dev.mydomain.net.crt;
ssl_certificate_key /etc/pki/tls/certs/dev.mydomain.net.key;

server_name  metro.mydomain.net;
root   /var/www/html/grafana;
index index.html
client_max_body_size 30M;

#charset koi8-r;
rewrite_log off;
access_log  /var/www/html/grafana.access.log  main;
error_log   /var/www/html/grafana.error.log debug;

location /render 
    proxy_pass http://graphite:8000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";

location /metric 
    proxy_pass http://graphite:8000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  

grafana config.js:

 // Graphite & Elasticsearch example setup
 datasources: 
 graphite: 
 default: true,
 type: 'graphite',
 url:  "https://metro.mydomain.net",
 render_method: 'GET',
,
/* elasticsearch: 
type: 'elasticsearch',
url: "http://my.elastic.server.com:9200",
index: 'grafana-dash',
grafanaDB: true,
  */
 ,

请注意,在这里,我可以将我的 URL 中的石墨替换为 localhost,它仍然可以工作。

现在我可以创建和保存我的图表

希望这将帮助其他面临 grafana 设置的人。

问候,

【讨论】:

以上是关于带有石墨的 grafana 仪表板的主要内容,如果未能解决你的问题,请参考以下文章

grafana 上的脚本仪表板

如何以 json 或任何其他格式访问 Graphite RAW 数据?

如何在 Jsonnet 中为 Grafana 仪表板模板填充变量

Grafana Loki 的 Java 客户端库

Grafana 仪表板使用 TDengine 显示数据库名称错误

如何描述显示 systemd 单位的 grafana 仪表板