]>
Commit | Line | Data |
---|---|---|
d5c9e1cb PL |
1 | /* |
2 | * This file is part of PowerDNS or dnsdist. | |
3 | * Copyright -- PowerDNS.COM B.V. and its contributors | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of version 2 of the GNU General Public License as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * In addition, for the avoidance of any doubt, permission is granted to | |
10 | * link this program with OpenSSL and to (re)distribute the binaries | |
11 | * produced as the result of such linking. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
21 | */ | |
22 | #include "ixfrdist-web.hh" | |
23 | #include <thread> | |
24 | #include "threadname.hh" | |
9f517da5 | 25 | #include "iputils.hh" |
d5c9e1cb PL |
26 | #include "ixfrdist-stats.hh" |
27 | ||
28 | string doGetStats(); | |
29 | ||
f6149229 | 30 | IXFRDistWebServer::IXFRDistWebServer(const ComboAddress &listenAddress, const NetmaskGroup &acl, const string &loglevel) : |
8a70e507 CHB |
31 | d_ws(std::unique_ptr<WebServer>(new WebServer(listenAddress.toString(), listenAddress.getPort()))) |
32 | { | |
9f517da5 | 33 | d_ws->setACL(acl); |
f6149229 | 34 | d_ws->setLogLevel(loglevel); |
6f4d2df1 | 35 | d_ws->registerWebHandler("/metrics", boost::bind(&IXFRDistWebServer::getMetrics, this, _1, _2)); |
d5c9e1cb PL |
36 | d_ws->bind(); |
37 | } | |
38 | ||
39 | void IXFRDistWebServer::go() { | |
d5c9e1cb | 40 | setThreadName("ixfrdist/web"); |
6f4d2df1 | 41 | d_ws->go(); |
d5c9e1cb PL |
42 | } |
43 | ||
44 | void IXFRDistWebServer::getMetrics(HttpRequest* req, HttpResponse* resp) { | |
45 | if(req->method != "GET") | |
46 | throw HttpMethodNotAllowedException(); | |
47 | ||
48 | resp->body = doGetStats(); | |
256d1820 | 49 | resp->headers["Content-Type"] = "text/plain; version=0.0.4"; // https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format |
d5c9e1cb PL |
50 | resp->status = 200; |
51 | } |