nodejs operation influxdb
const { OrgsAPI, BucketsAPI, UsersAPI, AuthorizationsAPI } = require( '@influxdata/influxdb-client-apis');
const { InfluxDB } = require('@influxdata/influxdb-client');
const uuid = require('uuid');
const influxHost = “127.0.0.1”;
const influxPort = 27017;
const url = `http://${influxHost}:${influxPort}`;
const token = 'zTQfDoeRo6C92S_6qjIhvq4KlDp9o-a8wgTMOCBY5Qb-DYVL4WIKr533QtbLgebwLmxtnYscFrR_9fCEEbsvmw==';
const influxDB = new InfluxDB({url, token});
const name = `ecmaster`; //orgName
// org create
const orgsAPI = new OrgsAPI(influxDB);
const organization = await orgsAPI.postOrgs({body: {name}});
const orgID = organization.id;
//bucket create
const bucketsAPI = new BucketsAPI(influxDB);
const bucket = await bucketsAPI.postBuckets({body: {orgID, name }});
// user create
const usersAPI = new UsersAPI(influxDB);
const user = await usersAPI.postUsers({body: {name}});
const userID = user.id;
const password = uuid.v4();
await usersAPI.postUsersIDPassword({userID, body: {password}});
await orgsAPI.postOrgsIDOwners({ orgID, body: { id: user.id } }); // The owner of the current orgID has the permission of all resources in this org, but does not have the org write permission. The resource permissions assigned to the API Token created by this user's login web interface belong to this org.
//APIToken create
/*
Explanation of parameters related to API Token permission field :
[name] Optional: If name is set, the permissions for the resource of that name. If not set, the permissions for all resources of this resource type.
[id] Optional: If ID is set, the permissions of the resource with that ID. If not set, the permissions for all resources of this resource type.
[orgID] Optional: If orgID is set, this is the permission for all resources owned by the organization with that orgID. If not set, the permissions for all resources of this resource type.
type 必填: "authorizations" "buckets" "dashboards" "orgs" "sources" "tasks" "telegrafs" "users" "variables" "scrapers" "secrets" "labels" "views" "documents" "notificationRules" "notificationEndpoints" "checks" "dbrp" "notebooks" "annotations" "remotes" "replications"
*/
const authorizationsAPI = new AuthorizationsAPI(influxDB);
const apiToken = await authorizationsAPI.postAuthorizations({ body : {orgID, userID: user.id, permissions: [
{
"action": "read",
"resource": {
"orgID": `${orgID}`,
"type": "authorizations"
}
},
{
"action": "read",
"resource": {
"orgID": `${orgID}`,
"type": "buckets"
}
},
{
"action": "read",
"resource": {
"orgID": `${orgID}`,
"type": "users"
}
},
{
"action": "write",
"resource": {
"orgID": `${orgID}`,
"type": "buckets"
}
}
]}
});
const influxSetting= {
org: organization.name,
bucket: bucket.name,
url,
token: apiToken.token,
username: user.name,
password: password
}
console.log(influxSetting);
influxdb-cli
mac installation:
brew install influxdb-cli
influx config create --config-name onboarding \
--host-url "http://10.1.1.115:8086" \
--token "zTQfDoeRo6C92S_6qjIhvq4KlDp9o-a8wgTMOCBY5Qb-DYVL4WIKr533QtbLgebwLmxtnYscFrR_9fCEEbsvmw==" \
--active
influx config list
influx config delete onboarding
org related operations
influx org list
influx org delete -i 07668febbebcbbbd //Delete org -i specified id
Bucket related operations
influx bucket list -o undefined_ecmaster //View the bucket of the specified org
influx bucket delete -i 6d10e05825be0228 -o undefined_ecmaster
API Token related operations
influx auth list -o ecmaster //View the APIToken of the specified org
user related operations
influx user list
influx user delete -i 0ba14fd3b1efe000 //Delete user-specified id
Read and write data
influx write --bucket undefined_ecmaster -o undefined_ecmaster --url https://influx-testdata.s3.amazonaws.com/air-sensor-data-annotated.csv //write data to bucket
influx query -o undefined_ecmaster 'from(bucket:"undefined_ecmaster") |> range(start:-1d,stop:-1ms)' //Read data