Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,23 @@

import io.prometheus.metrics.model.registry.PrometheusRegistry;
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
import java.io.File;
import java.io.FileReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.logging.LogManager;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;

@SuppressWarnings("unchecked")
public class JmxCollectorConfigTest {
Expand Down Expand Up @@ -572,6 +584,49 @@ public void testDefaultExportWithInferCounterTypeFromName() throws Exception {
}
}

@Nested
class ExampleConfigsValidationTests {

@Test
public void testAllExampleConfigsLoadAndSpecifyExplicitGaugeOrCounterType() throws Exception {
Path examplesDir = Paths.get("../examples");
List<Path> yamlFiles;
try (Stream<Path> paths = Files.list(examplesDir)) {
yamlFiles = paths.filter(path -> {
String fileName = path.getFileName().toString();
return fileName.endsWith(".yml") || fileName.endsWith(".yaml");
})
.sorted()
.collect(Collectors.toList());
}

assertThat(yamlFiles).isNotEmpty();

for (Path yamlPath : yamlFiles) {
File file = yamlPath.toFile();
new JmxCollector(file);

try (FileReader reader = new FileReader(file)) {
Map<String, Object> yamlConfig = new Yaml(new SafeConstructor(new LoaderOptions())).load(reader);
assertThat(yamlConfig)
.as("Example config %s should contain rules", yamlPath.getFileName())
.containsKey("rules");

List<Map<String, Object>> rules = (List<Map<String, Object>>) yamlConfig.get("rules");
assertThat(rules)
.as("Example config %s rules should not be empty", yamlPath.getFileName())
.isNotEmpty();

for (Map<String, Object> rule : rules) {
assertThat(rule.get("type"))
.as("Rule %s in %s must specify GAUGE or COUNTER type", rule, yamlPath.getFileName())
.isIn("GAUGE", "COUNTER");
}
}
}
}
}

private Double getSampleValue(String name, String[] labelNames, String[] labelValues) {
return prometheusRegistryUtils.getSampleValue(name, labelNames, labelValues);
}
Expand Down
16 changes: 16 additions & 0 deletions examples/activemq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,31 @@ whitelistObjectNames:
- "org.apache.activemq:type=Topic,brokerName=*"

rules:
- pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Queue, destinationName=(\S*)><>((?:enqueue|dequeue|dispatch|expired|forward)_count)
name: activemq_queue_$3
attrNameSnakeCase: true
type: COUNTER
labels:
destination: $2

- pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Queue, destinationName=(\S*)><>(\w+)
name: activemq_queue_$3
attrNameSnakeCase: true
type: GAUGE
labels:
destination: $2

- pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Topic, destinationName=(\S*)><>((?:enqueue|dequeue|dispatch|expired|forward)_count)
name: activemq_topic_$3
attrNameSnakeCase: true
type: COUNTER
labels:
destination: $2

- pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Topic, destinationName=(\S*)><>(\w+)
name: activemq_topic_$3
attrNameSnakeCase: true
type: GAUGE
labels:
destination: $2

Expand Down
6 changes: 3 additions & 3 deletions examples/cassandra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ rules:
#
- pattern: org.apache.cassandra.metrics<type=(\S*)(?:, ((?!scope)\S*)=(\S*))?(?:, scope=(\S*))?, name=(.+)?(?:Total)(Latency)><>Count
name: cassandra_$1_$5$6_seconds_sum
type: UNTYPED
type: COUNTER
labels:
"$1": "$4"
"$2": "$3"
Expand All @@ -63,14 +63,14 @@ rules:

- pattern: org.apache.cassandra.metrics<type=(\S*)(?:, ((?!scope)\S*)=(\S*))?(?:, scope=(\S*))?, name=((?:.+)?(?:Latency))><>Count
name: cassandra_$1_$5_seconds_count
type: UNTYPED
type: COUNTER
labels:
"$1": "$4"
"$2": "$3"

- pattern: org.apache.cassandra.metrics<type=(\S*)(?:, ((?!scope)\S*)=(\S*))?(?:, scope=(\S*))?, name=(.+)><>Count
name: cassandra_$1_$5_count
type: UNTYPED
type: COUNTER
labels:
"$1": "$4"
"$2": "$3"
Expand Down
5 changes: 5 additions & 0 deletions examples/flink.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ rules:
# Example: org.apache.flink.metrics<key0=127.0.0.1, key1=jobmanager, name=taskSlotsTotal><>Value
- pattern: org.apache.flink.metrics<key0=(.*), key1=jobmanager, name=([a-z].*)><>Value
name: flink_jobmanager_$2
type: GAUGE

# Example: org.apache.flink.metrics<key0=127.0.0.1, key1=jobmanager, key2=My_Job, name=lastCheckpointDuration><>Value
- pattern: org.apache.flink.metrics<key0=(.*), key1=jobmanager, key2=(.*), name=([a-z].*)><>Value
name: flink_jobmanager_$3
labels:
flink_job: $2
type: GAUGE

