• Stars
    star
    262
  • Rank 155,302 (Top 4 %)
  • Language
    Python
  • Created over 8 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

query metric from elasticsearch using sql

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
}

More Repositories

1

awesome-lowcode

国内低代码平台从业者交流
13,236
star
2

modularization-examples

代码防腐实用技术
1,147
star
3

vite-howto

Modularization best practice to common web development scenarios, applies to vue/react/... any framework
TypeScript
171
star
4

12fallacy

打造杰出软件开发团队的12条指导建议
83
star
5

awesome-debugger

record & replay or time travel debugging
61
star
6

define-function

quick.js based eval
JavaScript
36
star
7

go-php7

bind php7 to go environment
Go
34
star
8

modern-cpp-howto

C++
28
star
9

toolchain

km of toolchain
Java
18
star
10

motrix

alternative reality
Go
17
star
11

learn-llama

my personal learning log
Python
14
star
12

vue-component-preview

preview individual vue component without running the full application
Vue
14
star
13

awesome-html

collection of "html over the wire" libraries
12
star
14

vite-ioc-demo

Inversion of Control (IoC) via vite in build time, a simple yet powerful way to modularize code
TypeScript
10
star
15

tsdb-book

9
star
16

repo-to-prompt

combine source code files into single prompt to chat with your repository
JavaScript
8
star
17

sslcode

start a https protected coding environment
JavaScript
7
star
18

vue-db

Get rid of as many mutable states as possible
TypeScript
5
star
19

daili

proxy based on java kilim coroutine
Java
4
star
20

vue-fusion

微信小程序的 SSR / OTA / HMR 解决方案,用熟悉的 Vue + TSX 写界面
TypeScript
3
star
21

readable

examples of readable code
Java
3
star
22

lambdafs

apply a lambda on your file system
Go
3
star
23

colorfour

real world business process modeling
Go
3
star
24

bayberry

Complement test frameworks with dependency injection, data injection and test helpers
Java
3
star
25

pythonic-modern-cpp

Collection of modern c++ code examples for python developers
C++
3
star
26

go-libc

intercept libc networking call to golang netpoller
C
2
star
27

emscripten-howto

demo emscripten usage
JavaScript
2
star
28

refactor-by-example

TypeScript
2
star
29

gatsby-starter-netlify-cms

JavaScript
1
star
30

wasm3.js

compile wasm3 using emscripten
C
1
star
31

react-sui-l0vyg3uq

Technology Sample you can rely on to build your own Design System, based on React and a System UI theme (Theme UI | styled-components).
TypeScript
1
star
32

game-of-life

Go
1
star
33

awesome-bayesian-approximation

algorithms to approximate the likelihood function in situations where its analytic form is intractable
1
star
34

incremental-html

update ui incrementally with html
TypeScript
1
star