Skip to content
This repository has been archived by the owner on Jun 12, 2019. It is now read-only.

Commit

Permalink
Small doc improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Richard <[email protected]>
  • Loading branch information
Thibault Richard committed Jan 2, 2017
1 parent b2ee32b commit c45d50b
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 53 deletions.
82 changes: 46 additions & 36 deletions Bash/README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,67 @@
## IoT PAAS API put/query/utils bash functions.
## Bash functions for the Metrics data platform API.

Create a [`creds`](creds.example) file with your tokens info.

Source [lib/iot.lib.sh](lib/iot-lib.sh) and write some Bash:
Source [lib/metrics-functions.sh](lib/metrics-functions.sh) and write some Bash:

#!/bin/bash
set -euo pipefail
```
#!/bin/bash
set -euo pipefail
source lib/iot-lib.sh
source lib/metrics-functions.sh
```

### Put

echo '{
"metric":"foo",
"timestamp":'$(date +%s)',
"value":'0.$RANDOM',
"tags":{}
}' | put
```
echo '{
"metric":"foo",
"timestamp":'$(date +%s)',
"value":'0.$RANDOM',
"tags":{}
}' | put
```

Or send key:value list with `kv_to_put_json` function:

echo '\
foo:42
bar:123' \
| kv_to_put_json \
| put
```
echo '\
foo:42
bar:123' \
| kv_to_put_json \
| put
```

### Query

echo '{
"start":0,
"queries":[{
"metric":"foo",
"aggregator":"avg",
"downsample":"10s-avg",
"tags":{}
}]
}' | query
```
echo '{
"start":0,
"queries":[{
"metric":"foo",
"aggregator":"avg",
"downsample":"10s-avg",
"tags":{}
}]
}' | query
```

### Delete

echo '{
"start":0,
"queries":[{
"metric":"foo",
"aggregator":"avg",
"downsample":"10s-avg",
"tags":{}
}]
}' | delete
```
echo '{
"start":0,
"queries":[{
"metric":"foo",
"aggregator":"avg",
"downsample":"10s-avg",
"tags":{}
}]
}' | delete
```

### List Metrics

```
listMetrics

returns all metrics for the current application
```
4 changes: 2 additions & 2 deletions Bash/creds.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# IoT creds
# Metrics data platform creds
#

# https://cloud.runabove.com/#/iot/<your_app>
# https://www.ovh.com/manager/cloud/index.html#/paas/dbaas/timeseries/project/<your_app>/keys

READ_TOKEN_ID=
READ_TOKEN_KEY=
Expand Down
4 changes: 2 additions & 2 deletions Bash/delete
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euo pipefail

source lib/iot-lib.sh
source lib/metrics-functions.sh

# @param metric the metric to query
# @param startDate the date to start the query (default: 0)
Expand All @@ -12,7 +12,7 @@ delete_query() {
local metric=$1
local startDate=${2:-0}
local downSample=${3:-10s}

echo '{
"start":'$startDate',
"queries":[{
Expand Down
10 changes: 5 additions & 5 deletions Bash/lib/iot-lib.sh → Bash/lib/metrics-functions.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# IoT PAAS API put/query/utils bash functions.
# Metrics data plaform API put/query/utils bash functions.
#

IOT_API=https://opentsdb.iot.runabove.io
IOT_API=https://opentsdb-gra1.tsaas.ovh.com
OPTS="-w {\"status\":%{http_code},\"time\":%{time_total}}\n"

[ ! -f creds ] && echo "error: please setup a creds file with write/read id and key tokens" && exit 1
Expand Down Expand Up @@ -34,7 +34,7 @@ query() {

# Delete data from query
#
# @param stdin JSON data to query (http://opentsdb.net/docs/build/html/api_http/query.html)
# @param stdin JSON data to delete (http://opentsdb.net/docs/build/html/api_http/query.html)
#
delete() {
curl -s \
Expand All @@ -44,7 +44,7 @@ delete() {
$OPTS
}

# Get metrics
# Get metrics list
#
# @param none
#
Expand All @@ -69,7 +69,7 @@ kv_to_put_json() {
local now=$(date +%s)
local comma=''
local tags='"tags":'"$tag"

echo '['
while read line
do
Expand Down
2 changes: 1 addition & 1 deletion Bash/list-metrics
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euo pipefail

source lib/iot-lib.sh
source lib/metrics-functions.sh

#
# @return a JSON object representing an OpenTSDB suggest metrics query
Expand Down
2 changes: 1 addition & 1 deletion Bash/put-n-query-foo-bar
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euo pipefail

source lib/iot-lib.sh
source lib/metrics-functions.sh

# Put and Query

Expand Down
2 changes: 1 addition & 1 deletion Bash/put-sys
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euo pipefail

source lib/iot-lib.sh
source lib/metrics-functions.sh

./probes/sys.sh \
| kv_to_put_json '{"host":"'$HOSTNAME'"}' \
Expand Down
4 changes: 2 additions & 2 deletions Bash/query
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euo pipefail

source lib/iot-lib.sh
source lib/metrics-functions.sh

# @param metric the metric to query
# @param startDate the date to start the query (default: 0)
Expand All @@ -11,7 +11,7 @@ source lib/iot-lib.sh
json_avg_query() {
local metric=$1
local startDate=${2:-0}

echo '{
"start":'$startDate',
"queries":[{
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
This repository contains examples of how to push data to the Runabove IoT metrics storage in different languages.

The metrics storage uses the OpenTSDB API, and read-made libraries already exist in most languages.
This repository contains examples of how to push data to the OVH Metrics Data platform in different languages.

0 comments on commit c45d50b

Please sign in to comment.