## Task Manager ##
# Example: org.apache.flink.metrics<key0=debian-8, key1=taskmanager, key2=407401ecfef1f050d3dcc83af9cbfb74, key3=My_Job, key4=Map, key6=1, name=numRecordsIn><>Count
Expand All @@ -27,6 +29,7 @@ rules:
flink_job: $3
operator: $4
partition: $5
type: GAUGE

# Example: org.apache.flink.metrics<key0=debian-8, key1=taskmanager, key2=407401ecfef1f050d3dcc83af9cbfb74, key3=My_Job, key4=Sink, key5=1, key6=KafkaProducer, name=batch-size-avg><>Value
- pattern: org.apache.flink.metrics<key0=(.*), key1=taskmanager, key2=(.*), key3=(.*), key4=(.*), key5=([0-9]*), key6=KafkaProducer, name=([a-z].*)><>Value
Expand All @@ -35,6 +38,7 @@ rules:
flink_job: $3
operator: $4
partition: $5
type: GAUGE

# Example: org.apache.flink.metrics<key0=debian-8, key1=taskmanager, key2=407401ecfef1f050d3dcc83af9cbfb74, key3=My_Job, key4=Source, key5=1, key6=KafkaConsumer, key7=committed-offsets, name=topic-name-1><>Value
- pattern: org.apache.flink.metrics<key0=(.*), key1=taskmanager, key2=(.*), key3=(.*), key4=(.*), key5=([0-9]*), key6=KafkaConsumer, key7=(.*), name=([a-z].*)><>Value
Expand All @@ -45,3 +49,4 @@ rules:
partition: $5
offsets: $6
name: $7
type: GAUGE
2 changes: 2 additions & 0 deletions examples/hazelcast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rules:
- pattern: "^com.hazelcast<type=Metrics, instance=(.*), prefix=(.*), tag([0-9]+)=(.*)><>(.+):"
name: hazelcast_$5
attrNameSnakeCase: true
type: GAUGE
labels:
instance: $1
prefix: $2
Expand All @@ -17,6 +18,7 @@ rules:
- pattern: "^com.hazelcast<type=Metrics, instance=(.*), prefix=(.*)><>(.+):"
name: hazelcast_$3
attrNameSnakeCase: true
type: GAUGE
labels:
instance: $1
prefix: $2
Expand Down
76 changes: 67 additions & 9 deletions examples/kafka-0-8-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ lowercaseOutputName: true
rules:
- pattern : kafka.cluster<type=(.+), name=(.+), topic=(.+), partition=(.+)><>Value
name: kafka_cluster_$1_$2
type: GAUGE
labels:
topic: "$3"
partition: "$4"
- pattern : kafka.log<type=Log, name=(.+), topic=(.+), partition=(.+)><>Value
name: kafka_log_$1
type: GAUGE
labels:
topic: "$2"
partition: "$3"
- pattern : kafka.controller<type=(.+), name=(.+)><>(Count|Value)
- pattern : kafka.controller<type=(.+), name=(.+)><>Count
name: kafka_controller_$1_$2
type: COUNTER
- pattern : kafka.controller<type=(.+), name=(.+)><>Value
name: kafka_controller_$1_$2
type: GAUGE
- pattern : kafka.network<type=(.+), name=(.+)><>Value
name: kafka_network_$1_$2
type: GAUGE
- pattern : kafka.network<type=(.+), name=(.+)PerSec, request=(.+)><>Count
name: kafka_network_$1_$2_total
type: COUNTER
labels:
request: "$3"
- pattern : kafka.network<type=(.+), name=(\w+), networkProcessor=(.+)><>Count
Expand All @@ -28,47 +36,88 @@ rules:
name: kafka_network_$1_$2
labels:
request: "$3"
type: COUNTER
- pattern : kafka.network<type=(.+), name=(\w+)><>Count
name: kafka_network_$1_$2
type: COUNTER
- pattern : kafka.server<type=(.+), name=(.+)PerSec\w*, topic=(.+)><>Count
name: kafka_server_$1_$2_total
type: COUNTER
labels:
topic: "$3"
- pattern : kafka.server<type=(.+), name=(.+)PerSec\w*><>Count
name: kafka_server_$1_$2_total
type: COUNTER

- pattern : kafka.server<type=(.+), name=(.+), clientId=(.+), topic=(.+), partition=(.*)><>(Count|Value)
- pattern : kafka.server<type=(.+), name=(.+), clientId=(.+), topic=(.+), partition=(.*)><>Count
name: kafka_server_$1_$2
type: COUNTER
labels:
clientId: "$3"
topic: "$4"
partition: "$5"
- pattern : kafka.server<type=(.+), name=(.+), topic=(.+), partition=(.*)><>(Count|Value)
- pattern : kafka.server<type=(.+), name=(.+), clientId=(.+), topic=(.+), partition=(.*)><>Value
name: kafka_server_$1_$2
type: GAUGE
labels:
clientId: "$3"
topic: "$4"
partition: "$5"
- pattern : kafka.server<type=(.+), name=(.+), topic=(.+), partition=(.*)><>Count
name: kafka_server_$1_$2
type: COUNTER
labels:
topic: "$3"
partition: "$4"
- pattern : kafka.server<type=(.+), name=(.+), topic=(.+)><>(Count|Value)
- pattern : kafka.server<type=(.+), name=(.+), topic=(.+), partition=(.*)><>Value
name: kafka_server_$1_$2
type: GAUGE
labels:
topic: "$3"
partition: "$4"
- pattern : kafka.server<type=(.+), name=(.+), topic=(.+)><>Count
name: kafka_server_$1_$2
labels:
topic: "$3"
type: COUNTER
- pattern : kafka.server<type=(.+), name=(.+), topic=(.+)><>Value
name: kafka_server_$1_$2
labels:
topic: "$3"
type: GAUGE

