Code Monkey home page Code Monkey logo

es-monitor's Introduction

Gitter

A set of tools to query Elasticsearch with SQL

Tutorial in Chinese: https://segmentfault.com/a/1190000003502849

As Monitor Plugin

./plugin.sh https://url-to-params

The url points to a file with format:

  • first line: elasticsearch http url
  • remaining lines: sql

For example

http://es_hosts

SELECT count(*) AS value FROM gs_plutus_debug
    WHERE "timestamp" > now() - INTERVAL '5 minutes';
SAVE RESULT AS gs_plutus_debug.count;

SELECT count(*) AS value FROM gs_api_track
    WHERE "@timestamp" > now() - INTERVAL '5 minutes';
SAVE RESULT AS gs_api_track.count;

Basic authentication is supported

cat << EOF | python -m es_sql http://xxx:8000/
    VAR username=hello;
    VAR password=world;
    SELECT count(*) FROM my_index
EOF

Can also use SQL to query Elasticsearch cluster health stats

SELECT * FROM _cluster_health
SELECT * FROM _cluster_state
SELECT * FROM _cluster_stats
SELECT * FROM _cluster_pending_tasks
SELECT * FROM _cluster_reroute
SELECT * FROM _nodes_stats
SELECT * FROM _nodes_info
SELECT * FROM _indices_stats
SELECT * FROM _indices_stats.all
SELECT * FROM _indices_stats.[index_name]

The output will be a JSON array containing data points

As Console Command

For example

cat << EOF | python -m es_sql http://es_hosts
    SELECT "user", "oid", max("@timestamp") as value FROM gs_api_track_
    GROUP BY "user", "oid" WHERE "@timestamp" > 1454239084000
EOF

python -m es_sql can be es-sql if pip install es-sql

As Python Library

pip install es-sql
import es_sql
es_sql.execute_sql(
    'http://127.0.0.1:9200',
    'SELECT COUNT(*) FROM your_index WHERE field=%(param)s',
    arguments={'param': 'value'})

For more information: https://github.com/taowen/es-monitor/tree/master/es_sql

As HTTP Api

Start http server (gunicorn)

python -m explorer

Translate SQL to Elasticsearch DSL request

$ cat << EOF | curl -X POST -d @- http://127.0.0.1:8000/translate
SELECT * FROM quote WHERE symbol='AAPL'
EOF

{
  "data": {
    "indices": "quote*",
    "query": {
      "term": {
        "symbol": "AAPL"
      }
    }
  },
  "error": null
}

Use SQL to query Elasticsearch

$ cat << EOF | curl -X POST -d @- http://127.0.0.1:8000/search?elasticsearch=http://127.0.0.1:9200
SELECT COUNT(*) FROM quote WHERE symbol='AAPL'
EOF

{
  "data": {
    "result": [
      {
        "COUNT(*)": 8790
      }
    ]
  },
  "error": null
}

Use SQL with arguments

$ cat << EOF | curl -X POST -d @- http://127.0.0.1:8000/search_with_arguments
{
    "elasticsearch":"http://127.0.0.1:9200",
    "sql":"SELECT COUNT(*) FROM quote WHERE symbol=%(param1)s",
    "arguments":{"param1":"AAPL"}
}
EOF
{
  "data": {
    "result": [
      {
        "COUNT(*)": 8790
      }
    ]
  },
  "error": null
}

es-monitor's People

Contributors

taowen avatar yujinqiu 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  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  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  avatar

Watchers

 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

es-monitor's Issues

是否支持sum(a)/sum(b)

是否支持
seletc sum(a)/sum(b)
这种聚合后结果相除的sql表达式呢

我知道es的bucket_script应该可以写出来 但是不知道sql的方式是否可以
看中文文档例子里没有涉及

滴滴招聘资深工程师

工作地点:
北京市

岗位描述:

  1. 负责基础设施产品的研发工作,参与中间件产品架构设计;
  2. 负责产品的核心代码编写,负责子模块的架构设计,设计高可用、高性能的分布式中间件;
  3. 参与分布式缓存、消息队列、数据库中间件等其一的主要开发工作;

任职资格:

  1. 工作经验3年以上,2年的相关产品开发经验优先;
  2. 精通Linux下的C/C++/Java/Go开发,多线程、网络编程;
  3. 熟悉Redis/RocketMQ/Kafka/Cobar等开源项目源码优先;
  4. 有丰富性能优化和故障排查经验的优先;
  5. 有耐心,有一颗把基础设施服务化的决心

所属部门 基础平台部 章文嵩

[email protected]

