001package io.prometheus.jmx;
002
003import io.prometheus.client.Collector.Type;
004
005import java.util.List;
006
007/**
008 * MatchedRule is the result of matching a JMX bean against the rules present in the configuration file.
009 * As rules are matched using regular expressions, caching helps prevent having to match the same beans to the same list
010 * of regular expressions.
011 */
012public class MatchedRule {
013    final String name;
014    final String matchName;
015    final Type type;
016    final String help;
017    final List<String> labelNames;
018    final List<String> labelValues;
019    final Double value;
020    final double valueFactor;
021
022    private static final MatchedRule _unmatched = new MatchedRule();
023
024    private MatchedRule() {
025        this.name = null;
026        this.matchName = null;
027        this.type = null;
028        this.help = null;
029        this.labelNames = null;
030        this.labelValues = null;
031        this.value = null;
032        this.valueFactor = 1.0;
033    }
034
035    public MatchedRule(
036            final String name,
037            final String matchName,
038            final Type type,
039            final String help,
040            final List<String> labelNames,
041            final List<String> labelValues,
042            final Double value,
043            double valueFactor) {
044        this.name = name;
045        this.matchName = matchName;
046        this.type = type;
047        this.help = help;
048        this.labelNames = labelNames;
049        this.labelValues = labelValues;
050        this.value = value;
051        this.valueFactor = valueFactor;
052    }
053
054    /**
055     * A unmatched MatchedRule, used when no rule matching a JMX bean has been found in the configuration.
056     * Cached unmatched rules are still a cache hit, that will not produce any metric/value.
057     * @return the invalid rule
058     */
059    public static MatchedRule unmatched() {
060        return _unmatched;
061    }
062
063    public boolean isUnmatched() {
064        return this == _unmatched;
065    }
066
067    public boolean isMatched() {
068        return !isUnmatched();
069    }
070}