001/* 002 * Copyright (C) 2020-2023 The Prometheus jmx_exporter Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package io.prometheus.jmx; 018 019import java.util.List; 020 021/** 022 * MatchedRule is the result of matching a JMX bean against the rules present in the configuration 023 * file. As rules are matched using regular expressions, caching helps prevent having to match the 024 * same beans to the same list of regular expressions. 025 */ 026public class MatchedRule { 027 028 final String name; 029 final String matchName; 030 final String type; 031 final String help; 032 final List<String> labelNames; 033 final List<String> labelValues; 034 final Double value; 035 final double valueFactor; 036 037 private static final MatchedRule _unmatched = new MatchedRule(); 038 039 private MatchedRule() { 040 this.name = null; 041 this.matchName = null; 042 this.type = null; 043 this.help = null; 044 this.labelNames = null; 045 this.labelValues = null; 046 this.value = null; 047 this.valueFactor = 1.0; 048 } 049 050 public MatchedRule( 051 final String name, 052 final String matchName, 053 final String type, 054 final String help, 055 final List<String> labelNames, 056 final List<String> labelValues, 057 final Double value, 058 double valueFactor) { 059 this.name = name; 060 this.matchName = matchName; 061 this.type = type; 062 this.help = help; 063 this.labelNames = labelNames; 064 this.labelValues = labelValues; 065 this.value = value; 066 this.valueFactor = valueFactor; 067 } 068 069 /** 070 * An unmatched MatchedRule, used when no rule matching a JMX bean has been found in the 071 * configuration. Cached unmatched rules are still a cache hit, that will not produce any 072 * metric/value. 073 * 074 * @return the invalid rule 075 */ 076 public static MatchedRule unmatched() { 077 return _unmatched; 078 } 079 080 public boolean isUnmatched() { 081 return this == _unmatched; 082 } 083 084 public boolean isMatched() { 085 return !isUnmatched(); 086 } 087}