GithubHelp home page GithubHelp logo

query's Introduction

Introduction

Query面向终端用户,收到查询请求后,根据一致性哈希算法,会去相应的Graph里面,查询不同metric的数据,汇总后统一返回给用户。

查询历史数据

查询过去一段时间内的历史数据,使用接口 HTTP POST /graph/history。该接口不能查询最新上报的两个数据点。一个python例子,如下

#!-*- coding:utf8 -*-

import requests
import time
import json

end = int(time.time())
start = end - 3600  #查询过去一小时的数据

d = {
        "start": start,
        "end": end,
        "cf": "AVERAGE",
        "endpoint_counters": [
            {
                "endpoint": "host1",
                "counter": "cpu.idle",
            },
            {
                "endpoint": "host1",
                "counter": "load.1min",
            },
        ],
}

url = "http://127.0.0.1:9966/graph/history"
r = requests.post(url, data=json.dumps(d))
print r.text

其中cf的值可以为:AVERAGE、MAX、MIN ,具体可以参考RRDtool的相关概念

查询最新上报的数据

查询最新上报的一个数据点,使用接口HTTP POST /graph/last。一个bash的例子,如下

#!/bin/bash
if [ $# != 2 ];then
    printf "format:./last \"endpoint\" \"counter\"\n"
    exit 1
fi

# args
endpoint=$1
counter=$2

# form request body
req="[{\"endpoint\":\"$endpoint\", \"counter\":\"$counter\"}]"

# request 
url="http://127.0.0.1:9966/graph/last"
curl -s -X POST -d "$req" "$url" | python -m json.tool

源码编译

注意: 请首先更新common模块

# download source
cd $GOPATH/src/github.com/open-falcon
git clone https://github.com/open-falcon/query.git # or use git pull to update query

# update dependencies: open-falcon/common, toolkits/consistent, toolkits/pool
cd query
go get ./...

# compile and pack
./control build
./control pack

最后一步会pack出一个tar.gz的安装包,拿着这个包去部署服务即可。你也可以在这里,下载最新发布的代码。

服务部署

服务部署,包括配置修改、启动服务、检验服务、停止服务等。这之前,需要将安装包解压到服务的部署目录下。

# 修改配置, 配置项含义见下文, 注意graph集群的配置
mv cfg.example.json cfg.json
vim cfg.json
# 注意: 从v1.4.0开始, 我们把graph列表的配置信息,移动到了cfg.json中,不再需要graph_backends.txt

# 启动服务
./control start

# 校验服务,这里假定服务开启了9966的http监听端口。检验结果为ok表明服务正常启动。
curl -s "127.0.0.1:9966/health"

...
# 停止服务
./control stop

服务启动后,可以通过日志查看服务的运行状态,日志文件地址为./var/app.log。可以通过./test/debug,查看服务的内部状态数据。可以通过scripts下的query last等脚本,进行数据查询。

配置文件格式说明

注意: 配置文件格式有更新; 请确保 graph.replicasgraph.cluster 的内容与transfer的配置完全一致

{
    "debug": "false",   // 是否开启debug日志
    "http": {
        "enabled":  true,          // 是否开启http.server
        "listen":   "0.0.0.0:9966" // http.server监听地址&端口
    },
    "graph": {
        "connTimeout": 1000, // 单位是毫秒,与后端graph建立连接的超时时间,可以根据网络质量微调,建议保持默认
        "callTimeout": 5000, // 单位是毫秒,从后端graph读取数据的超时时间,可以根据网络质量微调,建议保持默认
        "maxConns": 32,      // 连接池相关配置,最大连接数,建议保持默认
        "maxIdle": 32,       // 连接池相关配置,最大空闲连接数,建议保持默认
        "replicas": 500,     // 这是一致性hash算法需要的节点副本数量,应该与transfer配置保持一致
        "cluster": {         // 后端的graph列表,应该与transfer配置保持一致;不支持一条记录中配置两个地址
            "graph-00": "test.hostname01:6070",
            "graph-01": "test.hostname02:6070"
        },
        "api": {  // 适配grafana需要的API配置
            "query": "http://127.0.0.1:9966",     // query的http地址
            "dashboard": "http://127.0.0.1:8081", // dashboard的http地址
            "max": 500                            //API返回结果的最大数量
        }
    }
}

补充说明

部署完成query组件后,请修改dashboard组件的配置、使其能够正确寻址到query组件。请确保query组件的graph列表 与 transfer的配置 一致。

query's People

Contributors

hitripod avatar laiwei avatar niean avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

query's Issues

http/grafana.go 存在bug

http/grafana.go 中 以下代码条件应该写反了
if strings.Index(g.Config().Api.Query, req.Host) >= 0 {

grafana调用query api报错

query 版本号:1.4.3 ea558f8
grafana版本号:Version 3.0.4 (commit: v3.0.4)
grafana falcon plugin版本号:1.0.0

错误截图:
11

query配置文件截图:
11

请告知下我哪个环节配置有问题,非常感谢。

Cannot read property 'length' of null

我们配置好了grafana + open-falcon 的dashboard,但是在选择时间的时候出现了“Cannot
read property 'length' of null”的错误,只有在最近3个小时到24小时是有数据,其他时间就提示这样的错误。
image
image

grafana 模版变量定义不生效

我用falcon grafana的时候定义一个模版变量, port
thread#active#count/jmxport=[[port]]
在使用的时候发现port替换到falcon的表达式为jmxport={21071,21097}'),拿不到数据
我替换成 jmxport=(21906|21083)') 这个后能正常
大神能帮忙看看么

配置查询结果时间间隔

存数据时 step 设为 30; 查 6 小时内数据, 默认 timestamp 间隔是 30s, 12 小时内数据, timestamp 间隔变为了 150s, 跨度略大. 请问此参数有办法配置么?

centos7 安装query遇到错误,望回复

[work@iZ236uv37bdZ query]$ ./control start
start ok, pid=12969
[work@iZ236uv37bdZ query]$ ./control tail
2016/04/20 16:04:18 g.ParseConfig ok, file cfg.json
2016/04/20 16:04:18 proc.Start, ok
2016/04/20 16:04:18 graph.Start ok
2016/04/20 16:04:18 http.Start warning, not enabled
fatal error: all goroutines are asleep - deadlock!

goroutine 1 [select (no cases)]:
main.main()
/home/work/workspace/src/github.com/of-release/query/main.go:40 +0x36d

grafana 添加 falcon源,报 bad gateway

根据https://book.open-falcon.org/zh/dev/support_grafana.html 配置 grafana 的open-falcon源,报bad gateway。

query : 1.4.3
配置:

{
"debug": "false",
"http": {
"enabled": true,
"listen": "0.0.0.0:9966"
},
"graph": {
"connTimeout": 10000,
"callTimeout": 50000,
"maxConns": 32,
"maxIdle": 32,
"replicas": 500,
"cluster": {
"node-00": "172.16.5.44:6070"
}
},
"api": {
"query": "http://0.0.0.0:9966",
"dashboard": "http://0.0.0.0:8081",
"max": 500
}
}

grafana 的plugin配置参照官网:https://grafana.com/plugins/fastweb-openfalcon-datasource

错误信息截图:
qq 20170531184009

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.