Commit b1271c43 by marwan

init flowengine grafana influxdb package

parent 84f4b05a
#!/bin/bash
ORG_NAME="$1"
BUCKET_NAME="influxdb_monitoring"
INFLUX_TOKEN="$2"
URI="$3"
echo ORG_NAME: $ORG_NAME
echo INFLUX_TOKEN: $INFLUX_TOKEN
echo URI: $URI
OrgID=''
LengthOrgID=0
while [ "$LengthOrgID" -ne 16 ]
do
sleep 1
orgInfo=$(influx org list --token $INFLUX_TOKEN --host $URI)
orgInfo=$(echo "$orgInfo" | sed -e 's/^[ \t]*//')
#ID Name
#ae4907f2f6f4ac66 primary
name=''
while read -r line; do
echo $line
name=$(echo "$line" | awk '{print $2}' | sed 's/[^a-zA-Z0-9]//g')
echo $name
if [ "$ORG_NAME" == "$name" ]; then
OrgID=($(echo "$line" | awk '{print $1}'))
fi
done <<< "$(echo "$orgInfo" | awk 'NR > 1')"
LengthOrgID=${#OrgID}
#echo $LengthOrgID
#if [ "$LengthOrgID" -ne 16 ]; then
# echo cannot get orgID
# exit 0;
#fi
done
echo "OrgID: ${OrgID[@]}"
curl --request POST ${URI}/api/v2/buckets -H "Authorization: Token ${INFLUX_TOKEN}" -H "Accept: application/json" -H "Content-Type: application/json" -d "{ \"name\": \"${BUCKET_NAME}\", \"description\": \"A bucket holding air sensor data\", \"orgID\": \"${OrgID[@]}\", \"retentionRules\": [ { \"type\": \"expire\", \"everySeconds\": 15552000 } ] }" #2592000
output=$(influx bucket list --token $INFLUX_TOKEN --org $ORG_NAME --host $URI)
echo output :$output
#"
#ID Name Retention Shard group duration Organization ID Schema Type
#94d1807ef7a7a5f7 _monitoring 168h0m0s 24h0m0s 57e96428672da980 implicit
#dd7cb4ebd0ba6dec _tasks 72h0m0s 24h0m0s 57e96428672da980 implicit
#5b72652dc7c001c4 primary infinite 168h0m0s 57e96428672da980 implicit
#"
# Remove leading and trailing whitespace from each line
output=$(echo "$output" | sed -e 's/^[ \t]*//')
# Parse the data using awk into separate arrays
# The field separator is one or more spaces or tabs
# Check if "Name" is "primary" before storing it in the array
ID=''
Name=''
Retention=''
ShardDuration=''
OrgID=''
SchemaType=''
while read -r line; do
name=$(echo "$line" | awk '{print $2}')
if [ "$name" == "$BUCKET_NAME" ]; then
ID=($(echo "$line" | awk '{print $1}'))
Name=("$name")
Retention=($(echo "$line" | awk '{print $3}'))
ShardDuration=($(echo "$line" | awk '{print $4}'))
OrgID=($(echo "$line" | awk '{print $5}'))
SchemaType=($(echo "$line" | awk '{print $6}'))
fi
done <<< "$(echo "$output" | awk 'NR > 1')"
# Check if "Name" is "primary" for each matching row
# Print the arrays
echo "ID: ${ID[@]}"
echo "Name: ${Name[@]}"
echo "Retention: ${Retention[@]}"
echo "Shard Duration: ${ShardDuration[@]}"
echo "Organization ID: ${OrgID[@]}"
echo "Schema Type: ${SchemaType[@]}"
#echo curl -X POST http://localhost:8086/api/v2/scrapers -H "Authorization: Token ${INFLUX_TOKEN}" -H "Content-Type: application/json" -d "{ \"allowInsecure\": false, \"orgID\": \"${OrgID[@]}\", \"bucketID\": \"${ID[@]}\", \"name\": \"string\", \"type\": \"prometheus\", \"url": \"http://localhost:8086/metrics\" }"
curl -X POST ${URI}/api/v2/scrapers -H "Authorization: Token ${INFLUX_TOKEN}" -H "Content-Type: application/json" -d "{ \"allowInsecure\": false, \"orgID\": \"${OrgID[@]}\", \"bucketID\": \"${ID[@]}\", \"name\": \"string\", \"type\": \"prometheus\", \"url\": \"http://localhost:8086/metrics\" }" -i
echo ----success----
exit 1
services: services:
app: app:
image: dock.nexpie.com/stack/flowengine:1.3.5-2-f633d8d2 image: dock.nexpie.com/stack/flowengine:1.3.5-2-f633d8d2
volumes: volumes:
- ./flow-data:/usr/local/flowengine - flow_data:/usr/local/flowengine
- ./store-data:/usr/local/store-data - store_data:/usr/local/store-data
# - Gluster/
ports: ports:
- 30081:80 - 30081:80
environment: # environment:
PROJECT_ID: "${SH_PROJECT_ID}" # PROJECT_ID: "${SH_PROJECT_ID}"
OAUTH_LOGIN: "TRUE" # OAUTH_LOGIN: "TRUE"
PASSWORD_LOGIN: "TRUE" # PASSWORD_LOGIN: "TRUE"
AUTH_ENDPOINT: https://auth.nexiiot.io/dialog/authorize # AUTH_ENDPOINT: https://auth.nexiiot.io/dialog/authorize
AUTH_PLATFORM_NAME: NEXIIOT # AUTH_PLATFORM_NAME: NEXIIOT
GQLV2_ENDPOINT: https://gqlv2.nexiiot.io # GQLV2_ENDPOINT: https://gqlv2.nexiiot.io
INSTANCE_NAME: NEXIIOT FlowEngine # INSTANCE_NAME: NEXIIOT FlowEngine
OAUTH_CLIENT_ID: ${SH_OAUTH_CLIENT_ID} # OAUTH_CLIENT_ID: ${SH_OAUTH_CLIENT_ID}
OAUTH_CLIENT_SECRET: ${SH_OAUTH_CLIENT_SECRET} # OAUTH_CLIENT_SECRET: ${SH_OAUTH_CLIENT_SECRET}
TOKEN_ENDPOINT: https://auth.nexiiot.io/oauth/token # TOKEN_ENDPOINT: https://auth.nexiiot.io/oauth/token
USERINFO_API_ENDPOINT: https://auth.nexiiot.io/api/userinfo # USERINFO_API_ENDPOINT: https://auth.nexiiot.io/api/userinfo
influxdb: influxdb:
image: docker.io/bitnami/influxdb:2.7.1 image: docker.io/bitnami/influxdb:2.7.1
ports: ports:
...@@ -27,9 +29,9 @@ services: ...@@ -27,9 +29,9 @@ services:
environment: environment:
- INFLUXDB_ADMIN_USER_PASSWORD=nexiiotpassword - INFLUXDB_ADMIN_USER_PASSWORD=nexiiotpassword
- INFLUXDB_ADMIN_USER_TOKEN=nexiiottoken - INFLUXDB_ADMIN_USER_TOKEN=nexiiottoken
- influxdb_primary_bucket=primary - INFLUXDB_PRIMARY_BUCKET=primary
- influxdb_admin_organization=primary - INFLUXDB_ADMIN_ORGANIZATION=primary
- influxdb_retention_period=4320 #24 * 180 อายุข้อมูล - INFLUXDB_RETENTION_PERIOD=4320 #24 * 180 อายุข้อมูล
- INFLUXDB_MONITOR_STORE_DATABASE="primary" - INFLUXDB_MONITOR_STORE_DATABASE="primary"
- INFLUXD_UI_DISABLED=false - INFLUXD_UI_DISABLED=false
- INFLUXD_REPORTING_DISABLED=false - INFLUXD_REPORTING_DISABLED=false
...@@ -39,6 +41,19 @@ services: ...@@ -39,6 +41,19 @@ services:
- influxdb:/bitnami/influxdb - influxdb:/bitnami/influxdb
- ./bash-influx:/bitnami/ - ./bash-influx:/bitnami/
influxdb_init:
image: docker.io/bitnami/influxdb:2.7.1
depends_on:
- influxdb
entrypoint: ["bash","-c","bash /bitnami/script/init.bash $${INFLUXDB_ADMIN_ORGANIZATION} $${INFLUXDB_ADMIN_USER_TOKEN} http://influxdb:8086"]
environment:
- INFLUXDB_ADMIN_USER_TOKEN=nexiiottoken
- INFLUXDB_ADMIN_ORGANIZATION=primary
volumes:
- ./bash-influx:/bitnami/script
grafana: grafana:
image: docker.io/bitnami/grafana:10 image: docker.io/bitnami/grafana:10
ports: ports:
...@@ -46,13 +61,17 @@ services: ...@@ -46,13 +61,17 @@ services:
environment: environment:
- 'GF_SECURITY_ADMIN_PASSWORD=nexiiot' - 'GF_SECURITY_ADMIN_PASSWORD=nexiiot'
volumes: volumes:
- grafana_data:/opt/bitnami/grafana/data - grafana_data:/opt/bitnami/grafana/data
- ./grafana/datasources:/opt/bitnami/grafana/conf/provisioning/datasources/ - ./grafana/datasources:/opt/bitnami/grafana/conf/provisioning/datasources/
- ./grafana/dashboard/templates:/var/lib/dashboards - ./grafana/dashboard/templates:/var/lib/dashboards
- ./grafana/dashboard/conf:/opt/bitnami/grafana/conf/provisioning/dashboards/ - ./grafana/dashboard/conf:/opt/bitnami/grafana/conf/provisioning/dashboards/
volumes: volumes:
grafana_data: grafana_data:
driver: local driver: local
influxdb: influxdb:
driver: local driver: local
\ No newline at end of file flow_data:
driver: local
store_data:
driver: local
apiVersion: 1
providers:
- name: dashboards
type: file
updateIntervalSeconds: 30
options:
path: /var/lib/dashboards
apiVersion: 1
datasources:
- name: InfluxDB_v2_Flux
type: influxdb
access: proxy
url: http://influxdb:8086
jsonData:
version: Flux
organization: primary
defaultBucket: admin
tlsSkipVerify: true
secureJsonData:
token: nexiiottoken
apiVersion: 1
datasources:
- name: InfluxDB_v2_InfluxQL
type: influxdb
access: proxy
url: http://influxdb:8086
jsonData:
# This database should be mapped to a bucket
dbName: primary
httpMode: GET
httpHeaderName1: 'Authorization'
secureJsonData:
httpHeaderValue1: 'Token nexiiottoken'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment