InfluxDB connector
InfluxDB is the database we use to store data and build dashboards. Our InfluxDB
connector is in multivac/influxdb.py
.
Run and connect to InfluxDB locally
Install InfluxDB 2 according to official instruction.
Launch InfluxDB:
$ influxd
After that you will be able to work with your InfluxDB with web-interface at http://localhost:8086 . You can change it with instruction. Go to your site and create the account. Save your login organisation as environmental variable or in
.env
asINFLUX_ORG
Go to
<localhost:8086> -> Load data -> Buckets
to create bucket. Save bucket name to environmental variable or in.env
file asINFLUX_BUCKET=<bucket>
Go to
<localhost:8086> -> Load data -> API Tokens
to get your token. Save token to environmental variable or in.env
file asINFLUX_TOKEN=<token>
Save your InfluxDB site to environmental variable or in
.env
file asINFLUX_URL
If you’ve written variables to
.env
, run the following command:$ source .env && export $(cut -d= -f1 .env)
Now you are ready to start any python script using InfluxDB connector
Using InfluxDB connector from code
To use our connector from your code, import the connector:
from multivac.influxdb import influx_connector
...
bucket = os.getenv('INFLUX_BUCKET')
org = os.getenv('INFLUX_ORG')
write_api = influx_connector()
data = {
'measurement': <your_record_ID, required>,
'tags': {<'indexed key/value structure, not required'>},
'fields': {<'not indexed key/value structure, required'>},
'time': <'unix time in nanoseconds, not required'>
}
write_api.write(bucket, org, [data])
InfluxDB connector in gather_data.py
Job data:
Measurement: failure type (or “successful jobs”);
Tags: job_name, job_id, run_id, branch, commit_sha, platform, conclusion, runner_label, gc64;
Fields: always: {“value”: 1};
Time: queued at, timestamp in nanoseconds.
Test data:
Measurement: test name;
Tags: job_name, commit_sha, job_id, test_configuration, test_attempt; The
test_attempt
increments if already stored this test with this configuration for this job ID.Fields: always: {“value”: 1};
Time: queued at, timestamp in nanoseconds.
Usage:
$ multivac/gather_data.py --format influxdb