FilterCrucialMetrics filters crucial metrics and also add cpu_count.
()
| 86 | |
| 87 | // FilterCrucialMetrics filters crucial metrics and also add cpu_count. |
| 88 | func (mfm *SimpleMetricMap) FilterCrucialMetrics() (ret map[string]float64) { |
| 89 | crucialMetricNameMap := map[string]string{ |
| 90 | "node_memory_MemAvailable_bytes": "mem_avail", |
| 91 | "node_load1": "load1", |
| 92 | "node_load5": "load5", |
| 93 | "node_load15": "load15", |
| 94 | "node_ntp_offset_seconds": "ntp_offset", |
| 95 | "node_filesystem_free_bytes": "fs_avail", |
| 96 | "node_cpu_count": "cpu_count", |
| 97 | } |
| 98 | ret = make(map[string]float64) |
| 99 | for _, v := range *mfm { |
| 100 | if newName, ok := crucialMetricNameMap[*v.Name]; ok { |
| 101 | var metricVal float64 |
| 102 | switch v.GetType() { |
| 103 | case dto.MetricType_GAUGE: |
| 104 | metricVal = v.GetMetric()[0].GetGauge().GetValue() |
| 105 | case dto.MetricType_COUNTER: |
| 106 | metricVal = v.GetMetric()[0].GetCounter().GetValue() |
| 107 | case dto.MetricType_HISTOGRAM: |
| 108 | metricVal = v.GetMetric()[0].GetHistogram().GetBucket()[0].GetUpperBound() |
| 109 | case dto.MetricType_SUMMARY: |
| 110 | metricVal = v.GetMetric()[0].GetSummary().GetQuantile()[0].GetValue() |
| 111 | case dto.MetricType_UNTYPED: |
| 112 | metricVal = v.GetMetric()[0].GetUntyped().GetValue() |
| 113 | default: |
| 114 | continue |
| 115 | } |
| 116 | ret[newName] = metricVal |
| 117 | } |
| 118 | } |
| 119 | log.Debugf("crucial Metric added: %v", ret) |
| 120 | |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | // GetCrucialMetrics gets NodeCrucialMetricMap from NodeMetricMap. |
| 125 | func (nmm *NodeMetricMap) GetCrucialMetrics() (ret NodeCrucialMetricMap) { |
no test coverage detected