Loading...
Searching...
No Matches
prometheus_handler.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <glog/logging.h>
23#include <prometheus/counter.h>
24#include <prometheus/exposer.h>
25#include <prometheus/registry.h>
26
27namespace resdb {
28
38
52
54 public:
55 PrometheusHandler(const std::string& server_address);
57
58 void Set(MetricName name, double value);
59 void Inc(MetricName name, double value);
60
61 protected:
62 void Register();
63 void RegisterTable(const std::string& name);
64 void RegisterMetric(const std::string& table_name,
65 const std::string& metric_name);
66
67 private:
68 typedef prometheus::Family<prometheus::Gauge> gbuilder;
69 typedef prometheus::Gauge gmetric;
70
71 std::unique_ptr<prometheus::Exposer, std::default_delete<prometheus::Exposer>>
72 exposer_;
73 std::shared_ptr<prometheus::Registry> registry_;
74
75 std::map<std::string, gbuilder*> gauge_;
76 std::map<std::string, gmetric*> metric_;
77};
78
79} // namespace resdb
void Inc(MetricName name, double value)
void RegisterMetric(const std::string &table_name, const std::string &metric_name)
void Set(MetricName name, double value)
void RegisterTable(const std::string &name)