package blackboard.monitor.newrelic.postgresql;

import java.util.HashMap;
import java.util.Map;

/**
 * PostgreSQL data enum
 * Created by ntatsumi on 5/6/14.
 */
public enum PostgresqlData {
    TOTAL_CONNECTIONS("TotalConnections", "", "Total Connections"),
    MAX_CONNECTIONS("MaxConnections", "", "Max Connections"),
    TOTAL_SESSION_TIME_HOURS("TotalSessionTimeHours", "hours", "Total Session Time"),
    OLDEST_SESSION_TIME_HOURS("OldestSessionTimeHours", "hours", "Oldest Session Duration"),
    DATABASE_SIZE("DatabaseSize", "MB", "Database Size"),
    TOTAL_LIVE_SIZE("TotalLiveSize", "MB", "Total Live Size"),
    TOTAL_DEAD_SIZE("TotalDeadSize", "MB", "Total Dead Size"),
    TOTAL_TABLE_SCANS("TotalTableScans", "MB", "Total Table Scans"),
    TOTAL_INDEX_SCANS("TotalIndexScans", "MB", "Total Index Scans"),
    TOTAL_INSERTS("TotalInserts", "MB", "Total Inserts"),
    TOTAL_UPDATES("TotalUpdates", "MB", "Total Updates"),
    TOTAL_DELETES("TotalDeletes", "MB", "Total Deletes");

    private String key;
    private String unit;
    private String metricName;

    private static Map<String, PostgresqlData> keyMap;

    private PostgresqlData(String key, String unit, String metricName) {
        this.key = key;
        this.unit = unit;
        this.metricName = metricName;
    }

    public static PostgresqlData getPostgresqlData(String key) {
        if(keyMap == null)
            initMapping();

        return keyMap.get(key);
    }

    private static void initMapping() {
        keyMap = new HashMap<String, PostgresqlData>();
        for (PostgresqlData data : values()) {
            keyMap.put(data.key, data);
        }
    }

    public String getUnit() {
        return unit;
    }

    public String getMetricName() {
        return metricName;
    }
}

@@ -205,24 +205,36 @@
 ONNECTIONS(%22
+Connections/
 TotalConnect
@@ -237,24 +237,35 @@
 nections%22, %22
+connections
 %22, %22Total Co
@@ -298,16 +298,28 @@
 CTIONS(%22
+Connections/
 MaxConne
@@ -328,16 +328,27 @@
 ions%22, %22
+connections
 %22, %22Max 
@@ -392,16 +392,25 @@
 _HOURS(%22
+Sessions/
 TotalSes
@@ -488,16 +488,25 @@
 _HOURS(%22
+Sessions/
 OldestSe
@@ -578,16 +578,24 @@
 E_SIZE(%22
+Storage/
 Database
@@ -642,24 +642,32 @@
 _LIVE_SIZE(%22
+Storage/
 TotalLiveSiz
@@ -717,16 +717,24 @@
 D_SIZE(%22
+Storage/
 TotalDea
@@ -786,24 +786,39 @@
 ABLE_SCANS(%22
+AccessPatterns/
 TotalTableSc
@@ -874,16 +874,31 @@
 _SCANS(%22
+AccessPatterns/
 TotalInd
@@ -954,16 +954,31 @@
 NSERTS(%22
+AccessPatterns/
 TotalIns
@@ -1023,24 +1023,39 @@
 AL_UPDATES(%22
+AccessPatterns/
 TotalUpdates
@@ -1100,16 +1100,31 @@
 ELETES(%22
+AccessPatterns/
 TotalDel

Categorized metrics