Skip to content

Metrics

Iñaki Villar edited this page May 11, 2020 · 3 revisions

Metrics help us to add more information in the execution of every task. For instance, in a time/series configuration it helps us to filter and group the information to be a better response regarding the analysis of performance issues.

Predefined Metrics

Talaiot offers some predefined metrics grouped by category:

  • defaultMetrics: The basic metrics of the project. The name of the project, the version of Gradle and the requested tasks are some of the metrics generated by this group.
  • gitMetrics: Git related metrics. Contains metrics for the Git user and the branch where the build ran.
  • performanceMetrics: System-related metrics, like the number of processors and the amount of available ram during the build.
  • gradleSwitchesMetrics: Gradle configuration related metrics.
  • environmentMetrics: Build environment metrics. Hostname, public IP, default charset and OS manufacturer are some of the metrics in this group.

Please check the MetricsConfiguration.kt for implementation details for each of those groups.

Disabling metrics

By default, all predefined metrics are enabled. You can disable certain groups if desired. For example, if you want to disable Git and performance metrics:

talaiot {
    metrics {
        gitMetrics = false
        performanceMetrics = false
    }
}

Custom metrics

Creating custom metrics

To create your custom metric class, extend the Metric class or any of the Metric based classes. SimpleMetric is a good start point.

class HelloMetric : SimpleMetric<String>(
    provider = { "Hello!" },
    assigner = { report, value -> 
        report.customProperties.buildProperties["hello"] = value 
    }
)

Using custom metrics

If none of the predefined metrics contains the information you want in your reports, you can use a custom metric.

talaiot {
    metrics {
        customMetrics(
            // Our custom metric, HelloMetric.
            HelloMetric()
        )
    }
}

If you only need to report simple values, and don't desire to create a class for your custom metric, you can use customBuildMetrics() or customTaskMetrics() to provide your metrics.

talaiot {
    metrics {
        customBuildMetrics(
            "kotlinVersion" to $kotlinVersion,
            "javaVersion" to $javaVersion
        )
        customTaskMetrics(
            "taskPid" to $pid
        )
    }
}

Using specific predefined metrics

You can also pass any predefined metrics as a custom metric. A common case is where you don't want all metrics from a predefined group. You can disable the group and specify only the metrics you want as custom metrics.

talaiot {
    metrics {
        // We don't need all environment metrics, so we disable them here.
        environmentMetrics = false
        // Using custom metrics, we enable some of the environment metrics.
        customMetrics(
            // Our custom metric, HelloMetric.
            HelloMetric(),
            // Predefined metrics from the environment group that we want to
            // include in our report.
            DefaultCharsetMetric(),
            HostnameMetric()
        )
    }
}