不知是否感兴趣? @LiboDing @jakeslee @cooerson @iYUYUE @wwek @otbzi @cloudtrends @oulan @cwbhhjl @tcdona @zhiyue @temberature @summerwish @zoowii @shunix @jimbray @jumping @min520li @outofbound @crystoneme @pandyxu @caizixian @tclh123 @kyalipay @ultimate010 @lsw0794 @zhaochunqi @ProgramCaiCai @justinlm @xophiix @jun9 @keyeMyria @Xronger @duyamin @edisonh @wangjieest @lvyaojia @alexzhang2015 @zdj2006 @vincenttone @scientist2009 @eastlhu

2.0 版 解析 的sql有问题吧

cat << EOF | python -m es_sql http://xxxxxxxxxxxxxxxxx
SELECT shares_count, COUNT(*) FROM symbol GROUP BY floor(market_cap / last_sale / 1000000) AS shares_count ORDER BY shares_count LIMIT 3
EOF
解释成了这个:

{
  "aggs": {
    "shares_count": {
      "terms": {
        "size": 3, 
        "order": {
          "_key": "asc"
        }, 
        "script": {
          "lang": "expression", 
          "inline": "floor(doc['market_cap'].value / doc['last_sale'].value/1000000)"
        }
      }, 
      "aggs": {}
    }
  }, 
  "size": 0
}

应该是:

{
  "aggs": {
    "shares_count": {
      "terms": {
        "size": 3, 
        "order": {
          "_term": "asc"
        }, 
        "script": {
          "lang": "expression", 
          "inline": "floor(doc['market_cap'].value / doc['last_sale'].value / 1000000)"
        }
      }, 
      "aggs": {}
    }
  }, 
  "size": 0
} 

这个吧
问题在 order 那

setup question

python setup.py install
Traceback (most recent call last):
File "setup.py", line 35, in
include=('es_sql*', )
TypeError: find_packages() got an unexpected keyword argument 'include'

python -m explorer error

As HTTP Api Start http server (gunicorn) have some error:
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"main", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/hdfs/danier/project/es-monitor/explorer/main.py", line 14, in
'--error-logfile', 'log/error.log'] + sys.argv[1:])
TypeError: coercing to Unicode: need string or buffer, NoneType found

能支支持这样的计算吗

indices为这样的数据 zone code colo count
我想计算出每个zone code >400的数量 占每zone的总数的百分比
with all_data as (select zone, sum(count) t1 from dd group by zone)
with all_fail as (select zone,sum(count) t2 from dd where code > 400 group by zone )
select all_fail.t2 /all_data.t1 from all_data join all_fail on all_data.zone = all_fail.zone

我看好象是不支持这样的查询,求助

error in explorer-ui

➜ explorer-ui git:(master) npm run dev

explorer-ui@ dev /Users/langge/dev/test/java/es/es-monitor/explorer-ui
node build/dev-server.js

Listening at http://localhost:8080
webpack built 79bfc92743887b702f54 in 3711ms
Hash: 79bfc92743887b702f54
Version: webpack 1.14.0
Time: 3711ms
Asset Size Chunks Chunk Names
app.js 1.16 MB 0 app

ERROR in ./src/components/Query.vue

error semi Extra semicolon
/Users/langge/dev/test/java/es/es-monitor/explorer-ui/src/components/Query.vue:31:67
this.$set('response', JSON.stringify(response.data));
^

✖ 1 problem (1 error, 0 warnings)

Child html-webpack-plugin for "index.html":
Asset Size Chunks Chunk Names
index.html 1.47 MB 0
webpack: bundle is now VALID.

<<<<<<<<<<<<<<<<<<<<<<<<<<<
➜ explorer-ui git:(master) npm install
npm WARN [email protected] requires a peer of babel-runtime@^6.0.0 but none was installed.
➜ explorer-ui git:(master)

http://localhost:8080 was broken

Python URLAttrib2 error

Hi Taowen,

I am getting error while executing my code(Code is given below). I am using python 2.7. Please help me to solve the issue.

Code

import es_sql
test = es_sql.execute_sql('http://127.0.0.1:9200', 'select city from mtmaster where city = "Leon"')

Error:

Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/Practice/elasticsearch_sql.py", line 2, in
test = es_sql.execute_sql('http://127.0.0.1:9200', 'select city from mtmaster where city = "Leon"')
File "C:\Python27\lib\site-packages\es_sql\es_query.py", line 43, in execute_sql
result_map['result'] = create_executor(current_sql_selects, result_map).execute(es_url, arguments)
File "C:\Python27\lib\site-packages\es_sql\executors\select_from_leaf_executor.py", line 35, in execute
response = select_from_system.execute(es_url, self.sql_select) or search_es(url, self.request, arguments)
File "C:\Python27\lib\site-packages\es_sql\executors\select_from_leaf_executor.py", line 109, in search_es
resp = urllib2.urlopen(url, json.dumps(request)).read()
File "C:\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 435, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 548, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 473, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 407, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 556, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 406: Not Acceptable

Would be great to know if this might support Python 3?

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.