/*
 * 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.geode.distributed.internal;

import java.util.concurrent.atomic.LongAdder;
import java.util.function.LongSupplier;

import org.apache.logging.log4j.Logger;

import org.apache.geode.StatisticDescriptor;
import org.apache.geode.Statistics;
import org.apache.geode.StatisticsFactory;
import org.apache.geode.StatisticsType;
import org.apache.geode.StatisticsTypeFactory;
import org.apache.geode.annotations.Immutable;
import org.apache.geode.annotations.VisibleForTesting;
import org.apache.geode.annotations.internal.MakeNotStatic;
import org.apache.geode.internal.NanoTimer;
import org.apache.geode.internal.statistics.StatisticsTypeFactoryImpl;
import org.apache.geode.internal.util.Breadcrumbs;
import org.apache.geode.logging.internal.log4j.api.LogService;

/**
 * This class maintains statistics in GemFire about the distribution manager and distribution in
 * general.
 *
 *
 */
public class DistributionStats implements DMStats {
  private static final Logger logger = LogService.getLogger();

  @MakeNotStatic
  public static boolean enableClockStats = false;


  ////////////////// Statistic "Id" Fields //////////////////

  @Immutable
  private static final StatisticsType type;
  private static final int sentMessagesId;
  private static final int sentCommitMessagesId;
  private static final int commitWaitsId;
  @VisibleForTesting
  static final int sentMessagesTimeId;
  @VisibleForTesting
  static final int sentMessagesMaxTimeId;
  private static final int broadcastMessagesId;
  private static final int broadcastMessagesTimeId;
  private static final int receivedMessagesId;
  private static final int receivedBytesId;
  private static final int sentBytesId;
  private static final int processedMessagesId;
  private static final int processedMessagesTimeId;
  private static final int messageProcessingScheduleTimeId;
  private static final int messageChannelTimeId;
  private static final int udpDispatchRequestTimeId;
  private static final int replyMessageTimeId;
  private static final int distributeMessageTimeId;
  private static final int nodesId;
  private static final int overflowQueueSizeId;
  private static final int processingThreadsId;
  private static final int serialThreadsId;
  private static final int waitingThreadsId;
  private static final int highPriorityThreadsId;
  private static final int partitionedRegionThreadsId;
  private static final int functionExecutionThreadsId;
  private static final int partitionedRegionThreadJobsId;
  private static final int functionExecutionThreadJobsId;
  private static final int waitingQueueSizeId;
  private static final int overflowQueueThrottleTimeId;
  private static final int overflowQueueThrottleCountId;
  private static final int highPriorityQueueSizeId;
  private static final int highPriorityQueueThrottleTimeId;
  private static final int highPriorityQueueThrottleCountId;
  private static final int partitionedRegionQueueSizeId;
  private static final int partitionedRegionQueueThrottleTimeId;
  private static final int partitionedRegionQueueThrottleCountId;
  private static final int functionExecutionQueueSizeId;
  private static final int functionExecutionQueueThrottleCountId;
  private static final int functionExecutionQueueThrottleTimeId;
  private static final int serialQueueSizeId;
  @VisibleForTesting
  static final int serialQueueBytesId;
  private static final int serialPooledThreadId;
  private static final int serialQueueThrottleTimeId;
  private static final int serialQueueThrottleCountId;
  private static final int replyWaitsInProgressId;
  private static final int replyWaitsCompletedId;
  @VisibleForTesting
  static final int replyWaitTimeId;
  private static final int replyTimeoutsId;
  @VisibleForTesting
  static final int replyWaitMaxTimeId;
  private static final int receiverConnectionsId;
  private static final int failedAcceptsId;
  private static final int failedConnectsId;
  private static final int reconnectAttemptsId;
  private static final int lostConnectionLeaseId;
  private static final int sharedOrderedSenderConnectionsId;
  private static final int sharedUnorderedSenderConnectionsId;
  private static final int threadOrderedSenderConnectionsId;
  private static final int threadUnorderedSenderConnectionsId;
  static final int senderCreateTimeId;
  static final int senderCreatesInProgressId;

