// Path: elasticsearch-plugin/src/main/java/pl/suchenia/elasticsearchPrometheusMetrics/writer/PrometheusFormatWriter.java
// public class PrometheusFormatWriter {
//     private final StringWriter writer = new StringWriter();
//     private final Map<String, String> globalLabels;
// 
//     public PrometheusFormatWriter(Map<String, String> globalLabels) {
//         this.globalLabels = globalLabels;
//     }
// 
//     public SingleMetricsDefinitionBuilder addGauge(String name) {
//         return new SingleMetricsDefinitionBuilder(MetricType.GAUGE, writer, name, globalLabels);
//     }
// 
//     public SingleMetricsDefinitionBuilder addCounter(String name) {
//         return new SingleMetricsDefinitionBuilder(MetricType.COUNTER, writer, name, globalLabels);
//     }
// 
//     public SummaryMetricsDefinitionBuilder addSummary(String name) {
//         return new SummaryMetricsDefinitionBuilder(writer, name, globalLabels);
//     }
// 
//     public String toString() {
//         return writer.toString();
//     }
// }
// 
// Path: elasticsearch-plugin/src/main/java/pl/suchenia/elasticsearchPrometheusMetrics/writer/SingleValueWriter.java
// public final class SingleValueWriter {
//     private final ValueWriter valueWriter;
//     private final String name;
// 
//     SingleValueWriter(StringWriter writer, String name, Map<String, String> globalLabels) {
//         this.valueWriter = new ValueWriter(writer, globalLabels);
//         this.name = name;
//     }
// 
//     public SingleValueWriter withSharedLabel(String labelName, String labelValue) {
//         valueWriter.addSharedLabel(labelName, labelValue);
//         return this;
//     }
// 
//     public void value(double value) {
//         this.value(value, Collections.emptyMap());
//     }
// 
//     public SingleValueWriter value(double value, Map<String, String> labels) {
//         valueWriter.writeValue(name, value, labels);
//         return this;
//     }
// 
// 
//     public SingleValueWriter value(double value, String...labels) {
//         if (labels.length % 2 != 0) {
//             throw new IllegalArgumentException("Wrong number of labels, should be in pairs..");
//         }
// 
//         Map<String, String> paramsMap = new LinkedHashMap<>();
//         for (int i = 0; i < labels.length; i++) {
//             paramsMap.put(labels[i], labels[++i]);
//         }
// 
//         return this.value(value, paramsMap);
//     }
// 
// 
// 
//     public void summary(long collectionCount, long millis, String...labels) {
//         if (labels.length % 2 != 0) {
//             throw new IllegalArgumentException("Wrong number of labels, should be in pairs..");
//         }
//         Map<String, String> paramsMap = new LinkedHashMap<>();
//         for (int i = 0; i < labels.length; i++) {
//             paramsMap.put(labels[i], labels[++i]);
//         }
//         valueWriter.writeValue(name + "_count", collectionCount, paramsMap);
//         valueWriter.writeValue(name + "_sum", millis, paramsMap);
//     }
// }


import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.monitor.fs.FsInfo;
import org.elasticsearch.monitor.fs.FsInfo.Path;
import pl.suchenia.elasticsearchPrometheusMetrics.writer.PrometheusFormatWriter;
import pl.suchenia.elasticsearchPrometheusMetrics.writer.SingleValueWriter;
package pl.suchenia.elasticsearchPrometheusMetrics.generators;


public class FsMetricsGenerator extends MetricsGenerator<FsInfo> {
    private static final Logger logger = Loggers.getLogger(FsMetricsGenerator.class, "init");
    private static final String PATH_LABEL = "path";

