| 23 | |
| 24 | |
| 25 | def _build_full_name(metric_type, name, namespace, subsystem, unit): |
| 26 | if not name: |
| 27 | raise ValueError('Metric name should not be empty') |
| 28 | full_name = '' |
| 29 | if namespace: |
| 30 | full_name += namespace + '_' |
| 31 | if subsystem: |
| 32 | full_name += subsystem + '_' |
| 33 | full_name += name |
| 34 | if metric_type == 'counter' and full_name.endswith('_total'): |
| 35 | full_name = full_name[:-6] # Munge to OpenMetrics. |
| 36 | if unit and not full_name.endswith("_" + unit): |
| 37 | full_name += "_" + unit |
| 38 | if unit and metric_type in ('info', 'stateset'): |
| 39 | raise ValueError('Metric name is of a type that cannot have a unit: ' + full_name) |
| 40 | return full_name |
| 41 | |
| 42 | |
| 43 | |