0
votes

I'm having problem to make grafana get metrics from graphite. It seems like the error comes from graphite itself, which need graphite-api.

Do I absolutely need graphite-api installed and running to have this work?

Thank you for your help.

With curl I can get all my metrics tree, but the browser still give me a metrics query failed error. May be I should copy and paste all my configurations here.

graphite nginx conf :

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 "${cors}options";  
    }

    if ($request_method = 'GET') {
    set $cors "${cors}get";  
    }

    if ($request_method = 'POST') {
    set $cors "${cors}post";
    }

    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 conf :

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,
  }*/
},

I can't copy and paste logs here, cause they contain links, and the site is telling me I should have at least 10 reputations to post more than 2 links. While they are not real links, just urls on my server, and I don't know how to convert them in plain text so that I can post. Then I was obliged to remove all log messages in order to edit my question.

Please help me????

Thanks.

Regards

1

1 Answers

1
votes

I didn't update the post. I succeeded to set up my grafana ui with graphite-web. The problem was that it's not possible to use cross domain with js and my browser (client) is not on the same machine as my grafana/graphite. What I did is to put the grafana url itself in datasources of config.js, and redirect it locally to my local graphite domain. This is my nginx and grafana/graphite configuration :

graphite nginx conf :

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 "${cors}options";  
}

if ($request_method = 'GET') {
set $cors "${cors}get";  
}

if ($request_method = 'POST') {
set $cors "${cors}post";
}

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 conf :

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,
  }*/
 },

Note that here, I could have graphite can be replace in my URLs by localhost and it will still work.

Now I can create and save my graphs

Hope this will help other people facing with grafana set up.

Regards,