aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/common/statusmetricconsumer.h
blob: a59d9cfaa95018f644167b284a9e8a9435fc3fb3 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

/**
 * @class storage::StatusMetricConsumer
 * @ingroup common
 *
 * @brief Writes metrics to status page.
 */

#pragma once

#include "storagecomponent.h"
#include <vespa/storageframework/generic/status/statusreporter.h>
#include <vespa/vespalib/util/jsonstream.h>

namespace vespalib { class StringTokenizer; }
namespace metrics { class MetricManager; }

namespace storage {

class StatusMetricConsumer : public framework::StatusReporter,
                             private vespalib::JsonStreamTypes
{
public:
    StatusMetricConsumer(StorageComponentRegister&, metrics::MetricManager&, const std::string& name = "status");
    ~StatusMetricConsumer() override;

    // Metric reporting requires the "vespa.content.metrics_api" capability
    CapabilitySet required_capabilities() const noexcept override {
        return CapabilitySet::of({ Capability::content_metrics_api() });
    }
    vespalib::string getReportContentType(const framework::HttpUrlPath&) const override;
    bool reportStatus(std::ostream& out, const framework::HttpUrlPath&) const override;
private:
    metrics::MetricManager& _manager;
    StorageComponent        _component;
    std::string             _name;
    mutable std::mutex      _lock;
};

} // storage