- pattern : kafka.server<type=(.+), name=(.+), clientId=(.+), brokerHost=(.+), brokerPort=(.+)><>(Count|Value)
- pattern : kafka.server<type=(.+), name=(.+), clientId=(.+), brokerHost=(.+), brokerPort=(.+)><>Count
name: kafka_server_$1_$2
type: COUNTER
labels:
clientId: "$3"
broker: "$4:$5"
- pattern : kafka.server<type=(.+), name=(.+), clientId=(.+)><>(Count|Value)
- pattern : kafka.server<type=(.+), name=(.+), clientId=(.+), brokerHost=(.+), brokerPort=(.+)><>Value
name: kafka_server_$1_$2
type: GAUGE
labels:
clientId: "$3"
broker: "$4:$5"
- pattern : kafka.server<type=(.+), name=(.+), clientId=(.+)><>Count
name: kafka_server_$1_$2
type: COUNTER
labels:
clientId: "$3"
- pattern : kafka.server<type=(.+), name=(.+), clientId=(.+)><>Value
name: kafka_server_$1_$2
type: GAUGE
labels:
clientId: "$3"
- pattern : kafka.server<type=(.+), name=(.+)><>(Count|Value)
- pattern : kafka.server<type=(.+), name=(.+)><>Count
name: kafka_server_$1_$2
type: COUNTER
- pattern : kafka.server<type=(.+), name=(.+)><>Value
name: kafka_server_$1_$2
type: GAUGE

- pattern : kafka.(\w+)<type=(.+), name=(.+)PerSec\w*><>Count
name: kafka_$1_$2_$3_total
type: COUNTER
- pattern : kafka.(\w+)<type=(.+), name=(.+)PerSec\w*, topic=(.+)><>Count
name: kafka_$1_$2_$3_total
labels:
Expand All @@ -80,11 +129,20 @@ rules:
topic: "$4"
partition: "$5"
type: COUNTER
- pattern : kafka.(\w+)<type=(.+), name=(.+)><>(Count|Value)
- pattern : kafka.(\w+)<type=(.+), name=(.+)><>(Count)
name: kafka_$1_$2_$3_$4
type: COUNTER
- pattern : kafka.(\w+)<type=(.+), name=(.+), (\w+)=(.+)><>(Count|Value)
- pattern : kafka.(\w+)<type=(.+), name=(.+)><>(Value)
name: kafka_$1_$2_$3_$4
type: GAUGE
- pattern : kafka.(\w+)<type=(.+), name=(.+), (\w+)=(.+)><>(Count)
name: kafka_$1_$2_$3_$6
type: COUNTER
labels:
"$4": "$5"
- pattern : kafka.(\w+)<type=(.+), name=(.+), (\w+)=(.+)><>(Value)
name: kafka_$1_$2_$3_$6
type: GAUGE
labels:
"$4": "$5"

12 changes: 10 additions & 2 deletions examples/kafka-connect.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
lowercaseOutputName: true
inferCounterTypeFromName: true
rules:
#kafka.connect:type=app-info,client-id="{clientid}"
#kafka.consumer:type=app-info,client-id="{clientid}"
Expand Down Expand Up @@ -42,13 +43,20 @@ rules:

#kafka.connect:type=connect-node-metrics,client-id="{clientid}",node-id="{nodeid}"
#kafka.consumer:type=consumer-node-metrics,client-id=consumer-1,node-id="{nodeid}"
- pattern: kafka.(.+)<type=(.+)-metrics, client-id=(.+), node-id=(.+)><>(.+-total|.+-avg)
- pattern: kafka.(.+)<type=(.+)-metrics, client-id=(.+), node-id=(.+)><>(.+-total)
name: kafka_$2_$5
labels:
clientId: "$3"
nodeId: "$4"
help: "Kafka $1 JMX metric type $2"
type: UNTYPED
type: COUNTER
- pattern: kafka.(.+)<type=(.+)-metrics, client-id=(.+), node-id=(.+)><>(.+-avg)
name: kafka_$2_$5
labels:
clientId: "$3"
nodeId: "$4"
help: "Kafka $1 JMX metric type $2"
type: GAUGE

#kafka.connect:type=kafka-metrics-count,client-id="{clientid}"
#kafka.consumer:type=consumer-fetch-manager-metrics,client-id="{clientid}"
Expand Down
Loading