  private static final int syncSocketWritesInProgressId;
  private static final int syncSocketWriteTimeId;
  private static final int syncSocketWritesId;
  private static final int syncSocketWriteBytesId;

  private static final int ucastReadsId;
  private static final int ucastReadBytesId;
  private static final int ucastWritesId;
  private static final int ucastWriteBytesId;
  private static final int ucastRetransmitsId;

  private static final int mcastReadsId;
  private static final int mcastReadBytesId;
  private static final int mcastWritesId;
  private static final int mcastWriteBytesId;
  private static final int mcastRetransmitsId;
  private static final int mcastRetransmitRequestsId;

  private static final int serializationTimeId;
  private static final int serializationsId;
  private static final int serializedBytesId;

  private static final int pdxSerializationsId;
  private static final int pdxSerializedBytesId;

  private static final int deserializationTimeId;
  private static final int deserializationsId;
  private static final int deserializedBytesId;
  private static final int pdxDeserializationsId;
  private static final int pdxDeserializedBytesId;
  private static final int pdxInstanceDeserializationsId;
  private static final int pdxInstanceDeserializationTimeId;
  private static final int pdxInstanceCreationsId;

  private static final int msgSerializationTimeId;
  private static final int msgDeserializationTimeId;

  private static final int udpMsgEncryptionTimeId;
  private static final int udpMsgDecryptionTimeId;

  private static final int batchSendTimeId;
  private static final int batchCopyTimeId;
  private static final int batchWaitTimeId;
  private static final int batchFlushTimeId;

  private static final int threadOwnedReceiversId;
  private static final int threadOwnedReceiversId2;

  private static final int asyncSocketWritesInProgressId;
  private static final int asyncSocketWritesId;
  private static final int asyncSocketWriteRetriesId;
  private static final int asyncSocketWriteTimeId;
  private static final int asyncSocketWriteBytesId;

  private static final int socketLocksInProgressId;
  private static final int socketLocksId;
  private static final int socketLockTimeId;

  private static final int bufferAcquiresInProgressId;
  private static final int bufferAcquiresId;
  private static final int bufferAcquireTimeId;

  private static final int asyncQueueAddTimeId;
  private static final int asyncQueueRemoveTimeId;

  private static final int asyncQueuesId;
  private static final int asyncQueueFlushesInProgressId;
  private static final int asyncQueueFlushesCompletedId;
  private static final int asyncQueueFlushTimeId;
  private static final int asyncQueueTimeoutExceededId;
  private static final int asyncQueueSizeExceededId;
  private static final int asyncDistributionTimeoutExceededId;
  private static final int asyncQueueSizeId;
  private static final int asyncQueuedMsgsId;
  private static final int asyncDequeuedMsgsId;
  private static final int asyncConflatedMsgsId;

  private static final int asyncThreadsId;
  private static final int asyncThreadInProgressId;
  private static final int asyncThreadCompletedId;
  private static final int asyncThreadTimeId;

  private static final int receiverDirectBufferSizeId;
  private static final int receiverHeapBufferSizeId;
  private static final int senderDirectBufferSizeId;
  private static final int senderHeapBufferSizeId;

  private static final int messagesBeingReceivedId;
  private static final int messageBytesBeingReceivedId;

  private static final int serialThreadStartsId;
  private static final int processingThreadStartsId;
  private static final int highPriorityThreadStartsId;
  private static final int waitingThreadStartsId;
  private static final int partitionedRegionThreadStartsId;
  private static final int functionExecutionThreadStartsId;
  private static final int serialPooledThreadStartsId;
  private static final int TOSentMsgId;

  private static final int replyHandoffTimeId;

  private static final int serialThreadJobsId;
  private static final int serialPooledThreadJobsId;
  private static final int pooledMessageThreadJobsId;
  private static final int highPriorityThreadJobsId;
  private static final int waitingPoolThreadJobsId;

  private static final int eldersId;
  private static final int initialImageMessagesInFlightId;
  private static final int initialImageRequestsInProgressId;

