summaryrefslogtreecommitdiffstats
path: root/logd/src/logd/state.cpp
blob: 232c300befa715003b665039846f0a2017fc069e (plain) (blame)
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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/log/log.h>
LOG_SETUP("");

#include "state.h"
#include <vespa/vespalib/metrics/simple_metrics_collector.h>

namespace logdemon {

vespalib::metrics::CollectorConfig minute()
{
    vespalib::metrics::CollectorConfig conf;
    conf.sliding_window_seconds = 60;
    return conf;
}


StateReporter::StateReporter()
    : _port(-1),
      _server(),
      _health(),
      _components(),
      _metrics(vespalib::metrics::SimpleMetricsCollector::create(minute())),
      _producer(_metrics)
{
}

void
StateReporter::setStatePort(int statePort)
{
    if (statePort != _port) {
        _port = statePort;
        _server.reset(new vespalib::StateServer(_port, _health, _producer, _components));
        LOG(info, "state server listening on port %d", _server->getListenPort());
    }
}

void
StateReporter::gotConf(size_t generation)
{
    vespalib::ComponentConfigProducer::Config conf("logd", generation);
    _components.addConfig(conf);
}

} // namespace