https://github.com/txchen/influx-gateway
write json event to influxdb
https://github.com/txchen/influx-gateway
Last synced: 12 months ago
JSON representation
write json event to influxdb
- Host: GitHub
- URL: https://github.com/txchen/influx-gateway
- Owner: txchen
- License: mit
- Created: 2015-09-09T23:52:42.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-02-24T18:37:13.000Z (over 10 years ago)
- Last Synced: 2025-02-15T16:44:32.601Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/influx-gateway
- Size: 27.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# influx-gateway
[](https://travis-ci.org/txchen/influx-gateway)
[](https://www.npmjs.com/package/influx-gateway)
[](https://codeclimate.com/github/txchen/eslint-plugin-riot)
InfluxDB had a json protocol but it will be deprecated, this service helps you to write json into influxDB.
## How to deploy
Firstly, install:
```bash
$ npm install influx-gateway -g
```
Then command `igw` or `influx-gateway` will be available.
Now we need a configuration file for influx-gateway, you can see the example by running:
```bash
$ igw genconfig
```
Create a config file, and then we can run the server:
```bash
$ igw -c [configfile]
```
## Configuration
Config is quite straight forward. The only tricky part is: if your influxdb requires authentication, you should include the username and password in the `influx_url`.
## Authentication
Influx-gateway does not provide authentication, you can put a proxy in front of igw. For example, an nginx instance with basic auth check enabled.
## API
* GET /ping
Ping will check the influxdb connectivity.
* POST /event
This API would transform json input into influx db's line protocol message. See [Here](https://influxdb.com/docs/v0.9/write_protocols/line.html) for more information about line-protocol.
Example payload:
```json
{
"_name": "cpu",
"__f1": 1,
"tag1": "v1",
"tag2": "v2"
}
```
`_name` must be specified as the measurement name, type must be string, regex: `/^[a-zA-Z0-9][\w-\.\/]*$/`
Field name starts with `__[a-zA-Z0-9]`, and remaining part use the same rule as measurement name.
Field value can be number, boolean or string.
Fields are optional, if no fields in the payload, igw will add `count=1i` automatically.
Tag name and tag value also should follow the measurement name regex.
Tags are also optional.
* POST /query
This API accepts influxdb query and returns json result. Query must start with `SELECT`.
Example payload:
```json
{
"q": "SELECT value FROM cpu_load_short WHERE region='us-west'",
}
```
Example result:
```json
{
"latency": 230,
"series": [
{
"name": "cpu_load_short",
"columns": [
"time",
"value"
],
"values": [
[
"2015-01-29T21:55:43.702900257Z",
0.55
],
[
"2015-01-29T21:55:43.702900257Z",
23422
],
[
"2015-06-11T20:46:02Z",
0.64
]
]
}
]
}
```
## Changelog
**2016-02-24** `0.1.5`
Add query latency in response.
**2016-02-23** `0.1.4`
Add query api.
**2015-10-13** `0.1.3`
Upgrade dependencies.
**2015-10-11** `0.1.2`
1st working version.