Java Code Examples for org.apache.bookkeeper.stats.StatsLogger#registerGauge()

The following examples show how to use org.apache.bookkeeper.stats.StatsLogger#registerGauge() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LeastLoadPlacementPolicy.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public LeastLoadPlacementPolicy(LoadAppraiser loadAppraiser, RoutingService routingService,
                                Namespace namespace, PlacementStateManager placementStateManager,
                                Duration refreshInterval, StatsLogger statsLogger) {
    super(loadAppraiser, routingService, namespace, placementStateManager, refreshInterval, statsLogger);
    statsLogger.registerGauge("placement/load.diff", new Gauge<Number>() {
        @Override
        public Number getDefaultValue() {
            return 0;
        }

        @Override
        public Number getSample() {
            if (serverLoads.size() > 0) {
                return serverLoads.last().getLoad() - serverLoads.first().getLoad();
            } else {
                return getDefaultValue();
            }
        }
    });
}
 
Example 2
Source File: SimplePermitLimiter.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public SimplePermitLimiter(boolean darkmode, int permitsMax, StatsLogger statsLogger,
                           boolean singleton, Feature disableWriteLimitFeature) {
    this.permits = new AtomicInteger(0);
    this.permitsMax = permitsMax;
    this.darkmode = darkmode;
    this.disableWriteLimitFeature = disableWriteLimitFeature;

    // stats
    if (singleton) {
        this.statsLogger = statsLogger;
        this.permitsGauge = new Gauge<Number>() {
            @Override
            public Number getDefaultValue() {
                return 0;
            }
            @Override
            public Number getSample() {
                return permits.get();
            }
        };
        this.permitsGaugeLabel = "permits";
        statsLogger.registerGauge(permitsGaugeLabel, permitsGauge);
    }
    acquireFailureCounter = statsLogger.getCounter("acquireFailure");
    permitsMetric = statsLogger.getOpStatsLogger("permits");
}
 
Example 3
Source File: SimplePermitLimiter.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public SimplePermitLimiter(boolean darkmode, int permitsMax, StatsLogger statsLogger,
                           boolean singleton, Feature disableWriteLimitFeature) {
    this.permits = new AtomicInteger(0);
    this.permitsMax = permitsMax;
    this.darkmode = darkmode;
    this.disableWriteLimitFeature = disableWriteLimitFeature;

    // stats
    if (singleton) {
        statsLogger.registerGauge("num_permits", new Gauge<Number>() {
            @Override
            public Number getDefaultValue() {
                return 0;
            }
            @Override
            public Number getSample() {
                return permits.get();
            }
        });
    }
    acquireFailureCounter = statsLogger.getCounter("acquireFailure");
    permitsMetric = statsLogger.getOpStatsLogger("permits");
}
 
Example 4
Source File: ReadAheadTracker.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
ReadAheadTracker(String streamName,
                 final ReadAheadCache cache,
                 ReadAheadPhase initialPhase,
                 StatsLogger statsLogger) {
    this.phase = initialPhase;
    statsLogger.registerGauge("phase", new Gauge<Number>() {
        @Override
        public Number getDefaultValue() {
            return ReadAheadPhase.SCHEDULE_READAHEAD.getCode();
        }

        @Override
        public Number getSample() {
            return phase.getCode();
        }
    });
    statsLogger.registerGauge("ticks", new Gauge<Number>() {
        @Override
        public Number getDefaultValue() {
            return 0;
        }

        @Override
        public Number getSample() {
            return ticks.get();
        }
    });
    statsLogger.registerGauge("cache_entries", new Gauge<Number>() {
        @Override
        public Number getDefaultValue() {
            return 0;
        }

        @Override
        public Number getSample() {
            return cache.getNumCachedRecords();
        }
    });
}
 
Example 5
Source File: FileCommitLog.java    From herddb with Apache License 2.0 4 votes vote down vote up
public FileCommitLog(
        Path logDirectory, String tableSpaceName,
        long maxLogFileSize, ExecutorService fsyncThreadPool, StatsLogger statslogger,
        Consumer<FileCommitLog> onClose,
        int maxUnsynchedBatchSize,
        int maxUnsynchedBatchBytes,
        int maxSyncTime,
        boolean requireSync,
        boolean enableO_DIRECT
) {
    this.maxUnsyncedBatchSize = maxUnsynchedBatchSize;
    this.maxUnsyncedBatchBytes = maxUnsynchedBatchBytes;
    this.maxSyncTime = TimeUnit.MILLISECONDS.toNanos(maxSyncTime);
    this.requireSync = requireSync;
    this.enableO_DIRECT = enableO_DIRECT && OpenFileUtils.isO_DIRECT_Supported();
    this.onClose = onClose;
    this.maxLogFileSize = maxLogFileSize;
    this.tableSpaceName = tableSpaceName;
    this.logDirectory = logDirectory.toAbsolutePath();
    this.spool = new Thread(new SpoolTask(), "commitlog-" + tableSpaceName);
    this.spool.setDaemon(true);
    this.statsFsyncTime = statslogger.getOpStatsLogger("fsync");
    this.statsEntryLatency = statslogger.getOpStatsLogger("entryLatency");
    this.statsEntrySyncLatency = statslogger.getOpStatsLogger("entrySyncLatency");
    this.syncSize = statslogger.getOpStatsLogger("syncBatchSize");
    this.syncBytes = statslogger.getOpStatsLogger("syncBatchBytes");
    this.deferredSyncs = statslogger.getCounter("deferredSyncs");
    this.newfiles = statslogger.getCounter("newfiles");
    statslogger.registerGauge("queuesize", new Gauge<Integer>() {
        @Override
        public Integer getDefaultValue() {
            return 0;
        }

        @Override
        public Integer getSample() {
            return queueSize.get();
        }

    });
    statslogger.registerGauge("pendingentries", new Gauge<Integer>() {
        @Override
        public Integer getDefaultValue() {
            return 0;
        }

        @Override
        public Integer getSample() {
            return pendingEntries.get();
        }

    });

    this.fsyncThreadPool = fsyncThreadPool;
    LOGGER.log(Level.FINE, "tablespace {2}, logdirectory: {0}, maxLogFileSize {1} bytes", new Object[]{logDirectory, maxLogFileSize, tableSpaceName});
}
 
Example 6
Source File: MonitoredScheduledThreadPoolExecutor.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public MonitoredScheduledThreadPoolExecutor(int corePoolSize,
                                            ThreadFactory threadFactory,
                                            StatsLogger statsLogger,
                                            boolean traceTaskExecution) {
    super(corePoolSize, threadFactory);
    this.traceTaskExecution = traceTaskExecution;

    this.taskPendingStats = statsLogger.getOpStatsLogger("task_pending_time");
    this.taskExecutionStats = statsLogger.getOpStatsLogger("task_execution_time");
    // outstanding tasks
    statsLogger.registerGauge("pending_tasks", new Gauge<Number>() {
        @Override
        public Number getDefaultValue() {
            return 0;
        }

        @Override
        public Number getSample() {
            return getQueue().size();
        }
    });
    // completed tasks
    statsLogger.registerGauge("completed_tasks", new Gauge<Number>() {
        @Override
        public Number getDefaultValue() {
            return 0;
        }

        @Override
        public Number getSample() {
            return getCompletedTaskCount();
        }
    });
    // total tasks
    statsLogger.registerGauge("total_tasks", new Gauge<Number>() {
        @Override
        public Number getDefaultValue() {
            return 0;
        }

        @Override
        public Number getSample() {
            return getTaskCount();
        }
    });
}