├── .gitattributes
├── .gitignore
├── .jscsrc
├── .jshintrc
├── CHANGELOG.md
├── Gruntfile.js
├── LICENSE
├── README.md
├── crate-logo.png
├── dist
├── README.md
├── config_ctrl.d.ts
├── config_ctrl.js
├── config_ctrl.js.map
├── config_ctrl.ts
├── datasource.d.ts
├── datasource.js
├── datasource.js.map
├── datasource.ts
├── img
│ ├── crate-datasource-add-src.png
│ ├── crate-datasource-error.png
│ ├── crate-datasource-graph.png
│ ├── crate-datasource-nonvalidation.png
│ └── crate_logo.png
├── module.d.ts
├── module.js
├── module.js.map
├── module.ts
├── partials
│ ├── config.html
│ ├── query.editor.html
│ └── query.options.html
├── plugin.json
├── query_builder.d.ts
├── query_builder.js
├── query_builder.js.map
├── query_builder.ts
├── query_ctrl.d.ts
├── query_ctrl.js
├── query_ctrl.js.map
├── query_ctrl.ts
├── query_def.d.ts
├── query_def.js
├── query_def.js.map
├── query_def.ts
├── response_handler.d.ts
├── response_handler.js
├── response_handler.js.map
├── response_handler.ts
└── sdk
│ ├── query_ctrl.d.ts
│ ├── query_ctrl.js
│ ├── query_ctrl.js.map
│ ├── query_ctrl.ts
│ ├── sdk.d.ts
│ ├── sdk.js
│ ├── sdk.js.map
│ └── sdk.ts
├── headers
├── common.d.ts
├── es6-shim
│ └── es6-shim.d.ts
├── mocha
│ └── mocha.d.ts
└── zone
│ └── zone.d.ts
├── package.json
├── src
├── config_ctrl.ts
├── datasource.ts
├── img
│ ├── crate-datasource-add-src.png
│ ├── crate-datasource-error.png
│ ├── crate-datasource-graph.png
│ ├── crate-datasource-nonvalidation.png
│ └── crate_logo.png
├── module.ts
├── partials
│ ├── config.html
│ ├── query.editor.html
│ └── query.options.html
├── plugin.json
├── query_builder.ts
├── query_ctrl.ts
├── query_def.ts
├── response_handler.ts
├── sdk
│ ├── query_ctrl.ts
│ └── sdk.ts
└── spec
│ ├── datasource_specs.js
│ ├── query_builder_specs.js
│ ├── response_handler_specs.js
│ └── test-main.js
├── tsconfig.json
├── tsd.json
└── tslint.json
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Don't diff files in dist/
2 | *.map binary
3 | dist/** binary
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | npm-debug.log
3 | coverage/
4 | .aws-config.json
5 | awsconfig
6 | /emails/dist
7 | /public_gen
8 | /tmp
9 | vendor/phantomjs/phantomjs
10 |
11 | # Builded dist
12 | # /dist
13 |
14 | # Test artifacts
15 | /dist/test
16 | /dist/spec
17 |
18 | docs/AWS_S3_BUCKET
19 | docs/GIT_BRANCH
20 | docs/VERSION
21 | docs/GITCOMMIT
22 | docs/changed-files
23 | docs/changed-files
24 |
25 | # locally required config files
26 | public/css/*.min.css
27 |
28 | # Editor junk
29 | *.sublime-workspace
30 | *.sublime-project
31 | *.swp
32 | .idea/
33 | *.iml
34 |
35 | /data/*
36 | /bin/*
37 |
38 | conf/custom.ini
39 | fig.yml
40 | profile.cov
41 | grafana
42 | .notouch
43 |
--------------------------------------------------------------------------------
/.jscsrc:
--------------------------------------------------------------------------------
1 | {
2 | "disallowImplicitTypeConversion": ["string"],
3 | "disallowKeywords": ["with"],
4 | "disallowMultipleLineBreaks": true,
5 | "disallowMixedSpacesAndTabs": true,
6 | "disallowTrailingWhitespace": true,
7 | "requireSpacesInFunctionExpression": {
8 | "beforeOpeningCurlyBrace": true
9 | },
10 | "disallowSpacesInsideArrayBrackets": true,
11 | "disallowSpacesInsideParentheses": true,
12 | "validateIndentation": 2
13 | }
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "browser": true,
3 |
4 | "bitwise":false,
5 | "curly": true,
6 | "eqnull": true,
7 | "strict": true,
8 | "module": true,
9 | "devel": true,
10 | "eqeqeq": true,
11 | "forin": false,
12 | "immed": true,
13 | "supernew": true,
14 | "expr": true,
15 | "indent": 2,
16 | "latedef": false,
17 | "newcap": true,
18 | "noarg": true,
19 | "noempty": true,
20 | "undef": true,
21 | "boss": true,
22 | "trailing": true,
23 | "laxbreak": true,
24 | "laxcomma": true,
25 | "sub": true,
26 | "unused": true,
27 | "maxdepth": 6,
28 | "maxlen": 140,
29 | "esnext": true,
30 |
31 | "globals": {
32 | "System": true,
33 | "Promise": true,
34 | "define": true,
35 | "require": true,
36 | "Chromath": false,
37 | "setImmediate": true,
38 | "expect": true,
39 | "it": true,
40 | "describe": true,
41 | "sinon": true,
42 | "module": true,
43 | "beforeEach": true,
44 | "inject": true
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 |
4 | ## [Unreleased]
5 |
6 |
7 | ## [0.5.1] - 2017-04-05
8 | ### Changed
9 | - Use date_trunk() when interval set to second, minute, etc
10 | - Override limit only for Raw agg queries.
11 |
12 |
13 | ## [0.5.0] - 2017-03-22
14 | ### Added
15 | - Checks schema and table (prevent queries to different source).
16 |
17 |
18 | ## [0.4.0] - 2017-03-19
19 | ### Added
20 | - 'Auto' (uses date_trunk()) and 'Auto (Grafana)' (uses floor()) time intervals.
21 |
22 | ### Fixed
23 | - 10K issue
24 |
25 | ### Changed
26 | - Use explicit aggregation by time interval based on floor() instead date_trunk()
27 |
28 | ## [0.3.0] - 2017-03-02
29 | ### Added
30 | - Table mode support
31 | - Ad-hoc filters support
32 | - $timeFilter variable support
33 | - Quote column names with capital letters [#28](https://github.com/raintank/crate-datasource/issues/28)
34 | - Support GROUP BY in raw queries, issue [#30](https://github.com/raintank/crate-datasource/issues/30)
35 |
36 | ### Fixed
37 | - Schema queries (changed in Crate 1.0)
38 |
39 |
40 | ## [0.2.0] - 2016-11-29
41 | ### Added
42 | - Special "Raw" aggregation type [#9](https://github.com/raintank/crate-datasource/issues/9)
43 | - Alias for each field in SELECT
44 |
45 |
46 | ## [0.1.0] - 2016-07-10
47 | - Initial release
48 | - Implementation by [raintank](http://raintank.io)
49 | - Documentation contributions from [Crate.io](https://crate.io)
50 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | module.exports = function(grunt) {
2 |
3 | require('load-grunt-tasks')(grunt);
4 |
5 | grunt.loadNpmTasks('grunt-execute');
6 | grunt.loadNpmTasks('grunt-contrib-clean');
7 |
8 | grunt.initConfig({
9 |
10 | clean: ["dist"],
11 |
12 | copy: {
13 | src_to_dist: {
14 | cwd: 'src',
15 | expand: true,
16 | src: ['**/*', '!**/*.js', '!**/*.scss'],
17 | dest: 'dist'
18 | },
19 | pluginDef: {
20 | expand: true,
21 | src: ['README.md'],
22 | dest: 'dist'
23 | }
24 | },
25 |
26 | watch: {
27 | rebuild_all: {
28 | files: ['src/**/*'],
29 | tasks: ['watch-ts'],
30 | options: {spawn: false}
31 | }
32 | },
33 |
34 | typescript: {
35 | build: {
36 | src: ['dist/**/*.ts', "!src/spec/**/*", "!**/*.d.ts"],
37 | dest: 'dist/',
38 | options: {
39 | module: 'system', //or commonjs
40 | target: 'es3', //or es5
41 | rootDir: 'dist/',
42 | keepDirectoryHierarchy: false,
43 | declaration: true,
44 | emitDecoratorMetadata: true,
45 | experimentalDecorators: true,
46 | sourceMap: true,
47 | noImplicitAny: false,
48 | }
49 | },
50 | distTests: {
51 | src: ['src/**/*.ts', "!src/spec/**/*", "!**/*.d.ts"],
52 | dest: 'dist/test/',
53 | options: {
54 | module: 'commonjs', //or commonjs
55 | target: 'es5', //or es5
56 | rootDir: 'src/',
57 | sourceRoot: 'src/',
58 | declaration: true,
59 | emitDecoratorMetadata: true,
60 | experimentalDecorators: true,
61 | sourceMap: true,
62 | noImplicitAny: false,
63 | }
64 | },
65 | // distTestsSpecs: {
66 | // src: ['src/spec/**/*.ts'],
67 | // dest: 'dist/test/',
68 | // options: {
69 | // module: 'commonjs', //or commonjs
70 | // target: 'es5', //or es5
71 | // declaration: true,
72 | // emitDecoratorMetadata: true,
73 | // experimentalDecorators: true,
74 | // sourceMap: true,
75 | // noImplicitAny: false,
76 | // }
77 | // }
78 | },
79 |
80 | babel: {
81 | options: {
82 | sourceMap: true,
83 | presets: ['es2015']
84 | },
85 | distTestsSpecsNoSystemJs: {
86 | files: [{
87 | expand: true,
88 | cwd: 'src/spec',
89 | src: ['**/*.js'],
90 | dest: 'dist/test/spec',
91 | ext:'.js'
92 | }]
93 | }
94 | },
95 |
96 | mochaTest: {
97 | test: {
98 | options: {
99 | reporter: 'spec'
100 | },
101 | src: ['dist/test/spec/test-main.js', 'dist/test/spec/*_specs.js']
102 | }
103 | }
104 | });
105 |
106 | grunt.registerTask('default', [
107 | 'clean',
108 | 'copy',
109 | 'typescript:build',
110 | 'typescript:distTests',
111 | 'babel',
112 | 'mochaTest'
113 | ]);
114 |
115 | grunt.registerTask('watch-ts', [
116 | 'clean',
117 | 'copy:src_to_dist',
118 | 'copy:pluginDef',
119 | 'typescript:build'
120 | ]);
121 | };
122 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Grafana Data Source Plugin for CrateDB
2 |
3 | [](https://crate.io)
4 |
5 |
6 | ## What Is CrateDB?
7 | CrateDB is a SQL database that makes it simple to store and analyze
8 | massive amounts of machine data in real-time. CrateDB customers have
9 | reported improving predictive analytic query performance of machine
10 | data by 20x more than MySQL, while reducing database hardware costs by
11 | 75%.
12 |
13 | Here’s how CrateDB makes this possible:
14 |
15 | - **Combining SQL & Search** into a single DBMS - allowing you to process any data structure...time series, geospatial, JSON, full-text, etc.
16 | - **Distributed query innovations** - that deliver real-time SQL performance
17 | - **An auto-scaling architecture** - grow CrateDB with less DBA expertise
18 | - **Dynamic schemas, adhoc queries** - quickly adapt to data structure changes
19 |
20 | For these reasons and more, CrateDB is your perfect datasource for Grafana.
21 |
22 | ## The CrateDB Datasource Plugin for Grafana
23 |
24 | ### Features
25 | Enables CrateDB clusters to act as data sources for your Grafana deployment, providing real-time analytical and time-series data with SQL.
26 |
27 | ### Requirements
28 | - **Grafana** > 3.x.x
29 | - **CrateDB** - All stable versions are supported by this plugin
30 |
31 | ### Setup
32 | 
33 |
34 | > The screenshot shows a connection to http://localhost:44200 which is a test database for the purpose of this tutorial. CrateDB's default binding is to http://localhost:4200.
35 |
36 | 1. Click on the Grafana icon on the top left.
37 | 2. After the menu opened, you should see a link `Data Sources` below `Dashboards`.
38 | 3. Click `+ Add data source`.
39 | 4. Select `CrateDB` from the 'Type' dropdown.
40 |
41 | #### Cross-origin Resource Sharing (CORS)
42 |
43 | CrateDB supports [cross-origin resource sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) and if Grafana is running on a different origin (e.g. another domain), it is required to configure CrateDB accordingly. For example by this is the minimum required configuration in your `crate.yml`:
44 | ```
45 | http.cors.enabled: true
46 | http.cors.allow-origin: "http://mydomain.com"
47 | ```
48 | > Replace http://mydomain.com with the domain Grafana is running on, or use a "*" if it's OK to allow any domain to access CrateDB
49 |
50 | For further options look in [CrateDB's documentation](https://crate.io/docs/reference/en/latest/configuration.html#cross-origin-resource-sharing-cors)
51 |
52 | #### The CrateDB Data Source
53 |
54 | Name | Description
55 | ------------ | -------------
56 | Name | The data source name.
57 | Default | Set this data source as default for new panels.
58 |
59 | ##### HTTP Settings
60 |
61 | Name | Description
62 | ------------ | -------------
63 | Url | The URI to any node in your CrateDB cluster.
64 | Access | Via Grafana backend (proxy) or directly from the browser (direct).
65 | Basic Auth | Enable basic authentication (only available via NGINX proxy in CrateDB).
66 | User | Not available in CrateDB.
67 | Password | Not available in CrateDB.
68 |
69 | ##### CrateDB Details
70 |
71 | These are specific settings for the CrateDB data source and it's required to set a fixed `schema`, `table`, and time series column per data source.
72 |
73 | Name | Description
74 | ------------ | -------------
75 | Schema | CrateDB schema to query from (defaults to `doc`).
76 | Table | Table to retrieve the data from. Has to be available in the previously defined schema.
77 | Time Column | Time series column, has to be of type `timestamp` in CrateDB.
78 | Default grouping interval | The grouping resolution (can be changed by query).
79 |
80 | 
81 |
82 | > Grafana will not check (yet) if the `time column`, the `schema`, or the `table` exists. Be sure to double check these values to avoid running into problems later.
83 |
84 | ### Querying CrateDB
85 |
86 | After adding a new dashboard and having the query editor open, define and run the queries you like - it's just like other SQL databases. For example we have added the [NYC yellow cab data set](http://www.nyc.gov/html/tlc/html/about/trip_record_data.shtml) in our cluster to show you something interesting!
87 |
88 | 
89 |
90 | > This graph shows the number of yellow cab pick ups between on a weekend in August 2013.
91 |
92 | ### Debugging Queries
93 |
94 | Grafana runs queries almost immediately after change and it will also auto-complete columns or previous values. However, sometimes queries might still be invalid and Grafana will then show a small exclamation mark in the top corner of the graph. Clicking on it will give you the error message.
95 |
96 | 
97 |
98 | The CrateDB data source for Grafana supports a great range of scalar functions and operators. To read more about them, install or scale a cluster, or even to contribute to Crate, please have a look at the [official Crate documentation](https://crate.io/docs)
99 |
100 | ### License
101 | - This plugins is made available under the terms of the [Apache License, Version 2.0](https://github.com/crate/crate-datasource/blob/master/LICENSE).
102 |
103 | ## Getting Help
104 |
105 | - Read the CrateDB documentation [here](https://crate.io/docs)
106 | - Issues with the Grafana plugin can be reported or discussed [here](https://github.com/raintank/crate-datasource/issues)
107 | - Issues with CrateDB can be reported or discussed [here](https://github.com/crate/crate/issues)
108 | - Join the CrateDB Community Slack channel [here](https://crate.io/docs/support/slackin/)
109 |
--------------------------------------------------------------------------------
/crate-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raintank/crate-datasource/81e4a2e9b7e0c000133de8533d2a14d01fd216e2/crate-logo.png
--------------------------------------------------------------------------------
/dist/README.md:
--------------------------------------------------------------------------------
1 | # Grafana Data Source Plugin for CrateDB
2 |
3 | [](https://crate.io)
4 |
5 |
6 | ## What Is CrateDB?
7 | CrateDB is a SQL database that makes it simple to store and analyze
8 | massive amounts of machine data in real-time. CrateDB customers have
9 | reported improving predictive analytic query performance of machine
10 | data by 20x more than MySQL, while reducing database hardware costs by
11 | 75%.
12 |
13 | Here’s how CrateDB makes this possible:
14 |
15 | - **Combining SQL & Search** into a single DBMS - allowing you to process any data structure...time series, geospatial, JSON, full-text, etc.
16 | - **Distributed query innovations** - that deliver real-time SQL performance
17 | - **An auto-scaling architecture** - grow CrateDB with less DBA expertise
18 | - **Dynamic schemas, adhoc queries** - quickly adapt to data structure changes
19 |
20 | For these reasons and more, CrateDB is your perfect datasource for Grafana.
21 |
22 | ## The CrateDB Datasource Plugin for Grafana
23 |
24 | ### Features
25 | Enables CrateDB clusters to act as data sources for your Grafana deployment, providing real-time analytical and time-series data with SQL.
26 |
27 | ### Requirements
28 | - **Grafana** > 3.x.x
29 | - **CrateDB** - All stable versions are supported by this plugin
30 |
31 | ### Setup
32 | 
33 |
34 | > The screenshot shows a connection to http://localhost:44200 which is a test database for the purpose of this tutorial. CrateDB's default binding is to http://localhost:4200.
35 |
36 | 1. Click on the Grafana icon on the top left.
37 | 2. After the menu opened, you should see a link `Data Sources` below `Dashboards`.
38 | 3. Click `+ Add data source`.
39 | 4. Select `CrateDB` from the 'Type' dropdown.
40 |
41 | #### Cross-origin Resource Sharing (CORS)
42 |
43 | CrateDB supports [cross-origin resource sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) and if Grafana is running on a different origin (e.g. another domain), it is required to configure CrateDB accordingly. For example by this is the minimum required configuration in your `crate.yml`:
44 | ```
45 | http.cors.enabled: true
46 | http.cors.allow-origin: "http://mydomain.com"
47 | ```
48 | > Replace http://mydomain.com with the domain Grafana is running on, or use a "*" if it's OK to allow any domain to access CrateDB
49 |
50 | For further options look in [CrateDB's documentation](https://crate.io/docs/reference/en/latest/configuration.html#cross-origin-resource-sharing-cors)
51 |
52 | #### The CrateDB Data Source
53 |
54 | Name | Description
55 | ------------ | -------------
56 | Name | The data source name.
57 | Default | Set this data source as default for new panels.
58 |
59 | ##### HTTP Settings
60 |
61 | Name | Description
62 | ------------ | -------------
63 | Url | The URI to any node in your CrateDB cluster.
64 | Access | Via Grafana backend (proxy) or directly from the browser (direct).
65 | Basic Auth | Enable basic authentication (only available via NGINX proxy in CrateDB).
66 | User | Not available in CrateDB.
67 | Password | Not available in CrateDB.
68 |
69 | ##### CrateDB Details
70 |
71 | These are specific settings for the CrateDB data source and it's required to set a fixed `schema`, `table`, and time series column per data source.
72 |
73 | Name | Description
74 | ------------ | -------------
75 | Schema | CrateDB schema to query from (defaults to `doc`).
76 | Table | Table to retrieve the data from. Has to be available in the previously defined schema.
77 | Time Column | Time series column, has to be of type `timestamp` in CrateDB.
78 | Default grouping interval | The grouping resolution (can be changed by query).
79 |
80 | 
81 |
82 | > Grafana will not check (yet) if the `time column`, the `schema`, or the `table` exists. Be sure to double check these values to avoid running into problems later.
83 |
84 | ### Querying CrateDB
85 |
86 | After adding a new dashboard and having the query editor open, define and run the queries you like - it's just like other SQL databases. For example we have added the [NYC yellow cab data set](http://www.nyc.gov/html/tlc/html/about/trip_record_data.shtml) in our cluster to show you something interesting!
87 |
88 | 
89 |
90 | > This graph shows the number of yellow cab pick ups between on a weekend in August 2013.
91 |
92 | ### Debugging Queries
93 |
94 | Grafana runs queries almost immediately after change and it will also auto-complete columns or previous values. However, sometimes queries might still be invalid and Grafana will then show a small exclamation mark in the top corner of the graph. Clicking on it will give you the error message.
95 |
96 | 
97 |
98 | The CrateDB data source for Grafana supports a great range of scalar functions and operators. To read more about them, install or scale a cluster, or even to contribute to Crate, please have a look at the [official Crate documentation](https://crate.io/docs)
99 |
100 | ### License
101 | - This plugins is made available under the terms of the [Apache License, Version 2.0](https://github.com/crate/crate-datasource/blob/master/LICENSE).
102 |
103 | ## Getting Help
104 |
105 | - Read the CrateDB documentation [here](https://crate.io/docs)
106 | - Issues with the Grafana plugin can be reported or discussed [here](https://github.com/raintank/crate-datasource/issues)
107 | - Issues with CrateDB can be reported or discussed [here](https://github.com/crate/crate/issues)
108 | - Join the CrateDB Community Slack channel [here](https://crate.io/docs/support/slackin/)
109 |
--------------------------------------------------------------------------------
/dist/config_ctrl.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | export declare class CrateConfigCtrl {
3 | static templateUrl: string;
4 | current: any;
5 | timeIntervals: any[];
6 | constructor($scope: any);
7 | }
8 |
--------------------------------------------------------------------------------
/dist/config_ctrl.js:
--------------------------------------------------------------------------------
1 | ///
2 | System.register([], function(exports_1) {
3 | var CrateConfigCtrl;
4 | return {
5 | setters:[],
6 | execute: function() {
7 | CrateConfigCtrl = (function () {
8 | function CrateConfigCtrl($scope) {
9 | this.timeIntervals = [
10 | { name: 'Auto', value: 'auto' },
11 | { name: 'Auto (Grafana)', value: 'auto_gf' },
12 | { name: 'Second', value: 'second' },
13 | { name: 'Minute', value: 'minute' },
14 | { name: 'Hour', value: 'hour' },
15 | { name: 'Day', value: 'day' },
16 | { name: 'Week', value: 'week' },
17 | { name: 'Month', value: 'month' },
18 | { name: 'Quarter', value: 'quarter' },
19 | { name: 'Year', value: 'year' }
20 | ];
21 | this.current.jsonData.timeInterval = this.current.jsonData.timeInterval || this.timeIntervals[1].value;
22 | }
23 | CrateConfigCtrl.templateUrl = 'partials/config.html';
24 | return CrateConfigCtrl;
25 | })();
26 | exports_1("CrateConfigCtrl", CrateConfigCtrl);
27 | }
28 | }
29 | });
30 | //# sourceMappingURL=config_ctrl.js.map
--------------------------------------------------------------------------------
/dist/config_ctrl.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"config_ctrl.js","sourceRoot":"","sources":["config_ctrl.ts"],"names":["CrateConfigCtrl","CrateConfigCtrl.constructor"],"mappings":"AAAA,8CAA8C;;;;;;YAK9C;gBAiBEA,yBAAYA,MAAMA;oBAblBC,kBAAaA,GAAUA;wBACrBA,EAACA,IAAIA,EAAEA,MAAMA,EAAKA,KAAKA,EAAEA,MAAMA,EAACA;wBAChCA,EAACA,IAAIA,EAAEA,gBAAgBA,EAAKA,KAAKA,EAAEA,SAASA,EAACA;wBAC7CA,EAACA,IAAIA,EAAEA,QAAQA,EAAGA,KAAKA,EAAEA,QAAQA,EAACA;wBAClCA,EAACA,IAAIA,EAAEA,QAAQA,EAAGA,KAAKA,EAAEA,QAAQA,EAACA;wBAClCA,EAACA,IAAIA,EAAEA,MAAMA,EAAKA,KAAKA,EAAEA,MAAMA,EAACA;wBAChCA,EAACA,IAAIA,EAAEA,KAAKA,EAAMA,KAAKA,EAAEA,KAAKA,EAACA;wBAC/BA,EAACA,IAAIA,EAAEA,MAAMA,EAAKA,KAAKA,EAAEA,MAAMA,EAACA;wBAChCA,EAACA,IAAIA,EAAEA,OAAOA,EAAIA,KAAKA,EAAEA,OAAOA,EAACA;wBACjCA,EAACA,IAAIA,EAAEA,SAASA,EAAEA,KAAKA,EAAEA,SAASA,EAACA;wBACnCA,EAACA,IAAIA,EAAEA,MAAMA,EAAKA,KAAKA,EAAEA,MAAMA,EAACA;qBACjCA,CAACA;oBAGAA,IAAIA,CAACA,OAAOA,CAACA,QAAQA,CAACA,YAAYA,GAAGA,IAAIA,CAACA,OAAOA,CAACA,QAAQA,CAACA,YAAYA,IAAIA,IAAIA,CAACA,aAAaA,CAACA,CAACA,CAACA,CAACA,KAAKA,CAACA;gBACzGA,CAACA;gBAlBMD,2BAAWA,GAAGA,sBAAsBA,CAACA;gBAmB9CA,sBAACA;YAADA,CAACA,AApBD,IAoBC;YApBD,6CAoBC,CAAA"}
--------------------------------------------------------------------------------
/dist/config_ctrl.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | import angular from 'angular';
4 | import _ from 'lodash';
5 |
6 | export class CrateConfigCtrl {
7 | static templateUrl = 'partials/config.html';
8 | current: any;
9 |
10 | timeIntervals: any[] = [
11 | {name: 'Auto', value: 'auto'},
12 | {name: 'Auto (Grafana)', value: 'auto_gf'},
13 | {name: 'Second', value: 'second'},
14 | {name: 'Minute', value: 'minute'},
15 | {name: 'Hour', value: 'hour'},
16 | {name: 'Day', value: 'day'},
17 | {name: 'Week', value: 'week'},
18 | {name: 'Month', value: 'month'},
19 | {name: 'Quarter', value: 'quarter'},
20 | {name: 'Year', value: 'year'}
21 | ];
22 |
23 | constructor($scope) {
24 | this.current.jsonData.timeInterval = this.current.jsonData.timeInterval || this.timeIntervals[1].value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/dist/datasource.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import { CrateQueryBuilder } from './query_builder';
3 | export declare class CrateDatasource {
4 | private $q;
5 | private backendSrv;
6 | private templateSrv;
7 | private timeSrv;
8 | type: string;
9 | url: string;
10 | name: string;
11 | basicAuth: string;
12 | withCredentials: boolean;
13 | schema: string;
14 | table: string;
15 | defaultTimeColumn: string;
16 | defaultGroupInterval: string;
17 | checkQuerySource: boolean;
18 | queryBuilder: CrateQueryBuilder;
19 | CRATE_ROWS_LIMIT: number;
20 | constructor(instanceSettings: any, $q: any, backendSrv: any, templateSrv: any, timeSrv: any);
21 | query(options: any): any;
22 | /**
23 | * Required.
24 | * Checks datasource and returns Crate cluster name and version or
25 | * error details.
26 | */
27 | testDatasource(): any;
28 | metricFindQuery(query: string): any;
29 | getTimeFilter(timeFrom: any, timeTo: any): string;
30 | getTagKeys(options: any): any;
31 | getTagValues(options: any): any;
32 | setScopedVars(scopedVars: any): any;
33 | /**
34 | * Sends SQL query to Crate and returns result.
35 | * @param {string} query SQL query string
36 | * @param {any[]} args Optional query arguments
37 | * @return
38 | */
39 | _sql_query(query: string, args?: any[]): any;
40 | checkSQLSource(query: any): void;
41 | _request(method: string, url: string, data?: any): any;
42 | _get(url?: string): any;
43 | _post(url: string, data?: any): any;
44 | }
45 | export declare function convertToCrateInterval(grafanaInterval: any): any;
46 |
--------------------------------------------------------------------------------
/dist/datasource.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"datasource.js","sourceRoot":"","sources":["datasource.ts"],"names":["formatCrateValue","wrapWithQuotes","convertToCrateInterval","crateToMsInterval","getMinCrateInterval","CrateDatasource","CrateDatasource.constructor","CrateDatasource.query","CrateDatasource.testDatasource","CrateDatasource.metricFindQuery","CrateDatasource.getTimeFilter","CrateDatasource.getTagKeys","CrateDatasource.getTagValues","CrateDatasource.setScopedVars","CrateDatasource._sql_query","CrateDatasource.checkSQLSource","CrateDatasource._request","CrateDatasource._get","CrateDatasource._post"],"mappings":"AAAA,8CAA8C;;;;IA0Q9C,qCAAqC;IACrC,0BAA0B,KAAK;QAC7BA,EAAEA,CAACA,CA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AACA,iBAAiBA,CAACA,GAAGA,IAAIA,CAACA;oBACpCA,CAACA;oBACDA,EAAEA,CAACA,CAACA,IAAIA,CAACA,SAASA,CAACA,CAACA,CAACA;wBACnBA,OAAOA,CAACA,OAAOA,CAACA,eAAeA,CAACA,GAAGA,IAAIA,CAACA,SAASA,CAACA;oBACpDA,CAACA;oBAEDA,MAAMA,CAACA,IAAIA,CAACA,UAAUA,CAACA,iBAAiBA,CAACA,OAAOA,CAACA;yBAChDA,IAAIA,CAACA,UAAAA,QAAQA;wBACZA,QAAQA,CAACA,IAAIA,CAACA,QAAQA,GAAGA,QAAQA,CAACA,MAAMA,CAACA;wBACzCA,QAAQA,CAACA,IAAIA,CAACA,QAAQA,GAAGA,QAAQA,CAACA,MAAMA,CAACA;wBACzCA,MAAMA,CAACA,QAAQA,CAACA,IAAIA,CAACA;oBACvBA,CAACA,CAACA,CAACA;gBACLA,CAACA;gBAEDX,8BAAIA,GAAJA,UAAKA,GAAQA;oBAARY,mBAAQA,GAARA,QAAQA;oBACXA,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA,KAAKA,EAAEA,GAAGA,CAACA,CAACA;gBACnCA,CAACA;gBAEDZ,+BAAKA,GAALA,UAAMA,GAAWA,EAAEA,IAAUA;oBAC3Ba,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA,MAAMA,EAAEA,GAAGA,EAAEA,IAAIA,CAACA,CAACA;gBAC1CA,CAACA;gBACHb,sBAACA;YAADA,CAACA,AAhQD,IAgQC;YAhQD,6CAgQC,CAAA"}
--------------------------------------------------------------------------------
/dist/datasource.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | import _ from 'lodash';
4 | import * as dateMath from 'app/core/utils/datemath';
5 | import moment from 'moment';
6 | import {CrateQueryBuilder, getEnabledAggs, getRawAggs, getNotRawAggs} from './query_builder';
7 | import handleResponse from './response_handler';
8 |
9 | export class CrateDatasource {
10 | type: string;
11 | url: string;
12 | name: string;
13 | basicAuth: string;
14 | withCredentials: boolean;
15 | schema: string;
16 | table: string;
17 | defaultTimeColumn: string;
18 | defaultGroupInterval: string;
19 | checkQuerySource: boolean;
20 | queryBuilder: CrateQueryBuilder;
21 | CRATE_ROWS_LIMIT: number;
22 |
23 |
24 | constructor(instanceSettings,
25 | private $q,
26 | private backendSrv,
27 | private templateSrv,
28 | private timeSrv) {
29 |
30 | this.type = instanceSettings.type;
31 | this.url = instanceSettings.url;
32 | this.name = instanceSettings.name;
33 | this.basicAuth = instanceSettings.basicAuth;
34 | this.withCredentials = instanceSettings.withCredentials;
35 | this.schema = instanceSettings.jsonData.schema;
36 | this.table = instanceSettings.jsonData.table;
37 | this.defaultTimeColumn = instanceSettings.jsonData.timeColumn;
38 | this.defaultGroupInterval = instanceSettings.jsonData.timeInterval;
39 | this.checkQuerySource = instanceSettings.jsonData.checkQuerySource;
40 |
41 | this.$q = $q;
42 | this.backendSrv = backendSrv;
43 | this.templateSrv = templateSrv;
44 | this.timeSrv = timeSrv;
45 |
46 | this.queryBuilder = new CrateQueryBuilder(this.schema,
47 | this.table,
48 | this.defaultTimeColumn,
49 | this.defaultGroupInterval,
50 | this.templateSrv);
51 |
52 | this.CRATE_ROWS_LIMIT = 10000;
53 | }
54 |
55 | // Called once per panel (graph)
56 | query(options) {
57 | let timeFrom = Math.ceil(dateMath.parse(options.range.from));
58 | let timeTo = Math.ceil(dateMath.parse(options.range.to));
59 | let timeFilter = this.getTimeFilter(timeFrom, timeTo);
60 | let scopedVars = this.setScopedVars(options.scopedVars);
61 |
62 | let queries = _.map(options.targets, target => {
63 | if (target.hide || (target.rawQuery && !target.query)) { return []; }
64 |
65 | let query: string;
66 | let rawAggQuery: string;
67 | let queryTarget, rawAggTarget;
68 | let getQuery: any;
69 | let getRawAggQuery: any;
70 | let getRawAggInterval: any;
71 | let adhocFilters = this.templateSrv.getAdhocFilters(this.name);
72 |
73 | if (target.rawQuery) {
74 | query = target.query;
75 | } else {
76 | let minInterval = Math.ceil((timeTo - timeFrom) / this.CRATE_ROWS_LIMIT);
77 | let maxLimit = timeTo - timeFrom;
78 | let interval;
79 |
80 | if (target.timeInterval === 'auto') {
81 | interval = getMinCrateInterval(options.intervalMs);
82 | } else if (target.timeInterval === 'auto_gf') {
83 | // Use intervalMs for panel, provided by Grafana
84 | interval = options.intervalMs;
85 | } else {
86 | interval = target.timeInterval;
87 | }
88 |
89 | // Split target into two queries (with aggs and raw data)
90 | query = this.queryBuilder.buildAggQuery(target, interval, adhocFilters);
91 | queryTarget = _.cloneDeep(target);
92 | queryTarget.metricAggs = getNotRawAggs(queryTarget.metricAggs);
93 |
94 | rawAggQuery = this.queryBuilder.buildRawAggQuery(target, 0, adhocFilters, maxLimit);
95 | rawAggQuery = this.templateSrv.replace(rawAggQuery, scopedVars, formatCrateValue);
96 | rawAggTarget = _.cloneDeep(target);
97 | rawAggTarget.metricAggs = getRawAggs(rawAggTarget.metricAggs);
98 | }
99 |
100 | query = this.templateSrv.replace(query, scopedVars, formatCrateValue);
101 |
102 | let queries = [
103 | {query: query, target: queryTarget},
104 | {query: rawAggQuery, target: rawAggTarget}
105 | ];
106 | queries = _.filter(queries, q => {
107 | return q.query;
108 | });
109 |
110 | return _.map(queries, q => {
111 | return this._sql_query(q.query, [timeFrom, timeTo])
112 | .then(result => {
113 | if (q.target) {
114 | return handleResponse(q.target, result);
115 | } else {
116 | return handleResponse(target, result);
117 | }
118 | });
119 | })
120 | });
121 | return this.$q.all(_.flattenDepth(queries, 2)).then(result => {
122 | return {
123 | data: _.flatten(result)
124 | };
125 | });
126 | }
127 |
128 | /**
129 | * Required.
130 | * Checks datasource and returns Crate cluster name and version or
131 | * error details.
132 | */
133 | testDatasource() {
134 | return this._get()
135 | .then(response => {
136 | if (response.$$status === 200) {
137 | return {
138 | status: "success",
139 | message: "Cluster: " + response.cluster_name +
140 | ", version: " + response.version.number,
141 | title: "Success"
142 | };
143 | }
144 | })
145 | .catch(error => {
146 | let message = error.statusText ? error.statusText + ': ' : '';
147 | if (error.data && error.data.error) {
148 | message += error.data.error;
149 | } else if (error.data) {
150 | message += error.data;
151 | } else {
152 | message = "Can't connect to Crate instance";
153 | }
154 | return {
155 | status: "error",
156 | message: message,
157 | title: "Error"
158 | };
159 | });
160 | }
161 |
162 | metricFindQuery(query: string) {
163 | if (!query) {
164 | return this.$q.when([]);
165 | }
166 |
167 | query = this.templateSrv.replace(query, null, formatCrateValue);
168 | return this._sql_query(query).then(result => {
169 | return _.map(_.flatten(result.rows), row => {
170 | return {
171 | text: row.toString(),
172 | value: row
173 | };
174 | });
175 | });
176 | }
177 |
178 | getTimeFilter(timeFrom, timeTo) {
179 | return this.defaultTimeColumn + " >= '" + timeFrom + "' and " + this.defaultTimeColumn + " <= '" + timeTo + "'";
180 | }
181 |
182 | getTagKeys(options) {
183 | let query = this.queryBuilder.getColumnsQuery();
184 | return this.metricFindQuery(query);
185 | }
186 |
187 | getTagValues(options) {
188 | let range = this.timeSrv.timeRange();
189 | let query = this.queryBuilder.getValuesQuery(options.key, this.CRATE_ROWS_LIMIT, range);
190 | return this.metricFindQuery(query);
191 | }
192 |
193 | setScopedVars(scopedVars) {
194 | scopedVars.crate_schema = {text: this.schema, value: `"${this.schema}"`};
195 | scopedVars.crate_table = {text: this.table, value: `"${this.table}"`};
196 |
197 | let crate_source = `"${this.schema}"."${this.table}"`;
198 | scopedVars.crate_source = {text: crate_source, value: crate_source};
199 |
200 | return scopedVars;
201 | }
202 |
203 | /**
204 | * Sends SQL query to Crate and returns result.
205 | * @param {string} query SQL query string
206 | * @param {any[]} args Optional query arguments
207 | * @return
208 | */
209 | _sql_query(query: string, args: any[] = []) {
210 | let data = {
211 | "stmt": query,
212 | "args": args
213 | };
214 |
215 | if (this.checkQuerySource) {
216 | // Checks schema and table and throw error if it different from configured in data source
217 | this.checkSQLSource(query);
218 | }
219 |
220 | return this._post('_sql', data);
221 | }
222 |
223 | checkSQLSource(query) {
224 | let source_pattern = /.*[Ff][Rr][Oo][Mm]\s"?([^\.\s\"]*)"?\.?"?([^\.\s\"]*)"?/;
225 | let match = query.match(source_pattern);
226 | let schema = match[1];
227 | let table = match[2];
228 | if (schema !== this.schema || table !== this.table) {
229 | throw { message: `Schema and table should be ${this.schema}.${this.table}` };
230 | }
231 | }
232 |
233 | _request(method: string, url: string, data?: any) {
234 | let options = {
235 | url: this.url + "/" + url,
236 | method: method,
237 | data: data,
238 | headers: {
239 | "Content-Type": "application/json"
240 | }
241 | };
242 |
243 | if (this.basicAuth || this.withCredentials) {
244 | options["withCredentials"] = true;
245 | }
246 | if (this.basicAuth) {
247 | options.headers["Authorization"] = this.basicAuth;
248 | }
249 |
250 | return this.backendSrv.datasourceRequest(options)
251 | .then(response => {
252 | response.data.$$status = response.status;
253 | response.data.$$config = response.config;
254 | return response.data;
255 | });
256 | }
257 |
258 | _get(url = "") {
259 | return this._request('GET', url);
260 | }
261 |
262 | _post(url: string, data?: any) {
263 | return this._request('POST', url, data);
264 | }
265 | }
266 |
267 | // Special value formatter for Crate.
268 | function formatCrateValue(value) {
269 | if (typeof value === 'string') {
270 | return wrapWithQuotes(value);
271 | } else {
272 | return value.map(v => wrapWithQuotes(v)).join(', ');
273 | }
274 | }
275 |
276 | function wrapWithQuotes(value) {
277 | if (!isNaN(value) ||
278 | value.indexOf("'") != -1 ||
279 | value.indexOf('"') != -1) {
280 | return value;
281 | } else {
282 | return "'" + value + "'";
283 | }
284 | }
285 |
286 | export function convertToCrateInterval(grafanaInterval) {
287 | let crateIntervals = [
288 | {shorthand: 's', value: 'second'},
289 | {shorthand: 'm', value: 'minute'},
290 | {shorthand: 'h', value: 'hour'},
291 | {shorthand: 'd', value: 'day'},
292 | {shorthand: 'w', value: 'week'},
293 | {shorthand: 'M', value: 'month'},
294 | {shorthand: 'y', value: 'year'}
295 | ];
296 | let intervalRegex = /([\d]*)([smhdwMy])/;
297 | let parsedInterval = intervalRegex.exec(grafanaInterval);
298 | let value = Number(parsedInterval[1]);
299 | let unit = parsedInterval[2];
300 | let crateInterval = _.find(crateIntervals, {'shorthand': unit});
301 | return crateInterval ? crateInterval.value : undefined;
302 | }
303 |
304 | function crateToMsInterval(crateInterval: string) {
305 | let intervals_s = {
306 | 'year': 60 * 60 * 24 * 30 * 12,
307 | 'quarter': 60 * 60 * 24 * 30 * 3,
308 | 'month': 60 * 60 * 24 * 30,
309 | 'week': 60 * 60 * 24 * 7,
310 | 'day': 60 * 60 * 24,
311 | 'hour': 60 * 60,
312 | 'minute': 60,
313 | 'second': 1
314 | };
315 |
316 | if (intervals_s[crateInterval]) {
317 | return intervals_s[crateInterval] * 1000; // Return ms
318 | } else {
319 | return undefined;
320 | }
321 | }
322 |
323 | function getMinCrateInterval(ms) {
324 | let seconds = ms / 1000;
325 | if (seconds > 60 * 60 * 24 * 30 * 3)
326 | return 'year';
327 | else if (seconds > 60 * 60 * 24 * 30) // TODO: check defenition of month interval
328 | return 'quarter';
329 | else if (seconds > 60 * 60 * 24 * 7)
330 | return 'month';
331 | else if (seconds > 60 * 60 * 24)
332 | return 'week';
333 | else if (seconds > 60 * 60)
334 | return 'day';
335 | else if (seconds > 60)
336 | return 'hour';
337 | else if (seconds > 1)
338 | return 'second';
339 | else
340 | return 'second';
341 | }
342 |
--------------------------------------------------------------------------------
/dist/img/crate-datasource-add-src.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raintank/crate-datasource/81e4a2e9b7e0c000133de8533d2a14d01fd216e2/dist/img/crate-datasource-add-src.png
--------------------------------------------------------------------------------
/dist/img/crate-datasource-error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raintank/crate-datasource/81e4a2e9b7e0c000133de8533d2a14d01fd216e2/dist/img/crate-datasource-error.png
--------------------------------------------------------------------------------
/dist/img/crate-datasource-graph.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raintank/crate-datasource/81e4a2e9b7e0c000133de8533d2a14d01fd216e2/dist/img/crate-datasource-graph.png
--------------------------------------------------------------------------------
/dist/img/crate-datasource-nonvalidation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raintank/crate-datasource/81e4a2e9b7e0c000133de8533d2a14d01fd216e2/dist/img/crate-datasource-nonvalidation.png
--------------------------------------------------------------------------------
/dist/img/crate_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raintank/crate-datasource/81e4a2e9b7e0c000133de8533d2a14d01fd216e2/dist/img/crate_logo.png
--------------------------------------------------------------------------------
/dist/module.d.ts:
--------------------------------------------------------------------------------
1 | import { CrateDatasource } from './datasource';
2 | import { CrateDatasourceQueryCtrl } from './query_ctrl';
3 | import { CrateConfigCtrl } from './config_ctrl';
4 | declare class CrateQueryOptionsCtrl {
5 | static templateUrl: string;
6 | }
7 | export { CrateDatasource as Datasource, CrateDatasourceQueryCtrl as QueryCtrl, CrateConfigCtrl as ConfigCtrl, CrateQueryOptionsCtrl as QueryOptionsCtrl };
8 |
--------------------------------------------------------------------------------
/dist/module.js:
--------------------------------------------------------------------------------
1 | System.register(['./datasource', './query_ctrl', './config_ctrl'], function(exports_1) {
2 | var datasource_1, query_ctrl_1, config_ctrl_1;
3 | var CrateQueryOptionsCtrl;
4 | return {
5 | setters:[
6 | function (datasource_1_1) {
7 | datasource_1 = datasource_1_1;
8 | },
9 | function (query_ctrl_1_1) {
10 | query_ctrl_1 = query_ctrl_1_1;
11 | },
12 | function (config_ctrl_1_1) {
13 | config_ctrl_1 = config_ctrl_1_1;
14 | }],
15 | execute: function() {
16 | CrateQueryOptionsCtrl = (function () {
17 | function CrateQueryOptionsCtrl() {
18 | }
19 | CrateQueryOptionsCtrl.templateUrl = 'partials/query.options.html';
20 | return CrateQueryOptionsCtrl;
21 | })();
22 | exports_1("Datasource", datasource_1.CrateDatasource);
23 | exports_1("QueryCtrl", query_ctrl_1.CrateDatasourceQueryCtrl);
24 | exports_1("ConfigCtrl", config_ctrl_1.CrateConfigCtrl);
25 | exports_1("QueryOptionsCtrl", CrateQueryOptionsCtrl);
26 | }
27 | }
28 | });
29 | //# sourceMappingURL=module.js.map
--------------------------------------------------------------------------------
/dist/module.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"module.js","sourceRoot":"","sources":["module.ts"],"names":["CrateQueryOptionsCtrl","CrateQueryOptionsCtrl.constructor"],"mappings":";;;;;;;;;;;;;;;YAIA;gBAAAA;gBAEAC,CAACA;gBADQD,iCAAWA,GAAGA,6BAA6BA,CAACA;gBACrDA,4BAACA;YAADA,CAACA,AAFD,IAEC;YAGoB,qDAAU;YACD,6DAAS;YAClB,sDAAU;YACJ,oDAAgB"}
--------------------------------------------------------------------------------
/dist/module.ts:
--------------------------------------------------------------------------------
1 | import {CrateDatasource} from './datasource';
2 | import {CrateDatasourceQueryCtrl} from './query_ctrl';
3 | import {CrateConfigCtrl} from './config_ctrl';
4 |
5 | class CrateQueryOptionsCtrl {
6 | static templateUrl = 'partials/query.options.html';
7 | }
8 |
9 | export {
10 | CrateDatasource as Datasource,
11 | CrateDatasourceQueryCtrl as QueryCtrl,
12 | CrateConfigCtrl as ConfigCtrl,
13 | CrateQueryOptionsCtrl as QueryOptionsCtrl
14 | };
15 |
--------------------------------------------------------------------------------
/dist/partials/config.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |