-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
163 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,75 @@ | ||
/* | ||
Copyright The Overlaybd Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "config.h" | ||
#include "exporter_handler.h" | ||
#include "metrics_fs.h" | ||
#include <photon/common/metric-meter/metrics.h> | ||
#include <photon/net/http/server.h> | ||
#include <photon/net/socket.h> | ||
#include <photon/photon.h> | ||
#include <photon/thread/thread.h> | ||
#include <photon/thread/timer.h> | ||
#include <photon/thread/workerpool.h> | ||
#include <pthread.h> | ||
#include <sys/prctl.h> | ||
|
||
#include <thread> | ||
|
||
|
||
#include "config.h" | ||
#include "exporter_handler.h" | ||
#include "metrics_fs.h" | ||
|
||
class OverlayBDMetric { | ||
public: | ||
MetricMeta download; | ||
ExposeMetrics::ExposeRender exporter; | ||
MetricMeta pread, download; | ||
|
||
photon::Timer timer; | ||
uint64_t m_timeout = -1; | ||
ExposeMetrics::ExposeRender exporter; | ||
|
||
OverlayBDMetric() : timer(-1, {this, &OverlayBDMetric::on_timer}) { | ||
OverlayBDMetric() { | ||
exporter.add_throughput("pread", pread.throughput); | ||
exporter.add_latency("pread", pread.latency); | ||
exporter.add_qps("pread", pread.qps); | ||
exporter.add_count("pread", pread.total); | ||
exporter.add_throughput("download", download.throughput); | ||
exporter.add_latency("download", download.latency); | ||
exporter.add_qps("download", download.qps); | ||
exporter.add_count("download", download.total); | ||
} | ||
|
||
~OverlayBDMetric() { | ||
timer.cancel(); | ||
timer.stop(); | ||
} | ||
|
||
uint64_t on_timer() { | ||
return m_timeout; | ||
} | ||
|
||
uint64_t interval(uint64_t x) { return m_timeout = x; } | ||
uint64_t interval() { return m_timeout; } | ||
int start() { return timer.reset(0); } | ||
}; | ||
|
||
struct ExporterServer { | ||
photon::WorkPool wp; | ||
|
||
photon::net::http::HTTPServer *httpserver = nullptr; | ||
photon::net::ISocketServer *tcpserver = nullptr; | ||
|
||
bool ready = false; | ||
|
||
ExporterServer(ImageConfigNS::GlobalConfig &config, | ||
OverlayBDMetric *metrics) | ||
: wp(1, photon::INIT_EVENT_EPOLL, 0, 0) { | ||
wp.call([&] { | ||
prctl(PR_SET_THP_DISABLE, 1); | ||
pthread_setname_np(pthread_self(), "overlaybd-exporter"); | ||
char buffer[64]; | ||
snprintf(buffer, 63, "localhost:%d", config.exporterConfig().port()); | ||
metrics->exporter.nodename = buffer; | ||
|
||
tcpserver = photon::net::new_tcp_socket_server(); | ||
tcpserver->bind(config.exporterConfig().port(), photon::net::IPAddr("127.0.0.1")); | ||
|
||
tcpserver->listen(); | ||
httpserver = photon::net::http::new_http_server(); | ||
httpserver->add_handler(&metrics->exporter); | ||
tcpserver->set_handler(httpserver->get_connection_handler()); | ||
tcpserver->start_loop(); | ||
ready = true; | ||
}); | ||
OverlayBDMetric *metrics) { | ||
tcpserver = photon::net::new_tcp_socket_server(); | ||
tcpserver->setsockopt(SOL_SOCKET, SO_REUSEPORT, 1); | ||
if (tcpserver->bind(config.exporterConfig().port()) < 0) | ||
LOG_ERRNO_RETURN(0, , "Failed to bind exporter port `", | ||
config.exporterConfig().port()); | ||
if (tcpserver->listen() < 0) | ||
LOG_ERRNO_RETURN(0, , "Failed to listen exporter port `", | ||
config.exporterConfig().port()); | ||
httpserver = photon::net::http::new_http_server(); | ||
httpserver->add_handler(&metrics->exporter, false, | ||
config.exporterConfig().uriPrefix()); | ||
tcpserver->set_handler(httpserver->get_connection_handler()); | ||
tcpserver->start_loop(); | ||
ready = true; | ||
} | ||
|
||
~ExporterServer() { | ||
wp.call([&] { | ||
delete tcpserver; | ||
delete httpserver; | ||
}); | ||
delete tcpserver; | ||
delete httpserver; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.