aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/persistence/filestorage/service_layer_host_info_reporter.h
blob: 5f15c3e66a260504ad39f5c234758eb570607d78 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/persistence/spi/resource_usage_listener.h>
#include <vespa/storage/common/hostreporter/hostreporter.h>
#include <atomic>
#include <mutex>

namespace storage {

struct NodeStateUpdater;

/*
 * Host info reporter for service layer that provides resource usage.
 */
class ServiceLayerHostInfoReporter : public HostReporter,
                                     public spi::ResourceUsageListener
{
    NodeStateUpdater&  _node_state_updater;
    std::mutex         _lock;
    spi::ResourceUsage _old_resource_usage;
    std::atomic<double> _noise_level;

    void update_resource_usage(const spi::ResourceUsage& resource_usage) override;
public:
    ServiceLayerHostInfoReporter(NodeStateUpdater& node_state_updater,
                                 double noise_level = 0.001);

    ServiceLayerHostInfoReporter(const ServiceLayerHostInfoReporter&) = delete;
    ServiceLayerHostInfoReporter& operator=(const ServiceLayerHostInfoReporter&) = delete;
    ~ServiceLayerHostInfoReporter() override;

    void set_noise_level(double level);
    void report(vespalib::JsonStream& output) override;
    const spi::ResourceUsage &get_old_resource_usage() noexcept { return _old_resource_usage; }
};

}