metrics are not displayed on localhost:9091

188 Views Asked by At

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.

I guess the problem is related to this part of the code:


    //creating the prometheus registry



    auto registry = std::make_shared<prometheus::Registry>();


    auto& ram_usage_gauge = prometheus::BuildGauge()
                               .Name("node_memory_usage_bytes")
                               .Help("RAM usage")
                               .Register(*registry);


    prometheus::Exposer exposer{"localhost:9091"};
    // collecting indicators every 1 seconds
    while (true) {
    try {
        // getting data about RAM on the server
        std::string output = execute_ssh_command(session, "free | grep Mem | awk '{print $3}'");
        int node_memory_usage_bytes = std::stoi(output);
        std::cout<< node_memory_usage_bytes<< std::endl;
        ram_usage_gauge.Add({{"name","id"}})
            .Set(node_memory_usage_bytes);
    } catch (std::exception& e) {
        std::cerr << "Error getting RAM usage: " << e.what() << std::endl;
    }
    // transferring metrics to port 9091

    

    exposer.RegisterCollectable(registry);
    
    std::this_thread::sleep_for(std::chrono::seconds(1));
}


in the prometheus-cpp documentation (https://jupp0r.github.io/prometheus-cpp /) nothing worthwhile has been written.

0

There are 0 best solutions below