Grafana dashboard: CodeQuality by Metrix++ 3:File
Description: Visualize code quality metrics LoC (Lines of Code), CC (Cyclomatic Complexity) and resulting CCD (Cyclomatic Complexity Density) collected for your codebase by Metrix++ in Prometheus

This dashboard allows you to visualize code quality metrics
1. LoC (Lines of Code)
1. CC (Cyclomatic Complexity)
1. and the resulting CCD (Cyclomatic Complexity Density), as division of CD by LoC

(all 3 horizontally in successive columns) collected for your codebase **files** (C/C++, C# and Java) by [Metrix++](https://metrixplusplus.github.io/home.html) in Prometheus.
For each metric, 3 graphs are rendered vertically showing successively:
1. total absolute for the current selection (codebase **files**)
1. distribution of the total 1. over the next level items (**regions**, i.e. methods, structures...)
1. deviation over the time of the total 1. by next level items (**regions**)

It is part of a set of 3 dashboards, linked for the sake of drilldown analysis:
1. _[CodeQuality by Metrix++ 1:Overall](https://grafana.com/grafana/dashboards/13754)_
1. _[CodeQuality by Metrix++ 2:Folder](https://grafana.com/grafana/dashboards/13755)_
1. **_[CodeQuality by Metrix++ 3:File](https://grafana.com/grafana/dashboards/13756)_**

**_[CodeQuality by Metrix++ 3:File](https://grafana.com/grafana/dashboards/13756)_** is designed as **last** dashboard used during analysis, showing metrics at codebase **file** level (selection) up to (scolling down to) the next level information about **regions** (i.e. methods, structures...).

First it requires you to put [Metrix++](https://metrixplusplus.github.io/home.html) in place for your codebase (C/C++, C# and Java), (see also its [github repo](https://github.com/metrixplusplus/metrixplusplus)), and to setup a Prometheus instance scraping the output of the following commands:
- `python metrix++.py view --ll=ERROR --format=prometheus`
- `python metrix++.py view --ll=ERROR --format=prometheus -- /home/mycodebase`
- `python metrix++.py view --ll=ERROR --format=prometheus -- /home/mycodebase/src`
- `python metrix++.py view --ll=ERROR --format=prometheus -- /home/mycodebase/src/main`
- `python metrix++.py view --ll=ERROR --format=prometheus -- /home/mycodebase/src/main/java`
- `python metrix++.py view --ll=ERROR --format=prometheus -- /home/mycodebase/src/main/java/Foo.java`

{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS_(VLEI)",
      "label": "Prometheus",
      "description": "Prometheus instance responsible for scraping Metrix++ metrics for your codebase",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    },
    {
      "name": "DS_METAINFO",
      "label": "metainfo",
      "description": "JSON datasource for meta information and events to be rendered as annotations, like build events",
      "type": "datasource",
      "pluginId": "simpod-json-datasource",
      "pluginName": "JSON"
    }
  ],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "5.4.3"
    },
    {
      "type": "panel",
      "id": "graph",
      "name": "Graph",
      "version": "5.0.0"
    },
    {
      "type": "datasource",
      "id": "prometheus",
      "name": "Prometheus",
      "version": "5.0.0"
    },
    {
      "type": "datasource",
      "id": "simpod-json-datasource",
      "name": "JSON",
      "version": "0.1.4"
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": false,
        "iconColor": "rgba(0, 211, 255, 1)",
        "limit": 100,
        "name": "Show user annotations",
        "showIn": 0,
        "type": "dashboard"
      },
      {
        "datasource": "${DS_METAINFO}",
        "enable": true,
        "hide": false,
        "iconColor": "rgba(255, 96, 96, 1)",
        "limit": 100,
        "name": "Show build annotations",
        "query": "builds",
        "showIn": 0,
        "tags": [],
        "type": "tags"
      }
    ]
  },
  "editable": true,
  "gnetId": 13756,
  "graphTooltip": 0,
  "id": null,
  "iteration": 1611099647798,
  "links": [],
  "panels": [
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_PROMETHEUS_(VLEI)}",
      "decimals": 0,
      "description": "Lines of Code",
      "fill": 1,
      "gridPos": {
        "h": 9,
        "w": 7,
        "x": 0,
        "y": 0
      },
      "id": 3,
      "legend": {
        "avg": false,
        "current": true,
        "max": true,
        "min": true,
        "show": true,
        "total": false,
        "values": true
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "null",
      "percentage": false,
      "pointradius": 5,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "std_code_lines_code_total{job=~`${codebase:regex}`,file=~`${folderFilter:regex}\\/${fileFilter:regex}`}",
          "format": "time_series",
          "hide": false,
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "LoC {{file}}",
          "refId": "A"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "LoC by file (total)",
      "tooltip": {
        "shared": true,
        "sort": 2,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": 0,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "decimals": 0,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_PROMETHEUS_(VLEI)}",
      "decimals": 0,
      "description": "Cyclomatic Complexity",
      "fill": 1,
      "gridPos": {
        "h": 9,
        "w": 7,
        "x": 7,
        "y": 0
      },
      "id": 2,
      "legend": {
        "avg": false,
        "current": true,
        "max": true,
        "min": true,
        "show": true,
        "total": false,
        "values": true
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "null",
      "percentage": false,
      "pointradius": 5,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "std_code_complexity_cyclomatic_total{job=~`${codebase:regex}`,file=~`${folderFilter:regex}\\/${fileFilter:regex}`}",
          "format": "time_series",
          "intervalFactor": 1,
          "legendFormat": "CC {{file}}",
          "refId": "C"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "CC by file (total)",
      "tooltip": {
        "shared": true,
        "sort": 2,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": 0,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "decimals": 0,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_PROMETHEUS_(VLEI)}",
      "decimals": null,
      "description": "Cyclomatic Complexity Density",
      "fill": 0,
      "gridPos": {
        "h": 9,
        "w": 10,
        "x": 14,
        "y": 0
      },
      "id": 9,
      "legend": {
        "avg": false,
        "current": true,
        "max": true,
        "min": true,
        "show": true,
        "total": false,
        "values": true
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "null",
      "percentage": false,
      "pointradius": 5,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "std_code_complexity_cyclomatic_total{job=~`${codebase:regex}`,file=~`${folderFilter:regex}\\/${fileFilter:regex}`} / std_code_lines_code_total{job=~`${codebase:regex}`,file=~`${folderFilter:regex}\\/${fileFilter:regex}`}",
          "format": "time_series",
          "intervalFactor": 1,
          "legendFormat": "CC {{file}}",
          "refId": "C"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "CCD by file (total)",
      "tooltip": {
        "shared": true,
        "sort": 2,
        "value_type": "individual"
      },
      "transparent": true,
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": null,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "decimals": null,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_PROMETHEUS_(VLEI)}",
      "decimals": 0,
      "description": "Lines of Code",
      "fill": 1,
      "gridPos": {
        "h": 11,
        "w": 7,
        "x": 0,
        "y": 9
      },
      "id": 7,
      "legend": {
        "avg": false,
        "current": false,
        "hideZero": false,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "minSpan": 3,
      "nullPointMode": "null",
      "percentage": true,
      "pointradius": 5,
      "points": false,
      "renderer": "flot",
      "repeatDirection": "v",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "std_code_lines_code{job=~`${codebase:regex}`,file=~`${folderFilter:regex}\\/${fileFilter:regex}`}",
          "format": "time_series",
          "hide": false,
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{file}}:{{region}}",
          "refId": "A"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "LoC (region distribution)",
      "tooltip": {
        "shared": true,
        "sort": 2,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": 0,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "decimals": 0,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_PROMETHEUS_(VLEI)}",
      "decimals": 0,
      "description": "Cyclomatic Complexity",
      "fill": 1,
      "gridPos": {
        "h": 11,
        "w": 7,
        "x": 7,
        "y": 9
      },
      "id": 8,
      "legend": {
        "avg": false,
        "current": false,
        "hideZero": false,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "null",
      "percentage": true,
      "pointradius": 5,
      "points": false,
      "renderer": "flot",
      "repeatDirection": null,
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "std_code_complexity_cyclomatic{job=~`${codebase:regex}`,file=~`${folderFilter:regex}\\/${fileFilter:regex}`}",
          "format": "time_series",
          "hide": false,
          "intervalFactor": 1,
          "legendFormat": "{{file}}:{{region}}",
          "refId": "A"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "CC (region distribution)",
      "tooltip": {
        "shared": true,
        "sort": 2,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": 0,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "decimals": 0,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_PROMETHEUS_(VLEI)}",
      "decimals": 9,
      "description": "Cyclomatic Complexity Density",
      "fill": 0,
      "gridPos": {
        "h": 11,
        "w": 10,
        "x": 14,
        "y": 9
      },
      "id": 10,
      "legend": {
        "avg": false,
        "current": false,
        "hideZero": false,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "null",
      "percentage": true,
      "pointradius": 5,
      "points": false,
      "renderer": "flot",
      "repeatDirection": null,
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "std_code_complexity_cyclomatic{job=~`${codebase:regex}`,file=~`${folderFilter:regex}\\/${fileFilter:regex}`} / std_code_lines_code{job=~`${codebase:regex}`,file=~`${folderFilter:regex}\\/${fileFilter:regex}`}",
          "format": "time_series",
          "hide": false,
          "intervalFactor": 1,
          "legendFormat": "{{file}}:{{region}}",
          "refId": "A"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "CCD (region distribution)",
      "tooltip": {
        "shared": true,
        "sort": 2,
        "value_type": "individual"
      },
      "transparent": true,
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": null,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "decimals": null,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_PROMETHEUS_(VLEI)}",
      "decimals": 0,
      "description": "Lines of Code",
      "fill": 1,
      "gridPos": {
        "h": 11,
        "w": 7,
        "x": 0,
        "y": 20
      },
      "id": 6,
      "legend": {
        "avg": false,
        "current": false,
        "hideZero": true,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "minSpan": 3,
      "nullPointMode": "null",
      "percentage": false,
      "pointradius": 5,
      "points": false,
      "renderer": "flot",
      "repeat": null,
      "repeatDirection": "v",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "delta(std_code_lines_code{job=~`${codebase:regex}`,file=~`${folderFilter:regex}\\/${fileFilter:regex}`}[$deltaTimeRange])",
          "format": "time_series",
          "hide": false,
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{file}}:{{region}}",
          "refId": "A"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "LoC by region (deviation)",
      "tooltip": {
        "shared": true,
        "sort": 2,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": 0,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "decimals": 0,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_PROMETHEUS_(VLEI)}",
      "decimals": 0,
      "description": "Cyclomatic Complexity",
      "fill": 1,
      "gridPos": {
        "h": 11,
        "w": 7,
        "x": 7,
        "y": 20
      },
      "id": 4,
      "legend": {
        "avg": false,
        "current": false,
        "hideZero": true,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "null",
      "percentage": false,
      "pointradius": 5,
      "points": false,
      "renderer": "flot",
      "repeat": null,
      "repeatDirection": null,
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "delta(std_code_complexity_cyclomatic{job=~`${codebase:regex}`,file=~`${folderFilter:regex}\\/${fileFilter:regex}`}[$deltaTimeRange])",
          "format": "time_series",
          "hide": false,
          "intervalFactor": 1,
          "legendFormat": "{{file}}:{{region}}",
          "refId": "A"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "CC by region (deviation)",
      "tooltip": {
        "shared": true,
        "sort": 2,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": 0,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "decimals": 0,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    }
  ],
  "refresh": false,
  "schemaVersion": 16,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "allValue": ".*",
        "current": {},
        "datasource": "${DS_PROMETHEUS_(VLEI)}",
        "definition": "label_values(std_code_lines_code_total{},job)",
        "hide": 0,
        "includeAll": false,
        "label": "Codebase",
        "multi": false,
        "name": "codebase",
        "options": [],
        "query": "label_values(std_code_lines_code_total{},job)",
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": ".*",
        "current": {},
        "datasource": "${DS_PROMETHEUS_(VLEI)}",
        "definition": "label_values(std_code_complexity_cyclomatic_avg{job=~\"$codebase\",file!~`.*(cpp|h|java)`},file)",
        "hide": 0,
        "includeAll": false,
        "label": "Folder",
        "multi": true,
        "name": "folderFilter",
        "options": [],
        "query": "label_values(std_code_complexity_cyclomatic_avg{job=~\"$codebase\",file!~`.*(cpp|h|java)`},file)",
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": ".*",
        "current": {},
        "datasource": "${DS_PROMETHEUS_(VLEI)}",
        "definition": "label_values(std_code_complexity_cyclomatic_avg{job=~\"$codebase\",file=~`${folderFilter:regex}\\/[^/]*(cpp|h|java)`},file)",
        "hide": 0,
        "includeAll": false,
        "label": "File",
        "multi": true,
        "name": "fileFilter",
        "options": [],
        "query": "label_values(std_code_complexity_cyclomatic_avg{job=~\"$codebase\",file=~`${folderFilter:regex}\\/[^/]*(cpp|h|java)`},file)",
        "refresh": 2,
        "regex": "/.([^\\/]*\\.(cpp|h|java))/",
        "skipUrlSync": false,
        "sort": 1,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {
          "tags": [],
          "text": "1h",
          "value": "1h"
        },
        "hide": 0,
        "includeAll": false,
        "label": "Delta time range",
        "multi": false,
        "name": "deltaTimeRange",
        "options": [
          {
            "selected": false,
            "text": "1m",
            "value": "1m"
          },
          {
            "selected": true,
            "text": "1h",
            "value": "1h"
          },
          {
            "selected": false,
            "text": "1d",
            "value": "1d"
          },
          {
            "selected": false,
            "text": "1w",
            "value": "1w"
          }
        ],
        "query": "1m, 1h, 1d, 1w",
        "skipUrlSync": false,
        "type": "custom"
      }
    ]
  },
  "time": {
    "from": "now-7d",
    "to": "now"
  },
  "timepicker": {
    "refresh_intervals": [
      "5s",
      "10s",
      "30s",
      "1m",
      "5m",
      "15m",
      "30m",
      "1h",
      "2h",
      "1d"
    ],
    "time_options": [
      "5m",
      "15m",
      "1h",
      "6h",
      "12h",
      "24h",
      "2d",
      "7d",
      "30d"
    ]
  },
  "timezone": "",
  "title": "CodeQuality by Metrix++ 3:File",
  "uid": "RYTpg2Jqb",
  "version": 8,
  "description": "Visualize code quality metrics LoC (Lines of Code), CC (Cyclomatic Complexity) and resulting CCD (Cyclomatic Complexity Density) collected for your codebase by Metrix++ in Prometheus"
}