Package com.newrelic.plugins.mysql

Source Code of com.newrelic.plugins.mysql.MetricMeta

package com.newrelic.plugins.mysql;

import static com.newrelic.plugins.mysql.util.Constants.*;

import com.newrelic.metrics.publish.processors.EpochCounter;

/**
* This class holds additional meta data about a given metric. This enables the
* Agent to work more intelligently with the global MySQL commands, by default
* knowing nothing, but then being able to define better unit names, identifying
* counters etc
*
* Currently a Metric can have the following attributes
*
* - Counter (Yes/No). The default is Yes - Unit Name
*
* @author Ronald Bradford me@ronaldbradford.com
*
*/
public class MetricMeta {

    public final static String DEFAULT_UNIT = "Operations";
    public final static String DEFAULT_COUNTER_UNIT = DEFAULT_UNIT + "/Second";

    private final String unit;
    private EpochCounter counter = null;

    public MetricMeta(boolean isCounter, String unit) {
        this.unit = unit;
        if (isCounter) {
            this.counter = new EpochCounter();
        }
    }

    public MetricMeta(boolean isCounter) {
        this.unit = isCounter ? DEFAULT_COUNTER_UNIT : DEFAULT_UNIT;
        if (isCounter) {
            this.counter = new EpochCounter();
        }
    }

    public static MetricMeta defaultMetricMeta() {
        return new MetricMeta(true);
    }

    public boolean isCounter() {
        return (this.counter == null ? false : true);
    }

    public String getUnit() {
        return this.unit;
    }

    public EpochCounter getCounter() {
        return this.counter;
    }

    @Override
    public String toString() {
        return new StringBuilder()
            .append(isCounter() ? COUNTER : EMPTY_STRING)
            .append(LEFT_PAREN)
            .append(getUnit())
            .append(RIGHT_PAREN)
            .toString();
    }
}
TOP

Related Classes of com.newrelic.plugins.mysql.MetricMeta

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.