1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/fastos/fastos.h>
#include "simple_metric_snapshot.h"
namespace vespalib {
SimpleMetricSnapshot::SimpleMetricSnapshot(uint32_t prevTime, uint32_t currTime)
: _data(),
_metrics(_data.setObject()),
_values(_metrics.setArray("values")),
_snapLen(currTime - prevTime)
{
vespalib::slime::Cursor& snapshot = _metrics.setObject("snapshot");
snapshot.setLong("from", prevTime);
snapshot.setLong("to", currTime);
if (_snapLen < 1.0) {
_snapLen = 1.0;
}
}
void
SimpleMetricSnapshot::addCount(const char *name, const char *desc, uint32_t count)
{
using namespace vespalib::slime::convenience;
Cursor& value = _values.addObject();
value.setString("name", name);
value.setString("description", desc);
Cursor& inner = value.setObject("values");
inner.setLong("count", count);
inner.setDouble("rate", count / _snapLen);
}
void
SimpleMetricSnapshot::addGauge(const char *name, const char *desc, long gauge)
{
using namespace vespalib::slime::convenience;
Cursor& value = _values.addObject();
value.setString("name", name);
value.setString("description", desc);
Cursor& inner = value.setObject("values");
inner.setLong("average", gauge);
inner.setLong("min", gauge);
inner.setLong("max", gauge);
inner.setLong("last", gauge);
inner.setLong("count", 1);
inner.setDouble("rate", 1.0 / _snapLen);
}
} // namespace vespalib
|