GetDatum returns the datum named by a sequence of string label values from a Metric. If the sequence of label values does not yet exist, it is created.
(labelvalues ...string)
| 149 | // GetDatum returns the datum named by a sequence of string label values from a |
| 150 | // Metric. If the sequence of label values does not yet exist, it is created. |
| 151 | func (m *Metric) GetDatum(labelvalues ...string) (d datum.Datum, err error) { |
| 152 | if len(labelvalues) != len(m.Keys) { |
| 153 | return nil, errors.Errorf("Label values requested (%q) not same length as keys for metric %v", labelvalues, m) |
| 154 | } |
| 155 | m.Lock() |
| 156 | defer m.Unlock() |
| 157 | if lv := m.FindLabelValueOrNil(labelvalues); lv != nil { |
| 158 | d = lv.Value |
| 159 | } else { |
| 160 | // TODO Check m.Limit and expire old data |
| 161 | switch m.Type { |
| 162 | case Int: |
| 163 | d = datum.NewInt() |
| 164 | case Float: |
| 165 | d = datum.NewFloat() |
| 166 | case String: |
| 167 | d = datum.NewString() |
| 168 | case Buckets: |
| 169 | buckets := m.Buckets |
| 170 | if buckets == nil { |
| 171 | buckets = make([]datum.Range, 0) |
| 172 | } |
| 173 | d = datum.NewBuckets(buckets) |
| 174 | } |
| 175 | lv := &LabelValue{Labels: labelvalues, Value: d} |
| 176 | if err := m.AppendLabelValue(lv); err != nil { |
| 177 | return nil, err |
| 178 | } |
| 179 | } |
| 180 | return d, nil |
| 181 | } |
| 182 | |
| 183 | // RemoveOldestDatum scans the Metric's LabelValues for the Datum with the oldest timestamp, and removes it. |
| 184 | func (m *Metric) RemoveOldestDatum() { |