Open paffosx opened 1 year ago
You should register the registry in the exposer only once and prior to your while-loop. For debugging I'd suggest that you set some breakpoints in the exposer code like here: https://github.com/jupp0r/prometheus-cpp/blob/99e4d5085e4557fc9f3bea8db0c69bb1727c3d56/pull/src/exposer.cc#L54
But if I look at the complexity with an SSH access to a remote machine, I wonder if installing something like Telegraf on the remote machine would be the easier option. Telegraf is a statically linked Go binary with no dependencies and easy to handle.
Hello everyone. I am writing code to remove metrics from a remote server and output them to localhost:9091. My problem is that I can't understand why the metrics are not displayed on localhost:9091 despite the fact that there is a connection to the server and the removed metrics are selected in the console. Who is not difficult to help or tell me how to solve my problem. my code:
include <libssh/libssh.h>
include <prometheus/registry.h>
include <prometheus/exposer.h>
include <prometheus/counter.h>
include <prometheus/gauge.h>
include
include
include
include
include
include "string.h"
// Function to execute a command on an SSH channel and return the output std::string execute_ssh_command(ssh_session session, const std::string& command) { ssh_channel channel = ssh_channel_new(session); if (channel == NULL) { throw std::runtime_error("Error creating SSH channel"); } if (ssh_channel_open_session(channel) != SSH_OK) { throw std::runtime_error("Error opening SSH channel"); } if (ssh_channel_request_exec(channel, command.c_str()) != SSH_OK) { throw std::runtime_error("Error executing SSH command"); } char buffer[256]; std::stringstream output; while (ssh_channel_read(channel, buffer, sizeof(buffer), 0) > 0) { output << buffer; } ssh_channel_send_eof(channel); ssh_channel_close(channel); ssh_channel_free(channel); return output.str(); }
int verify_knownhost(ssh_session session) { enum ssh_known_hosts_e state; unsigned char hash = NULL; ssh_key srv_pubkey = NULL; size_t hlen; char buf[10]; char hexa; char *p; int cmp; int rc;
}
int main() {
if (verify_knownhost(session) < 0) { ssh_disconnect(session); ssh_free(session); exit(-1); }
}
}