From 932f56f56f7c214eafc74bb56dd8d11150818610 Mon Sep 17 00:00:00 2001 From: Thibault Richard Date: Mon, 2 Jan 2017 11:00:44 +0100 Subject: [PATCH] Small doc improvements Signed-off-by: Thibault Richard --- Bash/README.md | 82 +++++++++++-------- Bash/creds.example | 4 +- Bash/delete | 4 +- Bash/lib/{iot-lib.sh => metrics-functions.sh} | 18 ++-- Bash/list-metrics | 2 +- Bash/put-n-query-foo-bar | 2 +- Bash/put-sys | 2 +- Bash/query | 4 +- README.md | 4 +- 9 files changed, 65 insertions(+), 57 deletions(-) rename Bash/lib/{iot-lib.sh => metrics-functions.sh} (77%) diff --git a/Bash/README.md b/Bash/README.md index dba7863..422eb1e 100644 --- a/Bash/README.md +++ b/Bash/README.md @@ -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 +``` diff --git a/Bash/creds.example b/Bash/creds.example index 61bcd0d..e145bca 100644 --- a/Bash/creds.example +++ b/Bash/creds.example @@ -1,8 +1,8 @@ # -# IoT creds +# Metrics data platform creds # -# https://cloud.runabove.com/#/iot/ +# https://www.ovh.com/manager/cloud/index.html#/paas/dbaas/timeseries/project//keys READ_TOKEN_ID= READ_TOKEN_KEY= diff --git a/Bash/delete b/Bash/delete index 0f04141..31ef71f 100755 --- a/Bash/delete +++ b/Bash/delete @@ -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) @@ -12,7 +12,7 @@ delete_query() { local metric=$1 local startDate=${2:-0} local downSample=${3:-10s} - + echo '{ "start":'$startDate', "queries":[{ diff --git a/Bash/lib/iot-lib.sh b/Bash/lib/metrics-functions.sh similarity index 77% rename from Bash/lib/iot-lib.sh rename to Bash/lib/metrics-functions.sh index bccfecd..4aeb17f 100644 --- a/Bash/lib/iot-lib.sh +++ b/Bash/lib/metrics-functions.sh @@ -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 +METRICS_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 @@ -15,7 +15,7 @@ source creds put() { curl -s \ -u $WRITE_TOKEN_ID:$WRITE_TOKEN_KEY \ - -XPOST "$IOT_API/api/put" \ + -XPOST "$METRICS_API/api/put" \ -d @- \ $OPTS } @@ -27,31 +27,31 @@ put() { query() { curl -s \ -u $READ_TOKEN_ID:$READ_TOKEN_KEY \ - -XPOST "$IOT_API/api/query" \ + -XPOST "$METRICS_API/api/query" \ -d @- \ $OPTS } # 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 \ -u $WRITE_TOKEN_ID:$WRITE_TOKEN_KEY \ - -XDELETE "$IOT_API/api/query" \ + -XDELETE "$METRICS_API/api/query" \ -d @- \ $OPTS } -# Get metrics +# Get metrics list # # @param none # listMetrics() { curl -s \ -u $READ_TOKEN_ID:$READ_TOKEN_KEY \ - -XGET "$IOT_API/api/suggest?type=metrics" \ + -XGET "$METRICS_API/api/suggest?type=metrics" \ $OPTS } @@ -69,7 +69,7 @@ kv_to_put_json() { local now=$(date +%s) local comma='' local tags='"tags":'"$tag" - + echo '[' while read line do diff --git a/Bash/list-metrics b/Bash/list-metrics index c275da4..7c87678 100755 --- a/Bash/list-metrics +++ b/Bash/list-metrics @@ -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 diff --git a/Bash/put-n-query-foo-bar b/Bash/put-n-query-foo-bar index 586e0fe..543b5ad 100755 --- a/Bash/put-n-query-foo-bar +++ b/Bash/put-n-query-foo-bar @@ -1,7 +1,7 @@ #!/bin/bash set -euo pipefail -source lib/iot-lib.sh +source lib/metrics-functions.sh # Put and Query diff --git a/Bash/put-sys b/Bash/put-sys index 2708b1c..a7921b3 100755 --- a/Bash/put-sys +++ b/Bash/put-sys @@ -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'"}' \ diff --git a/Bash/query b/Bash/query index ed51468..27e2f33 100755 --- a/Bash/query +++ b/Bash/query @@ -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) @@ -11,7 +11,7 @@ source lib/iot-lib.sh json_avg_query() { local metric=$1 local startDate=${2:-0} - + echo '{ "start":'$startDate', "queries":[{ diff --git a/README.md b/README.md index bd0238d..6e6b3ea 100644 --- a/README.md +++ b/README.md @@ -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.