All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.pulsar.broker.stats.ReplicationMetrics Maven / Gradle / Ivy

There is a newer version: 4.0.0.10
Show newest version
/**
 * 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.
 */
package org.apache.pulsar.broker.stats;

import com.google.common.collect.Maps;
import io.netty.util.Recycler;
import io.netty.util.Recycler.Handle;
import java.util.Map;
import org.apache.pulsar.common.stats.Metrics;

/**
 */
public class ReplicationMetrics {
    public double msgRateOut;
    public double msgThroughputOut;
    public double msgReplBacklog;
    public double maxMsgReplDelayInSeconds;
    public int connected;

    public void reset() {
        msgRateOut = 0;
        msgThroughputOut = 0;
        msgReplBacklog = 0;
        connected = 0;
        maxMsgReplDelayInSeconds = 0;
    }

    public static ReplicationMetrics get() {
        ReplicationMetrics replicationMetrics = RECYCLER.get();
        replicationMetrics.reset();
        return replicationMetrics;
    }

    private final Handle recyclerHandle;

    private ReplicationMetrics(Handle recyclerHandle) {
        this.recyclerHandle = recyclerHandle;
    }

    private static final Recycler RECYCLER = new Recycler() {
        @Override
        protected ReplicationMetrics newObject(Recycler.Handle handle) {
            return new ReplicationMetrics(handle);
        }
    };

    public void recycle() {
        msgRateOut = -1;
        msgThroughputOut = -1;
        msgReplBacklog = -1;
        connected = -1;
        recyclerHandle.recycle(this);
    }

    public Metrics add(String namespace, String local, String remote) {

        Map dimensionMap = Maps.newHashMap();
        dimensionMap.put("namespace", namespace);
        dimensionMap.put("from_cluster", local);
        dimensionMap.put("to_cluster", remote);
        Metrics dMetrics = Metrics.create(dimensionMap);

        dMetrics.put("brk_repl_out_rate", msgRateOut);
        dMetrics.put("brk_repl_out_tp_rate", msgThroughputOut);
        dMetrics.put("brk_replication_backlog", msgReplBacklog);
        dMetrics.put("brk_repl_is_connected", connected);
        dMetrics.put("brk_max_replication_delay_second", maxMsgReplDelayInSeconds);

        return dMetrics;

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy