May 8, 2014

Extending Perforce Insights 2014.1


The release of Insights 2014.1 adds support for the latest version of the Perforce Server, and also adds a few more metrics to those already available. Not only do these extend the functionality of Insights, they are also examples of what can be done with plugins.

By popular request, we've added the ability to see a breakdown of the files in your projects by file type or file extension. It is now possible to see what proportion of your projects consists of source code, graphic files, documentation or any other breakdown you desire by enabling the FileExtensions and FileTypes metrics.

We added two features to the backend to help support this. First, fully parametrized database queries and updates are now supported, making it both easier (and safer) to run SQL queries, and to also allow a plugin to run SQL updates.

Database updates go hand in hand with the second feature, which is the ability for a plugin to define a task that is run daily. This allows plugins to run complex queries once, and store the results in a format that can be quickly queried when a chart needs to be displayed.

Finally, another metric that Insights was obviously lacking was a weather widget to display the temperature in each of the Perforce offices, so we've added that as well. Whilst the widget itself may not be that useful (unless you want to correlate developer activity with temperature), it serves as an example of how Insights can be used to pull in data from any resource, and display it in your dashboard.

Since the plugins are written in Groovy, obtaining data from an external web service is as simple as:

[ "London", "Sydney", "San Francisco", "Victoria" ].each() { city->
    def url = "${city}&cnt=5&units=metric".toURL().text
    def root = new JsonSlurper().parseText(url)

    def series = new DataSeries()
    series.label = city
    root.list.each() { forecast ->

The Insights plugins interface is still in beta, and while the documentation is still sparse, the examples can be used as guides if you want to have a go.

These examples (including the ones mentioned above) are shipped with the Insights installation package, but are not enabled by default. They can be enabled by copying them into the plugins directory within Tomcat.