3

以下命令按预期返回指标:

curl " http://graphite.metrics:8080/metrics/find?format=completer&query=server *.cache"

{"metrics": [
  {"is_leaf": "1", "path": "server1200.cache", "name": "cache"},
  {"is_leaf": "1", "path": "server1201.cache", "name": "cache"},
  {"is_leaf": "1", "path": "server1202.cache", "name": "cache"},
  {"is_leaf": "1", "path": "server1203.cache", "name": "cache"}, 
  {"is_leaf": "1", "path": "server1205.cache", "name": "cache"}
 ]
}

如果我使用 Cubism.js 尝试相同的查询,我会得到“无法找到指标”:

var context = cubism.context()
                    .serverDelay(60 * 1000) 
                    .step(60 * 1000)
                    .size(1440); 

var graphite = context.graphite("http://graphite.metrics:8080");  
graphite.find("metricXX*", function(error, results){
  alert(error);
});

如果 Cubism.js 在内部执行相同的请求,为什么找不到指标?

4

1 回答 1

4

毕竟这不是 Cubism.js 的错误。实际上,这是一个跨站点 HTTP 请求。

我在 Chrome 中启用了 Web Developer Extension 并注意到以下消息:

Access-Control-Allow-Origin 不允许来源

并修复了在 Node.js 中添加以下代码:

var server = http.createServer(function (req, res) {

  res.setHeader("Access-Control-Allow-Origin", "*");
  res.setHeader("Access-Control-Allow-Headers", "X-Requested-With");

  proxy.proxyRequest(req, res);
});
于 2012-12-20T15:22:41.357 回答