-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add InfluxDB 2.x optional backend (#193)
* Add CURL to deps list * Add URL parsing * First working version * Clean up and docs
- Loading branch information
Showing
7 changed files
with
178 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/// | ||
/// \file HTTP.cxx | ||
/// \author Adam Wegrzynek <[email protected]> | ||
/// | ||
|
||
#include "HTTP.h" | ||
#include "../MonLogger.h" | ||
#include "../Exceptions/MonitoringException.h" | ||
#include <boost/algorithm/string.hpp> | ||
|
||
namespace o2 | ||
{ | ||
/// ALICE O2 Monitoring system | ||
namespace monitoring | ||
{ | ||
/// Monitoring transports | ||
namespace transports | ||
{ | ||
|
||
HTTP::HTTP(const std::string& url) | ||
{ | ||
mHeaders = NULL; | ||
mCurl = curl_easy_init(); | ||
curl_easy_setopt(mCurl, CURLOPT_URL, url.c_str()); | ||
curl_easy_setopt(mCurl, CURLOPT_SSL_VERIFYPEER, 0); | ||
curl_easy_setopt(mCurl, CURLOPT_CONNECTTIMEOUT, 10); | ||
curl_easy_setopt(mCurl, CURLOPT_TIMEOUT, 10); | ||
curl_easy_setopt(mCurl, CURLOPT_POST, 1); | ||
curl_easy_setopt(mCurl, CURLOPT_TCP_KEEPIDLE, 120L); | ||
curl_easy_setopt(mCurl, CURLOPT_TCP_KEEPINTVL, 60L); | ||
FILE *devnull = fopen("/dev/null", "w+"); | ||
curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, devnull); | ||
|
||
MonLogger::Get() << "HTTP transport initialized (" << url << ")" << MonLogger::End(); | ||
} | ||
|
||
HTTP::~HTTP() | ||
{ | ||
curl_slist_free_all(mHeaders); | ||
curl_easy_cleanup(mCurl); | ||
curl_global_cleanup(); | ||
} | ||
|
||
void HTTP::addHeader(const std::string& header) | ||
{ | ||
mHeaders = curl_slist_append(mHeaders, header.c_str()); | ||
curl_easy_setopt(mCurl, CURLOPT_HTTPHEADER, mHeaders); | ||
} | ||
|
||
void HTTP::send(std::string&& post) | ||
{ | ||
CURLcode response; | ||
long responseCode; | ||
curl_easy_setopt(mCurl, CURLOPT_POSTFIELDS, post.c_str()); | ||
curl_easy_setopt(mCurl, CURLOPT_POSTFIELDSIZE, (long) post.length()); | ||
response = curl_easy_perform(mCurl); | ||
curl_easy_getinfo(mCurl, CURLINFO_RESPONSE_CODE, &responseCode); | ||
if (response != CURLE_OK) { | ||
MonLogger::Get() << "HTTP Tranport " << curl_easy_strerror(response) << MonLogger::End(); | ||
} | ||
if (responseCode < 200 || responseCode > 206) { | ||
MonLogger::Get() << "HTTP Transport: Response code : " << std::to_string(responseCode) << MonLogger::End(); | ||
} | ||
} | ||
|
||
} // namespace transports | ||
} // namespace monitoring | ||
} // namespace o2 |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/// | ||
/// \file HTTP.h | ||
/// \author Adam Wegrzynek <[email protected]> | ||
/// | ||
|
||
#ifndef ALICEO2_MONITORING_TRANSPORTS_HTTP_H | ||
#define ALICEO2_MONITORING_TRANSPORTS_HTTP_H | ||
|
||
#include "TransportInterface.h" | ||
|
||
#include <curl/curl.h> | ||
#include <string> | ||
|
||
namespace o2 | ||
{ | ||
/// ALICE O2 Monitoring system | ||
namespace monitoring | ||
{ | ||
/// Monitoring transports | ||
namespace transports | ||
{ | ||
|
||
/// \brief HTTP POST transport | ||
/// | ||
/// Allows to push string formatted metrics as HTTP POST requests via cURL | ||
class HTTP : public TransportInterface | ||
{ | ||
public: | ||
/// Constructor | ||
/// \param url URL of HTTP server endpoint | ||
HTTP(const std::string& url); | ||
|
||
/// Destructor | ||
~HTTP(); | ||
|
||
/// Sends metric via HTTP POST | ||
/// \param post r-value reference string formatted metric | ||
void send(std::string&& post); | ||
|
||
/// Adds custom HTTP header | ||
void addHeader(const std::string& header); | ||
private: | ||
/// CURL pointers | ||
CURL *mCurl; | ||
|
||
/// HTTP headers struct | ||
struct curl_slist *mHeaders; | ||
}; | ||
|
||
} // namespace transports | ||
} // namespace monitoring | ||
} // namespace o2 | ||
|
||
#endif // ALICEO2_MONITORING_TRANSPORTS_HTTP_H |
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