  // For GMSHealthMonitor
  private static final int heartbeatRequestsSentId;
  private static final int heartbeatRequestsReceivedId;
  private static final int heartbeatsSentId;
  private static final int heartbeatsReceivedId;
  private static final int suspectsSentId;
  private static final int suspectsReceivedId;
  private static final int finalCheckRequestsSentId;
  private static final int finalCheckRequestsReceivedId;
  private static final int finalCheckResponsesSentId;
  private static final int finalCheckResponsesReceivedId;
  private static final int tcpFinalCheckRequestsSentId;
  private static final int tcpFinalCheckRequestsReceivedId;
  private static final int tcpFinalCheckResponsesSentId;
  private static final int tcpFinalCheckResponsesReceivedId;
  private static final int udpFinalCheckRequestsSentId;
  private static final int udpFinalCheckResponsesReceivedId;

  static {
    String statName = "DistributionStats";
    String statDescription = "Statistics on the gemfire distribution layer.";

    final String sentMessagesDesc =
        "The number of distribution messages that this GemFire system has sent. This includes broadcastMessages.";
    final String sentCommitMessagesDesc =
        "The number of transaction commit messages that this GemFire system has created to be sent. Note that it is possible for a commit to only create one message even though it will end up being sent to multiple recipients.";
    final String commitWaitsDesc =
        "The number of transaction commits that had to wait for a response before they could complete.";
    final String sentMessagesTimeDesc =
        "The total amount of time this distribution manager has spent sending messages. This includes broadcastMessagesTime.";
    final String sentMessagesMaxTimeDesc =
        "The highest amount of time this distribution manager has spent distributing a single message to the network.";
    final String broadcastMessagesDesc =
        "The number of distribution messages that this GemFire system has broadcast. A broadcast message is one sent to every other manager in the group.";
    final String broadcastMessagesTimeDesc =
        "The total amount of time this distribution manager has spent broadcasting messages. A broadcast message is one sent to every other manager in the group.";
    final String receivedMessagesDesc =
        "The number of distribution messages that this GemFire system has received.";
    final String receivedBytesDesc =
        "The number of distribution message bytes that this GemFire system has received.";
    final String sentBytesDesc =
        "The number of distribution message bytes that this GemFire system has sent.";
    final String processedMessagesDesc =
        "The number of distribution messages that this GemFire system has processed.";
    final String processedMessagesTimeDesc =
        "The amount of time this distribution manager has spent in message.process().";
    final String messageProcessingScheduleTimeDesc =
        "The amount of time this distribution manager has spent dispatching message to processor threads.";
    final String overflowQueueSizeDesc =
        "The number of normal distribution messages currently waiting to be processed.";
    final String waitingQueueSizeDesc =
        "The number of distribution messages currently waiting for some other resource before they can be processed.";
    final String overflowQueueThrottleTimeDesc =
        "The total amount of time, in nanoseconds, spent delayed by the overflow queue throttle.";
    final String overflowQueueThrottleCountDesc =
        "The total number of times a thread was delayed in adding a normal message to the overflow queue.";
    final String highPriorityQueueSizeDesc =
        "The number of high priority distribution messages currently waiting to be processed.";
    final String highPriorityQueueThrottleTimeDesc =
        "The total amount of time, in nanoseconds, spent delayed by the high priority queue throttle.";
    final String highPriorityQueueThrottleCountDesc =
        "The total number of times a thread was delayed in adding a normal message to the high priority queue.";
    final String serialQueueSizeDesc =
        "The number of serial distribution messages currently waiting to be processed.";
    final String serialQueueBytesDesc =
        "The approximate number of bytes consumed by serial distribution messages currently waiting to be processed.";
    final String serialPooledThreadDesc =
        "The number of threads created in the SerialQueuedExecutorPool.";
    final String serialQueueThrottleTimeDesc =
        "The total amount of time, in nanoseconds, spent delayed by the serial queue throttle.";
    final String serialQueueThrottleCountDesc =
        "The total number of times a thread was delayed in adding a ordered message to the serial queue.";
    final String serialThreadsDesc =
        "The number of threads currently processing serial/ordered messages.";
    final String processingThreadsDesc =
        "The number of threads currently processing normal messages.";
    final String highPriorityThreadsDesc =
        "The number of threads currently processing high priority messages.";
    final String partitionedRegionThreadsDesc =
        "The number of threads currently processing partitioned region messages.";
    final String functionExecutionThreadsDesc =
        "The number of threads currently processing function execution messages.";
    final String waitingThreadsDesc =
        "The number of threads currently processing messages that had to wait for a resource.";
    final String messageChannelTimeDesc =
        "The total amount of time received messages spent in the distribution channel";
    final String udpDispatchRequestTimeDesc =
        "The total amount of time spent deserializing and dispatching UDP messages in the message-reader thread.";
    final String replyMessageTimeDesc =
        "The amount of time spent processing reply messages. This includes both processedMessagesTime and messageProcessingScheduleTime.";
    final String distributeMessageTimeDesc =
        "The amount of time it takes to prepare a message and send it on the network.  This includes sentMessagesTime.";
    final String nodesDesc = "The current number of nodes in this distributed system.";
    final String replyWaitsInProgressDesc = "Current number of threads waiting for a reply.";
    final String replyWaitsCompletedDesc =
        "Total number of times waits for a reply have completed.";
    final String replyWaitTimeDesc = "Total time spent waiting for a reply to a message.";
    final String replyWaitMaxTimeDesc =
        "Maximum time spent transmitting and then waiting for a reply to a message. See sentMessagesMaxTime for related information";
    final String replyTimeoutsDesc = "Total number of message replies that have timed out.";
    final String receiverConnectionsDesc =
        "Current number of sockets dedicated to receiving messages.";
    final String failedAcceptsDesc =
        "Total number of times an accept (receiver creation) of a connect from some other member has failed";
    final String failedConnectsDesc =
        "Total number of times a connect (sender creation) to some other member has failed.";
    final String reconnectAttemptsDesc =
        "Total number of times an established connection was lost and a reconnect was attempted.";
    final String lostConnectionLeaseDesc =
        "Total number of times an unshared sender socket has remained idle long enough that its lease expired.";
    final String sharedOrderedSenderConnectionsDesc =
        "Current number of shared sockets dedicated to sending ordered messages.";
    final String sharedUnorderedSenderConnectionsDesc =
        "Current number of shared sockets dedicated to sending unordered messages.";
    final String threadOrderedSenderConnectionsDesc =
        "Current number of thread sockets dedicated to sending ordered messages.";
    final String threadUnorderedSenderConnectionsDesc =
        "Current number of thread sockets dedicated to sending unordered messages.";

    final String asyncQueuesDesc = "The current number of queues for asynchronous messaging.";
    final String asyncQueueFlushesInProgressDesc =
        "Current number of asynchronous queues being flushed.";
    final String asyncQueueFlushesCompletedDesc =
        "Total number of asynchronous queue flushes completed.";
    final String asyncQueueFlushTimeDesc = "Total time spent flushing asynchronous queues.";
    final String asyncQueueTimeoutExceededDesc =
        "Total number of asynchronous queues that have timed out by being blocked for more than async-queue-timeout milliseconds.";
    final String asyncQueueSizeExceededDesc =
        "Total number of asynchronous queues that have exceeded max size.";
    final String asyncDistributionTimeoutExceededDesc =
        "Total number of times the async-distribution-timeout has been exceeded during a socket write.";
    final String asyncQueueSizeDesc = "The current size in bytes used for asynchronous queues.";
    final String asyncQueuedMsgsDesc =
        "The total number of queued messages used for asynchronous queues.";
    final String asyncDequeuedMsgsDesc =
        "The total number of queued messages that have been removed from the queue and successfully sent.";
    final String asyncConflatedMsgsDesc =
        "The total number of queued conflated messages used for asynchronous queues.";

    final String asyncThreadsDesc = "Total number of asynchronous message queue threads.";
    final String asyncThreadInProgressDesc =
        "Current iterations of work performed by asynchronous message queue threads.";
    final String asyncThreadCompletedDesc =
        "Total number of iterations of work performed by asynchronous message queue threads.";
    final String asyncThreadTimeDesc =
        "Total time spent by asynchronous message queue threads performing iterations.";
    final String receiverDirectBufferSizeDesc =
        "Current number of bytes allocated from direct memory as buffers for incoming messages.";
    final String receiverHeapBufferSizeDesc =
        "Current number of bytes allocated from Java heap memory as buffers for incoming messages.";
    final String senderDirectBufferSizeDesc =
        "Current number of bytes allocated from direct memory as buffers for outgoing messages.";
    final String senderHeapBufferSizeDesc =
        "Current number of bytes allocated from Java heap memory as buffers for outoing messages.";

    final String replyHandoffTimeDesc =
        "Total number of seconds to switch thread contexts from processing thread to application thread.";

    final String partitionedRegionThreadJobsDesc =
        "The number of messages currently being processed by partitioned region threads";
    final String functionExecutionThreadJobsDesc =
        "The number of messages currently being processed by function execution threads";
    final String serialThreadJobsDesc =
        "The number of messages currently being processed by serial threads.";
    final String serialPooledThreadJobsDesc =
        "The number of messages currently being processed by pooled serial processor threads.";
    final String processingThreadJobsDesc =
        "The number of messages currently being processed by pooled message processor threads.";
    final String highPriorityThreadJobsDesc =
        "The number of messages currently being processed by high priority processor threads.";
    final String waitingThreadJobsDesc =
        "The number of messages currently being processed by waiting pooly processor threads.";

    final String eldersDesc = "Current number of system elders hosted in this member.";
    final String initialImageMessagesInFlightDesc =
        "The number of messages with initial image data sent from this member that have not yet been acknowledged.";
    final String initialImageRequestsInProgressDesc =
        "The number of initial images this member is currently receiving.";

    // For GMSHealthMonitor
    final String heartbeatRequestsSentDesc =
        "Heartbeat request messages that this member has sent.";
    final String heartbeatRequestsReceivedDesc =
        "Heartbeat request messages that this member has received.";

    final String heartbeatsSentDesc = "Heartbeat messages that this member has sent.";
    final String heartbeatsReceivedDesc = "Heartbeat messages that this member has received.";

    final String suspectsSentDesc = "Suspect member messages that this member has sent.";
    final String suspectsReceivedDesc = "Suspect member messages that this member has received.";

    final String finalCheckRequestsSentDesc = "Final check requests that this member has sent.";
    final String finalCheckRequestsReceivedDesc =
        "Final check requests that this member has received.";

    final String finalCheckResponsesSentDesc = "Final check responses that this member has sent.";
    final String finalCheckResponsesReceivedDesc =
        "Final check responses that this member has received.";

    final String tcpFinalCheckRequestsSentDesc =
        "TCP final check requests that this member has sent.";
    final String tcpFinalCheckRequestsReceivedDesc =
        "TCP final check requests that this member has received.";

    final String tcpFinalCheckResponsesSentDesc =
        "TCP final check responses that this member has sent.";
    final String tcpFinalCheckResponsesReceivedDesc =
        "TCP final check responses that this member has received.";

    final String udpFinalCheckRequestsSentDesc =
        "UDP final check requests that this member has sent.";
    final String udpFinalCheckRequestsReceivedDesc =
        "UDP final check requests that this member has received.";

    final String udpFinalCheckResponsesSentDesc =
        "UDP final check responses that this member has sent.";
    final String udpFinalCheckResponsesReceivedDesc =
        "UDP final check responses that this member has received.";

    final String senderCreatesDesc =
        "Total amount of time, in nanoseconds, spent creating a sender.";
    final String senderCreatesInProgressDesc =
        "Current number of sender creations in progress.";

    StatisticsTypeFactory f = StatisticsTypeFactoryImpl.singleton();

    type = f.createType(statName, statDescription, new StatisticDescriptor[] {
        f.createLongCounter("sentMessages", sentMessagesDesc, "messages"),
        f.createLongCounter("commitMessages", sentCommitMessagesDesc, "messages"),
        f.createLongCounter("commitWaits", commitWaitsDesc, "messages"),
        f.createLongCounter("sentMessagesTime", sentMessagesTimeDesc, "nanoseconds", false),
        f.createLongGauge("sentMessagesMaxTime", sentMessagesMaxTimeDesc, "milliseconds", false),
        f.createLongCounter("broadcastMessages", broadcastMessagesDesc, "messages"),
        f.createLongCounter("broadcastMessagesTime", broadcastMessagesTimeDesc, "nanoseconds",
            false),
        f.createLongCounter("receivedMessages", receivedMessagesDesc, "messages"),
        f.createLongCounter("receivedBytes", receivedBytesDesc, "bytes"),
        f.createLongCounter("sentBytes", sentBytesDesc, "bytes"),
        f.createLongCounter("processedMessages", processedMessagesDesc, "messages"),
        f.createLongCounter("processedMessagesTime", processedMessagesTimeDesc, "nanoseconds",
            false),
        f.createLongCounter("messageProcessingScheduleTime", messageProcessingScheduleTimeDesc,
            "nanoseconds", false),
        f.createLongGauge("overflowQueueSize", overflowQueueSizeDesc, "messages"),
        f.createLongGauge("waitingQueueSize", waitingQueueSizeDesc, "messages"),
        f.createLongGauge("overflowQueueThrottleCount", overflowQueueThrottleCountDesc, "delays"),
        f.createLongCounter("overflowQueueThrottleTime", overflowQueueThrottleTimeDesc,
            "nanoseconds", false),
        f.createLongGauge("highPriorityQueueSize", highPriorityQueueSizeDesc, "messages"),
        f.createLongGauge("highPriorityQueueThrottleCount", highPriorityQueueThrottleCountDesc,
            "delays"),
        f.createLongCounter("highPriorityQueueThrottleTime", highPriorityQueueThrottleTimeDesc,
            "nanoseconds", false),
        f.createLongGauge("partitionedRegionQueueSize", highPriorityQueueSizeDesc, "messages"),
        f.createLongGauge("partitionedRegionQueueThrottleCount", highPriorityQueueThrottleCountDesc,
            "delays"),
        f.createLongCounter("partitionedRegionQueueThrottleTime", highPriorityQueueThrottleTimeDesc,
            "nanoseconds", false),
        f.createLongGauge("functionExecutionQueueSize", highPriorityQueueSizeDesc, "messages"),
        f.createLongGauge("functionExecutionQueueThrottleCount", highPriorityQueueThrottleCountDesc,
            "delays"),
        f.createLongCounter("functionExecutionQueueThrottleTime", highPriorityQueueThrottleTimeDesc,
            "nanoseconds", false),
        f.createLongGauge("serialQueueSize", serialQueueSizeDesc, "messages"),
        f.createLongGauge("serialQueueBytes", serialQueueBytesDesc, "bytes"),
        f.createLongCounter("serialPooledThread", serialPooledThreadDesc, "threads"),
        f.createLongGauge("serialQueueThrottleCount", serialQueueThrottleCountDesc, "delays"),
        f.createLongCounter("serialQueueThrottleTime", serialQueueThrottleTimeDesc, "nanoseconds",
            false),
        f.createLongGauge("serialThreads", serialThreadsDesc, "threads"),
        f.createLongGauge("processingThreads", processingThreadsDesc, "threads"),
        f.createLongGauge("highPriorityThreads", highPriorityThreadsDesc, "threads"),
        f.createLongGauge("partitionedRegionThreads", partitionedRegionThreadsDesc, "threads"),
        f.createLongGauge("functionExecutionThreads", functionExecutionThreadsDesc, "threads"),
        f.createLongGauge("waitingThreads", waitingThreadsDesc, "threads"),
        f.createLongCounter("messageChannelTime", messageChannelTimeDesc, "nanoseconds", false),
        f.createLongCounter("udpDispatchRequestTime", udpDispatchRequestTimeDesc, "nanoseconds",
            false),
        f.createLongCounter("replyMessageTime", replyMessageTimeDesc, "nanoseconds", false),
        f.createLongCounter("distributeMessageTime", distributeMessageTimeDesc, "nanoseconds",
            false),
        f.createLongGauge("nodes", nodesDesc, "nodes"),
        f.createLongGauge("replyWaitsInProgress", replyWaitsInProgressDesc, "operations"),
        f.createLongCounter("replyWaitsCompleted", replyWaitsCompletedDesc, "operations"),
        f.createLongCounter("replyWaitTime", replyWaitTimeDesc, "nanoseconds", false),
        f.createLongGauge("replyWaitMaxTime", replyWaitMaxTimeDesc, "milliseconds", false),
        f.createLongCounter("replyTimeouts", replyTimeoutsDesc, "timeouts", false),
        f.createLongGauge("receivers", receiverConnectionsDesc, "sockets"),
        f.createLongGauge("sendersSO", sharedOrderedSenderConnectionsDesc, "sockets"),
        f.createLongGauge("sendersSU", sharedUnorderedSenderConnectionsDesc, "sockets"),
        f.createLongGauge("sendersTO", threadOrderedSenderConnectionsDesc, "sockets"),
        f.createLongGauge("sendersTU", threadUnorderedSenderConnectionsDesc, "sockets"),
        f.createLongCounter("failedAccepts", failedAcceptsDesc, "accepts"),
        f.createLongCounter("failedConnects", failedConnectsDesc, "connects"),
        f.createLongCounter("reconnectAttempts", reconnectAttemptsDesc, "connects"),
        f.createLongCounter("senderTimeouts", lostConnectionLeaseDesc, "expirations"),
        f.createLongCounter("senderCreateTime", senderCreatesDesc, "nanoseconds"),
        f.createLongGauge("senderCreatesInProgress", senderCreatesInProgressDesc, "operations"),

        f.createLongGauge("syncSocketWritesInProgress",
            "Current number of synchronous/blocking socket write calls in progress.", "writes"),
        f.createLongCounter("syncSocketWriteTime",
            "Total amount of time, in nanoseconds, spent in synchronous/blocking socket write calls.",
            "nanoseconds"),
        f.createLongCounter("syncSocketWrites",
            "Total number of completed synchronous/blocking socket write calls.", "writes"),
        f.createLongCounter("syncSocketWriteBytes",
            "Total number of bytes sent out in synchronous/blocking mode on sockets.", "bytes"),

        f.createLongCounter("ucastReads", "Total number of unicast datagrams received",
            "datagrams"),
        f.createLongCounter("ucastReadBytes", "Total number of bytes received in unicast datagrams",
            "bytes"),
        f.createLongCounter("ucastWrites", "Total number of unicast datagram socket write calls.",
            "writes"),
        f.createLongCounter("ucastWriteBytes",
            "Total number of bytes sent out on unicast datagram sockets.", "bytes"),
        f.createLongCounter("ucastRetransmits",
            "Total number of unicast datagram socket retransmissions", "writes"),

        f.createLongCounter("mcastReads", "Total number of multicast datagrams received",
            "datagrams"),
        f.createLongCounter("mcastReadBytes",
            "Total number of bytes received in multicast datagrams", "bytes"),
        f.createLongCounter("mcastWrites", "Total number of multicast datagram socket write calls.",
            "writes"),
        f.createLongCounter("mcastWriteBytes",
            "Total number of bytes sent out on multicast datagram sockets.", "bytes"),
        f.createLongCounter("mcastRetransmits",
            "Total number of multicast datagram socket retransmissions", "writes"),
        f.createLongCounter("mcastRetransmitRequests",
            "Total number of multicast datagram socket retransmission requests sent to other processes",
            "requests"),

        f.createLongCounter("serializationTime",
            "Total amount of time, in nanoseconds, spent serializing objects. This includes pdx serializations.",
            "nanoseconds"),
        f.createLongCounter("serializations",
            "Total number of object serialization calls. This includes pdx serializations.", "ops"),
        f.createLongCounter("serializedBytes",
            "Total number of bytes produced by object serialization. This includes pdx serializations.",
            "bytes"),
        f.createLongCounter("pdxSerializations", "Total number of pdx serializations.", "ops"),
        f.createLongCounter("pdxSerializedBytes",
            "Total number of bytes produced by pdx serialization.", "bytes"),
        f.createLongCounter("deserializationTime",
            "Total amount of time, in nanoseconds, spent deserializing objects. This includes deserialization that results in a PdxInstance.",
            "nanoseconds"),
        f.createLongCounter("deserializations",
            "Total number of object deserialization calls. This includes deserialization that results in a PdxInstance.",
            "ops"),
