Create a Statistic Mapping File

Create a new stat-mapping metadata file with the following content in stat-mapping.util2.json in the /usr/lib/sstore/metadata/json/site/ directory:

[
    {
        "$schema": "//:stat-mapping",
        "description": "map util2 instance errors to aggregate class errors",
        "id": "//:class.app/util2//:stat-mapping.errors",
        "instance-metadata": {
            "partitions": [
                "inst"
            ]
        },
        "transforms": [
            {
                "match": "//:class.app/util2//:res.inst/(Customers|Products|Orders)//:stat.errors$",
                "replace": "//:class.app/util2//:stat.errors//:part.inst(\\1)"
            }
        ]
    },
    {
        "$schema": "//:stat-mapping",
        "description": "map util2 instance reads and writes to aggregate class activity",
        "id": "//:class.app/util2//:stat-mapping.activity",
        "instance-metadata": {
            "partitions": [
                "inst",
                "type"
            ]
        },
        "transforms": [
            {
                "match": "//:class.app/util2//:res.inst/(Customers|Products|Orders)//:stat.(reads|writes)$",
                "replace": "//:class.app/util2//:stat.activity//:part.inst(\\1)//:part.type(\\2)"
            }
        ]
    }
]

In the first stanza, the errors statistic for each instance (statically allocated Customers, Products, and Orders) is mapped to a class-level errors statistic. The partitions element indicates that the statistic is partitioned by resource (inst). The (\\1) expression in the replace value matches the (Customers|Products|Orders) expression in the match value. The //:class.app/util2//:res.inst/Customers//:stat.errors, //:class.app/util2//:res.inst/Products//:stat.errors, and //:class.app/util2//:res.inst/Orders//:stat.errors values are aggregated in the //:class.app/util2//:stat.errors statistic. The split between resource instances is shown by the //:class.app/util2//:stat.errors//:part.inst SSID.

In the second stanza, the reads and writes statistics for each instance are mapped to the new activity statistic that you added to the stat.util2.json file. The (\\2) expression in the replace value matches the (reads|writes) expression in the match value. Total reads and writes from all three instances are aggregated in the //:class.app/util2//:stat.activity statistic. Splits between instances are shown by the //:class.app/util2//:stat.activity//:part.inst SSID. Splits between statistics are shown by the //:class.app/util2//:stat.activity//:part.type SSID.