    @Override
    public PrometheusFormatWriter generateMetrics(PrometheusFormatWriter writer, FsInfo fsInfo) {
        logger.debug("Generating data about FS stats: {}", fsInfo);

        writer.addGauge("es_fs_total_bytes")
                .withHelp("Total size of ES storage")
                .value(fsInfo.getTotal().getTotal().getBytes());
        writer.addGauge("es_fs_available_bytes")
                .withHelp("Available size of ES storage")
                .value(fsInfo.getTotal().getAvailable().getBytes());
        writer.addGauge("es_fs_free_bytes")
                .withHelp("Free size of ES storage")
// Path: elasticsearch-plugin/src/main/java/pl/suchenia/elasticsearchPrometheusMetrics/writer/PrometheusFormatWriter.java
// public class PrometheusFormatWriter {
//     private final StringWriter writer = new StringWriter();
//     private final Map<String, String> globalLabels;
// 
//     public PrometheusFormatWriter(Map<String, String> globalLabels) {
//         this.globalLabels = globalLabels;
//     }
// 
//     public SingleMetricsDefinitionBuilder addGauge(String name) {
//         return new SingleMetricsDefinitionBuilder(MetricType.GAUGE, writer, name, globalLabels);
//     }
// 
//     public SingleMetricsDefinitionBuilder addCounter(String name) {
//         return new SingleMetricsDefinitionBuilder(MetricType.COUNTER, writer, name, globalLabels);
//     }
// 
//     public SummaryMetricsDefinitionBuilder addSummary(String name) {
//         return new SummaryMetricsDefinitionBuilder(writer, name, globalLabels);
//     }
// 
//     public String toString() {
//         return writer.toString();
//     }
// }
// 
// Path: elasticsearch-plugin/src/main/java/pl/suchenia/elasticsearchPrometheusMetrics/writer/SingleValueWriter.java
// public final class SingleValueWriter {
//     private final ValueWriter valueWriter;
//     private final String name;
// 
//     SingleValueWriter(StringWriter writer, String name, Map<String, String> globalLabels) {
//         this.valueWriter = new ValueWriter(writer, globalLabels);
//         this.name = name;
//     }
// 
//     public SingleValueWriter withSharedLabel(String labelName, String labelValue) {
//         valueWriter.addSharedLabel(labelName, labelValue);
//         return this;
//     }
// 
//     public void value(double value) {
//         this.value(value, Collections.emptyMap());
//     }
// 
//     public SingleValueWriter value(double value, Map<String, String> labels) {
//         valueWriter.writeValue(name, value, labels);
//         return this;
//     }
// 
// 
//     public SingleValueWriter value(double value, String...labels) {
//         if (labels.length % 2 != 0) {
//             throw new IllegalArgumentException("Wrong number of labels, should be in pairs..");
//         }
// 
//         Map<String, String> paramsMap = new LinkedHashMap<>();
//         for (int i = 0; i < labels.length; i++) {
//             paramsMap.put(labels[i], labels[++i]);
//         }
// 
//         return this.value(value, paramsMap);
//     }
// 
// 
// 
//     public void summary(long collectionCount, long millis, String...labels) {
//         if (labels.length % 2 != 0) {
//             throw new IllegalArgumentException("Wrong number of labels, should be in pairs..");
//         }
//         Map<String, String> paramsMap = new LinkedHashMap<>();
//         for (int i = 0; i < labels.length; i++) {
//             paramsMap.put(labels[i], labels[++i]);
//         }
//         valueWriter.writeValue(name + "_count", collectionCount, paramsMap);
//         valueWriter.writeValue(name + "_sum", millis, paramsMap);
//     }
// }


// Path: elasticsearch-plugin/src/main/java/pl/suchenia/elasticsearchPrometheusMetrics/generators/FsMetricsGenerator.java
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.monitor.fs.FsInfo;
import org.elasticsearch.monitor.fs.FsInfo.Path;
import pl.suchenia.elasticsearchPrometheusMetrics.writer.PrometheusFormatWriter;
import pl.suchenia.elasticsearchPrometheusMetrics.writer.SingleValueWriter;

package pl.suchenia.elasticsearchPrometheusMetrics.generators;


public class FsMetricsGenerator extends MetricsGenerator<FsInfo> {
    private static final Logger logger = Loggers.getLogger(FsMetricsGenerator.class, "init");
    private static final String PATH_LABEL = "path";

    @Override
    public PrometheusFormatWriter generateMetrics(PrometheusFormatWriter writer, FsInfo fsInfo) {
        logger.debug("Generating data about FS stats: {}", fsInfo);

        writer.addGauge("es_fs_total_bytes")
                .withHelp("Total size of ES storage")
                .value(fsInfo.getTotal().getTotal().getBytes());
        writer.addGauge("es_fs_available_bytes")
                .withHelp("Available size of ES storage")
                .value(fsInfo.getTotal().getAvailable().getBytes());
        writer.addGauge("es_fs_free_bytes")
                .withHelp("Free size of ES storage")
                .value(fsInfo.getTotal().getFree().getBytes());