| 84 | |
| 85 | template <typename T, TMetricKind::type metric_kind_t> |
| 86 | TMetricKind::type ScalarMetric<T, metric_kind_t>::ToPrometheus( |
| 87 | string name, stringstream* val, stringstream* metric_kind) { |
| 88 | string metric_type = PrintValue(kind()); |
| 89 | // prometheus doesn't support 'property', so ignore it |
| 90 | if (!metric_type.compare("property")) { |
| 91 | return TMetricKind::PROPERTY; |
| 92 | } |
| 93 | |
| 94 | if (IsUnitTimeBased(unit())) { |
| 95 | // check if unit its 'TIME_MS','TIME_US' or 'TIME_NS' and convert it to seconds, |
| 96 | // this is because prometheus only supports time format in seconds |
| 97 | *val << ConvertToPrometheusSecs(GetValue(), unit()); |
| 98 | } else { |
| 99 | *val << GetValue(); |
| 100 | } |
| 101 | |
| 102 | // convert metric type to lower case, that's what prometheus expects |
| 103 | std::transform(metric_type.begin(), metric_type.end(), metric_type.begin(), ::tolower); |
| 104 | |
| 105 | *metric_kind << "# TYPE " << name << " " << metric_type; |
| 106 | return kind(); |
| 107 | } |
| 108 | |
| 109 | template <typename T, TMetricKind::type metric_kind_t> |
| 110 | string ScalarMetric<T, metric_kind_t>::ToHumanReadable() { |