36 #if defined(__APPLE__) || defined(__sun__) || defined(__FreeBSD__)
37 #include <arpa/inet.h>
38 #include <netinet/ip.h>
42 #include <netinet/in.h>
43 #include <netinet/tcp.h>
45 #include <sys/socket.h>
46 #include <sys/types.h>
47 #include <arpa/inet.h>
59 m_port = props->get_i16(
"Hypertable.Metrics.Ganglia.Port");
61 m_disabled = props->get_bool(
"Hypertable.Metrics.Ganglia.Disable");
63 m_prefix =
"ht." + component +
".";
65 if ((m_sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
66 HT_FATALF(
"socket(AF_INET, SOCK_DGRAM, 0) failure - %s", strerror(errno));
70 #if defined(__linux__)
72 setsockopt(m_sd, SOL_IP, IP_TOS, &opt,
sizeof(opt));
74 setsockopt(m_sd, SOL_SOCKET, SO_PRIORITY, &opt,
sizeof(opt));
75 #elif defined(__APPLE__) || defined(__sun__) || defined(__FreeBSD__)
77 setsockopt(m_sd, IPPROTO_IP, IP_TOS, &opt,
sizeof(opt));
81 if ((::bind(m_sd, (
const sockaddr *)&local_addr,
sizeof(sockaddr_in))) < 0)
82 HT_FATALF(
"bind(%s) failure - %s", local_addr.
format().c_str(), strerror(errno));
91 lock_guard<mutex> lock(m_mutex);
92 m_values_string[m_prefix + name] = value;
96 lock_guard<mutex> lock(m_mutex);
97 m_values_int[m_prefix + name] = (int32_t)value;
101 lock_guard<mutex> lock(m_mutex);
102 m_values_int[m_prefix + name] = value;
106 lock_guard<mutex> lock(m_mutex);
107 m_values_double[m_prefix + name] = (double)value;
111 lock_guard<mutex> lock(m_mutex);
112 m_values_double[m_prefix + name] = value;
116 lock_guard<mutex> lock(m_mutex);
128 m_message.append(
"{ ");
130 for (
auto & entry : m_values_string) {
132 m_message.append(
", \"");
134 m_message.append(
"\"");
137 m_message.append(entry.first);
138 m_message.append(
"\": \"");
139 m_message.append(entry.second);
140 m_message.append(
"\"");
143 for (
auto & entry : m_values_int) {
145 m_message.append(
", \"");
147 m_message.append(
"\"");
150 m_message.append(entry.first);
151 m_message.append(
"\": ");
152 sprintf(cbuf,
"%d", entry.second);
153 m_message.append(cbuf);
156 for (
auto & entry : m_values_double) {
158 m_message.append(
", \"");
160 m_message.append(
"\"");
163 m_message.append(entry.first);
164 m_message.append(
"\": ");
165 sprintf(cbuf,
"%f", entry.second);
166 m_message.append(cbuf);
169 m_message.append(
" }");
171 if (::send(m_sd, m_message.c_str(), m_message.length(), 0) < 0)
178 if (::connect(m_sd, (
struct sockaddr *) &addr,
sizeof(sockaddr_in)) < 0) {
Declarations for MetricsCollectorGanglia.
~MetricsCollectorGanglia()
Destructor.
Encapsulate an internet address.
std::shared_ptr< Properties > PropertiesPtr
Logging routines and macros.
Compatibility Macros for C/C++.
String format(int sep= ':') const
Returns a string with a dotted notation ("127.0.0.1:8080") including the port.
void update(const std::string &name, const std::string &value) override
Updates string metric value.
#define HT_FATALF(msg,...)
void connect()
Connects to Ganglia hypertable extension receive port.
MetricsCollectorGanglia(const std::string &component, PropertiesPtr &props)
Constructor.
Internet address wrapper classes and utility functions.
#define HT_THROW(_code_, _msg_)
void publish() override
Publishes metric values to Ganglia hypertable extension.