Metrics Forwarding - InfluxDB

Sends bundle analysis metrics to your InfluxDB database to create custom dashboards, correlate the data with other metrics, or create custom alerts.

Metrics forwarding is available for Open Source, PRO and Enterprise plans.

After every processed job, RelativeCI sends a measurement to InfluxDB that includes all bundle analysis metrics and the tags that identify your project and the job:

Forwarded metrics and tags

MetricUnitDescription
bundleSizebyteTotal bundle size
initialSizeJSbyteTotal size of the initial JS assets
initialSizeCSSbyteTotal size of the initial CSS assets
cacheInvalidationpercentagePercentage of changed assets
assetCountnumberTotal number of assets
chunkCountnumberTotal number of chunks
moduleCountnumberTotal number of modules
duplicateModuleCountnumberTotal number of duplicate modules
duplicateCodepercentagePercentage of duplicate code
packageCountnumberTotal number of packages
duplicatePackageCountnumberTotal number of duplicate packages
bundleSizeJSbyteTotal size of the JS assets
bundleSizeCSSbyteTotal size of the CSS assets
bundleSizeIMGbyteTotal size of the image assets
bundleSizeMEDIAbyteTotal size of the media assets
bundleSizeFONTbyteTotal size of the font assets
bundleSizeHTMLbyteTotal size of the HTML asets
bundleSizeOtherbyteTotal size of other assets

Every measurement is tagged with the following data:

TagDescription
organizationThe repository owner value
repoThe repository name
nameThe RelativeCI project name
branchThe job branch name

How to configure your InfluxDB connection

To configure Metrics Forwarding for InfluxDB, navigate to your project Settings -> Integrations -> Metrics Forwarding - InfluxDB and add your InfluxDB 2.0 database connection details:

Add InfluxDB 2.0 connection details

Debugging

In case of errors, you can browse the integration logs on Settings -> Integrations -> Metrics Forwarding - InfluxDB -> Logs and preview the JSON response.

Examples

Bundle size single stat

InfluxDB bundle size single stat example

bundleSize.flux
from(bucket: "relative-ci-data")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
// Filter by measurement
|> filter(fn: (r) => r["_measurement"] == "relative-ci")
// Filter by metric name
|> filter(fn: (r) => r["_field"] == "bundleSize")
// Filter by RelativeCI project name
|> filter(fn: (r) => r["name"] == "web-app")
// Filter by RelativeCI job branch
|> filter(fn: (r) => r["branch"] == "master")
// Select the last value
|> last()

To display the value using a custom unit, add the bytesToMiB function and use it to transform the value:

bundle-size.flux
bytesToMiB = (tables=<-) => tables
|> map(fn:(r) => ({
r with _value: string(
v: float(v: (r._value * 100 / 1048576)) / 100.0
) + "MiB"
}))
from(bucket: "relative-ci-data")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
// Filter by measurement
|> filter(fn: (r) => r["_measurement"] == "relative-ci")
// Filter by metric name
|> filter(fn: (r) => r["_field"] == "bundleSize")
// Filter by RelativeCI project name
|> filter(fn: (r) => r["name"] == "web-app")
// Filter by RelativeCI job branch
|> filter(fn: (r) => r["branch"] == "master")
// Select the last value
|> last()
// Format output value
|> bytesToMiB()

To allow you to select the project and the job branch, add two corresponding dashboard variables and reference them in the query:

relativeCIProjectName
import "influxdata/influxdb/schema"
schema.tagValues(bucket: "relative-ci-data", tag: "name")

relativeCIJobBranch
import "influxdata/influxdb/schema"
schema.tagValues(bucket: "relative-ci-data", tag: "branch")

bundle-size.flux
bytesToMiB = (tables=<-) => tables
|> map(fn:(r) => ({
r with _value: string(
v: float(v: (r._value * 100 / 1048576)) / 100.0
) + "MiB"
}))
from(bucket: "relative-ci-data")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
// Filter by measurement
|> filter(fn: (r) => r["_measurement"] == "relative-ci")
// Filter by metric name
|> filter(fn: (r) => r["_field"] == "bundleSize")
// Filter by RelativeCI project name dashboard variable
|> filter(fn: (r) => r["name"] == v.relativeCIProjectName)
// Filter by RelativeCI job branch dashboard variable
|> filter(fn: (r) => r["branch"] == v.relativeCIJobBranch)
// Select the last value
|> last()
// Format output value
|> bytesToMiB()

Initial JS size values over time

InfluxDB initial js values over time examle

from(bucket: "relative-ci-data")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
// Filter by measurement
|> filter(fn: (r) => r["_measurement"] == "relative-ci")
// Filter by metric name
|> filter(fn: (r) => r["_field"] == "initialSizeJS")
// Filter by RelativeCI project name dashboard variable
|> filter(fn: (r) => r["name"] == v.relativeCIProjectName)
// Filter by RelativeCI job branch dashboard variable
|> filter(fn: (r) => r["branch"] == v.relativeCIJobBranch)
// Get the latest value for every period
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)

Need help?Contact us via email, Twitter, or GitHub!