package peergos.server;

import io.prometheus.client.Counter;
import io.prometheus.client.exporter.HTTPServer;

import java.io.IOException;

/**
 * A wrapper around the prometheus metrics and HTTP exporter.
 */
public class AggregatedMetrics {
    private static Counter build(String name, String help) {
        return Counter.build()
                .name(name).help(help).register();
    }

    public static final Counter FOLLOW_REQUEST_COUNTER = build("send_follow_request_total","Total follow requests.");
    public static final Counter GET_FOLLOW_REQUEST_COUNTER = build("get_follow_request_counter", "Total get follow request calls.");
    public static final Counter REMOVE_FOLLOW_REQUEST_COUNTER = build("remove_follow_request_counter", "Total remove follow request calls.");

    public static final Counter PUBLIC_FILE_COUNTER = build("public_file_counter", "Total public files.");

    public static final Counter DHT_ID  = build("dht_id", "Total id calls.");
    public static final Counter DHT_BLOCK_PUT  = build("dht_block_put", "Total DHT block puts.");
    public static final Counter DHT_BLOCK_GET  = build("dht_block_get", "Total DHT block gets.");
    public static final Counter DHT_BLOCK_STAT  = build("dht_block_stat", "Total DHT block stats.");
    public static final Counter DHT_BLOCK_REFS  = build("dht_block_refs", "Total DHT block refs.");
    public static final Counter DHT_TRANSACTION_START  = build("dht_transaction_start", "Total DHT transaction starts.");
    public static final Counter DHT_TRANSACTION_CLOSE  = build("dht_transaction_close", "Total DHT transaction closes.");

    public static final Counter MUTABLE_POINTERS_SET  = build("mutable_pointers_set", "Total mutable-pointers set calls.");
    public static final Counter MUTABLE_POINTERS_GET  = build("mutable_pointers_get", "Total mutable-pointers get calls.");

    public static final Counter GET_ALL_USERNAMES  = build("core_node_get_all_usernames", "Total get-all-usernames calls.");
    public static final Counter GET_USERNAME  = build("core_node_get_username", "Total get-username calls.");
    public static final Counter GET_PUBLIC_KEY  = build("core_node_get_public_key", "Total get-public-key calls.");
    public static final Counter GET_PUBLIC_KEY_CHAIN  = build("core_node_get_chain", "Total get-public-key-chain calls.");
    public static final Counter UPDATE_PUBLIC_KEY_CHAIN  = build("core_node_update_chain", "Total getupdate-public-key-chain calls.");


    public static void startExporter(String address, int port) throws IOException {
        HTTPServer server = new HTTPServer(address, port);
        //shutdown hook on signal
        Runtime.getRuntime().addShutdownHook(new Thread(() -> server.stop()));
    }
}


@@ -99,24 +99,54 @@
 .HTTPServer;
+%0Aimport peergos.server.util.*;
 %0A%0Aimport jav
@@ -2583,16 +2583,98 @@
 ption %7B%0A
+        Logging.LOG().info(%22Starting metrics server at %22 + address + %22:%22 + port);%0A
         

Add log statement for metrics initialization