management:metrics:enable:all:false# all mean all inner metrics export:prometheus:enabled:truetags:# user define labels only for inner metricslabel-1-name:hellolabel-2-name:worldendpoint:metrics:enabled:trueprometheus:enabled:trueendpoints:web:exposure:include: ["prometheus","health"]
3. 验证
$curllocalhost:8080/actuator/prometheus
4. 关闭不需要的内置监控项
Whether meter IDs starting-with the specified name should be enabled. The longest match wins, the key all can also be used to configure all meters.
packagecom.example.prometheusdemo.config;importjava.util.ArrayList;importjava.util.Arrays;importjava.util.List;importjava.util.Random;importio.prometheus.client.Collector;importio.prometheus.client.GaugeMetricFamily;publicclassYourCustomCollectorextendsCollector{ @OverridepublicList<MetricFamilySamples> collect() {List<MetricFamilySamples> mfs =newArrayList<MetricFamilySamples>();// With no labels.mfs.add(newGaugeMetricFamily("my_gauge","help",42));// With labelsGaugeMetricFamily labeledGauge =newGaugeMetricFamily("my_other_gauge","help",Arrays.asList("labelname"));labeledGauge.addMetric(Arrays.asList("foo"),newRandom().nextInt(5));labeledGauge.addMetric(Arrays.asList("bar"),newRandom().nextInt(5));mfs.add(labeledGauge);return mfs; }}