/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Copyright 2015 Cloudius Systems
 *
 * Modified by Cloudius Systems
 */
package org.apache.cassandra.metrics;

import javax.management.MalformedObjectNameException;

/**
 * Metrics for compaction.
 */
public class CompactionMetrics implements Metrics {
    public CompactionMetrics() {
    }

    @Override
    public void register(MetricsRegistry registry) throws MalformedObjectNameException {
        MetricNameFactory factory = new DefaultNameFactory("Compaction");
        /** Estimated number of compactions remaining to perform */
        registry.register(() -> registry.gauge(Integer.class, "/compaction_manager/metrics/pending_tasks"),
                factory.createMetricName("PendingTasks"));
        /** Number of completed compactions since server [re]start */
        registry.register(() -> registry.gauge("/compaction_manager/metrics/completed_tasks"),
                factory.createMetricName("CompletedTasks"));
        /** Total number of compactions since server [re]start */
        registry.register(() -> registry.meter("/compaction_manager/metrics/total_compactions_completed"),
                factory.createMetricName("TotalCompactionsCompleted"));
        /** Total number of bytes compacted since server [re]start */
        registry.register(() -> registry.meter("/compaction_manager/metrics/bytes_compacted"),
                factory.createMetricName("BytesCompacted"));
    }

}

@@ -916,16 +916,124 @@
 trics;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport javax.json.JsonArray;%0Aimport javax.json.JsonObject;%0A
 import j
@@ -2315,17 +2315,860 @@
 ted%22));%0A
+%0A        registry.register(() -%3E registry.gauge((client) -%3E %7B%0A            Map%3CString, Map%3CString, Integer%3E%3E result = new HashMap%3C%3E();%0A            JsonArray compactions = client.getJsonArray(%22compaction_manager/compactions%22);%0A%0A            for (int i = 0; i %3C compactions.size(); i++) %7B%0A                JsonObject c = compactions.getJsonObject(i);%0A%0A                String ks = c.getString(%22ks%22);%0A                String cf = c.getString(%22cf%22);%0A%0A                if (!result.containsKey(ks)) %7B%0A                    result.put(ks, new HashMap%3C%3E());%0A                %7D%0A%0A                Map%3CString, Integer%3E map = result.get(ks);%0A                map.put(cf, (int)(c.getJsonNumber(%22total%22).longValue() - c.getJsonNumber(%22completed%22).longValue()));%0A            %7D%0A            return result;%0A        %7D), factory.createMetricName(%22PendingTasksByTableName%22));%0A
     %7D
-%0A
 %0A%7D%0A

Add "PendingTasksByTableName" gauge to CompactionMetrics