本文整理汇总了Java中org.springframework.boot.actuate.metrics.GaugeService类的典型用法代码示例。如果您正苦于以下问题:Java GaugeService类的具体用法?Java GaugeService怎么用?Java GaugeService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GaugeService类属于org.springframework.boot.actuate.metrics包,在下文中一共展示了GaugeService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dropwizardInstalledIfPresent
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Test
public void dropwizardInstalledIfPresent() {
this.context = new AnnotationConfigApplicationContext(
MetricsDropwizardAutoConfiguration.class,
MetricRepositoryAutoConfiguration.class, AopAutoConfiguration.class);
GaugeService gaugeService = this.context.getBean(GaugeService.class);
assertThat(gaugeService).isNotNull();
gaugeService.submit("foo", 2.7);
DropwizardMetricServices exporter = this.context
.getBean(DropwizardMetricServices.class);
assertThat(exporter).isEqualTo(gaugeService);
MetricRegistry registry = this.context.getBean(MetricRegistry.class);
@SuppressWarnings("unchecked")
Gauge<Double> gauge = (Gauge<Double>) registry.getMetrics().get("gauge.foo");
assertThat(gauge.getValue()).isEqualTo(new Double(2.7));
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:MetricRepositoryAutoConfigurationTests.java
示例2: recordsHttpInteractions
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Test
public void recordsHttpInteractions() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
Config.class, MetricFilterAutoConfiguration.class);
Filter filter = context.getBean(Filter.class);
final MockHttpServletRequest request = new MockHttpServletRequest("GET",
"/test/path");
final MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain chain = mock(FilterChain.class);
willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
response.setStatus(200);
return null;
}
}).given(chain).doFilter(request, response);
filter.doFilter(request, response, chain);
verify(context.getBean(CounterService.class)).increment("status.200.test.path");
verify(context.getBean(GaugeService.class)).submit(eq("response.test.path"),
anyDouble());
context.close();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:23,代码来源:MetricFilterAutoConfigurationTests.java
示例3: records302HttpInteractionsAsSingleMetric
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Test
public void records302HttpInteractionsAsSingleMetric() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
Config.class, MetricFilterAutoConfiguration.class, RedirectFilter.class);
MetricsFilter filter = context.getBean(MetricsFilter.class);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
.addFilter(filter).addFilter(context.getBean(RedirectFilter.class))
.build();
mvc.perform(get("/unknownPath/1")).andExpect(status().is3xxRedirection());
mvc.perform(get("/unknownPath/2")).andExpect(status().is3xxRedirection());
verify(context.getBean(CounterService.class), times(2))
.increment("status.302.unmapped");
verify(context.getBean(GaugeService.class), times(2))
.submit(eq("response.unmapped"), anyDouble());
context.close();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:MetricFilterAutoConfigurationTests.java
示例4: controllerMethodThatThrowsUnhandledException
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Test
public void controllerMethodThatThrowsUnhandledException() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
Config.class, MetricFilterAutoConfiguration.class);
Filter filter = context.getBean(Filter.class);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
.addFilter(filter).build();
try {
mvc.perform(get("/unhandledException"))
.andExpect(status().isInternalServerError());
}
catch (NestedServletException ex) {
// Expected
}
verify(context.getBean(CounterService.class))
.increment("status.500.unhandledException");
verify(context.getBean(GaugeService.class))
.submit(eq("response.unhandledException"), anyDouble());
context.close();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:MetricFilterAutoConfigurationTests.java
示例5: gaugeServiceThatThrows
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Test
public void gaugeServiceThatThrows() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
Config.class, MetricFilterAutoConfiguration.class);
GaugeService gaugeService = context.getBean(GaugeService.class);
willThrow(new IllegalStateException()).given(gaugeService).submit(anyString(),
anyDouble());
Filter filter = context.getBean(Filter.class);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
.addFilter(filter).build();
mvc.perform(get("/templateVarTest/foo")).andExpect(status().isOk());
verify(context.getBean(CounterService.class))
.increment("status.200.templateVarTest.someVariable");
verify(context.getBean(GaugeService.class))
.submit(eq("response.templateVarTest.someVariable"), anyDouble());
context.close();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:MetricFilterAutoConfigurationTests.java
示例6: records5xxxHttpInteractionsAsSingleMetric
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Test
public void records5xxxHttpInteractionsAsSingleMetric() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
Config.class, MetricFilterAutoConfiguration.class,
ServiceUnavailableFilter.class);
MetricsFilter filter = context.getBean(MetricsFilter.class);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
.addFilter(filter)
.addFilter(context.getBean(ServiceUnavailableFilter.class)).build();
mvc.perform(get("/unknownPath/1")).andExpect(status().isServiceUnavailable());
mvc.perform(get("/unknownPath/2")).andExpect(status().isServiceUnavailable());
verify(context.getBean(CounterService.class), times(2))
.increment("status.503.unmapped");
verify(context.getBean(GaugeService.class), times(2))
.submit(eq("response.unmapped"), anyDouble());
context.close();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:MetricFilterAutoConfigurationTests.java
示例7: doesNotRecordRolledUpMetricsIfConfigured
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Test
public void doesNotRecordRolledUpMetricsIfConfigured() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Config.class, MetricFilterAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(context,
"endpoints.metrics.filter.gauge-submissions=",
"endpoints.metrics.filter.counter-submissions=");
context.refresh();
Filter filter = context.getBean(Filter.class);
final MockHttpServletRequest request = new MockHttpServletRequest("PUT",
"/test/path");
final MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain chain = mock(FilterChain.class);
willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
response.setStatus(200);
return null;
}
}).given(chain).doFilter(request, response);
filter.doFilter(request, response, chain);
verify(context.getBean(GaugeService.class), never()).submit(anyString(),
anyDouble());
verify(context.getBean(CounterService.class), never()).increment(anyString());
context.close();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:27,代码来源:MetricFilterAutoConfigurationTests.java
示例8: provideAdditionalWriter
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Test
public void provideAdditionalWriter() {
this.context = new AnnotationConfigApplicationContext(WriterConfig.class,
MetricRepositoryAutoConfiguration.class,
MetricExportAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
GaugeService gaugeService = this.context.getBean(GaugeService.class);
assertThat(gaugeService).isNotNull();
gaugeService.submit("foo", 2.7);
MetricExporters exporters = this.context.getBean(MetricExporters.class);
MetricCopyExporter exporter = (MetricCopyExporter) exporters.getExporters()
.get("writer");
exporter.setIgnoreTimestamps(true);
exporter.export();
MetricWriter writer = this.context.getBean("writer", MetricWriter.class);
Mockito.verify(writer, Mockito.atLeastOnce()).set(Matchers.any(Metric.class));
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:MetricExportAutoConfigurationTests.java
示例9: configureKafkaMetrics
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
/**
* Method for setting Kafka-related properties, required for proper updating of metrics.
*
* @param configs {@link Map} with Kafka-specific properties, required to initialize the appropriate consumer/producer.
* @param gaugeService reference to an instance of Springs {@link GaugeService}, used to set the collected metrics
* @param prefix initial part of the metric's label
* @param executorService reference to an instance of {@link ScheduledExecutorService}, used to schedule periodic values' recalculation for metrics
* @param updateInterval interval for iterating the whole set of tracked metrics to recalculate and resubmit their values
*/
public static void configureKafkaMetrics(Map<String, Object> configs, GaugeService gaugeService, String prefix, ScheduledExecutorService executorService, Long updateInterval) {
if (gaugeService == null) {
throw new IllegalArgumentException("Initializing GaugeService as null is meaningless!");
}
configs.put(CommonClientConfigs.METRIC_REPORTER_CLASSES_CONFIG, Collections.singletonList(KafkaStatisticsProvider.class.getName()));
configs.put(KafkaStatisticsProvider.METRICS_GAUGE_SERVICE_IMPL, gaugeService);
LOGGER.debug("Set property {} with provided GaugeService instance reference", KafkaStatisticsProvider.METRICS_GAUGE_SERVICE_IMPL);
if (executorService != null) {
configs.put(KafkaStatisticsProvider.METRICS_UPDATE_EXECUTOR_IMPL, executorService);
LOGGER.debug("Set property {} with provided ScheduledExecutorService instance reference", KafkaStatisticsProvider.METRICS_UPDATE_EXECUTOR_IMPL);
}
if (updateInterval != null) {
configs.put(KafkaStatisticsProvider.METRICS_UPDATE_INTERVAL_PARAM, updateInterval);
LOGGER.debug("Set property {} with value {}", KafkaStatisticsProvider.METRICS_UPDATE_INTERVAL_PARAM, updateInterval);
}
if (prefix != null) {
configs.put(KafkaStatisticsProvider.METRICS_PREFIX_PARAM, prefix);
LOGGER.debug("Set property {} with value {}", KafkaStatisticsProvider.METRICS_PREFIX_PARAM, prefix);
}
}
示例10: configureKafkaMetrics_withGaugeServiceAndPrefix
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Test
public void configureKafkaMetrics_withGaugeServiceAndPrefix() {
Map<String, Object> config = new HashMap<>();
assertThat(config).isEmpty();
GaugeService gaugeService = mockGaugeService();
String prefix = "test.prefix";
KafkaConfigUtils.configureKafkaMetrics(config, gaugeService, prefix, null, null);
assertThat(config).hasSize(3);
assertThat(config.get(CommonClientConfigs.METRIC_REPORTER_CLASSES_CONFIG))
.asList()
.contains(KafkaStatisticsProvider.class.getCanonicalName());
assertThat(config.get(KafkaStatisticsProvider.METRICS_GAUGE_SERVICE_IMPL)).isSameAs(gaugeService);
assertThat(config.get(KafkaStatisticsProvider.METRICS_PREFIX_PARAM)).isEqualTo(prefix);
assertThat(config.get(KafkaStatisticsProvider.METRICS_UPDATE_EXECUTOR_IMPL)).isNull();
assertThat(config.get(KafkaStatisticsProvider.METRICS_UPDATE_INTERVAL_PARAM)).isNull();
}
示例11: configureKafkaMetrics_withGaugeServiceAndInterval
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Test
public void configureKafkaMetrics_withGaugeServiceAndInterval() {
Map<String, Object> config = new HashMap<>();
assertThat(config).isEmpty();
GaugeService gaugeService = mockGaugeService();
Long universalAnswer = 42L;
KafkaConfigUtils.configureKafkaMetrics(config, gaugeService, null, null, universalAnswer);
assertThat(config).hasSize(3);
assertThat(config.get(CommonClientConfigs.METRIC_REPORTER_CLASSES_CONFIG))
.asList()
.contains(KafkaStatisticsProvider.class.getCanonicalName());
assertThat(config.get(KafkaStatisticsProvider.METRICS_GAUGE_SERVICE_IMPL)).isSameAs(gaugeService);
assertThat(config.get(KafkaStatisticsProvider.METRICS_PREFIX_PARAM)).isNull();
assertThat(config.get(KafkaStatisticsProvider.METRICS_UPDATE_EXECUTOR_IMPL)).isNull();
assertThat(config.get(KafkaStatisticsProvider.METRICS_UPDATE_INTERVAL_PARAM)).isEqualTo(universalAnswer);
}
示例12: configureKafkaMetrics_withGaugeServiceAndExecutors
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Test
public void configureKafkaMetrics_withGaugeServiceAndExecutors() {
ScheduledExecutorService executors = Executors.newSingleThreadScheduledExecutor();
try {
Map<String, Object> config = new HashMap<>();
assertThat(config).isEmpty();
GaugeService gaugeService = mockGaugeService();
KafkaConfigUtils.configureKafkaMetrics(config, gaugeService, null, executors, null);
assertThat(config).hasSize(3);
assertThat(config.get(CommonClientConfigs.METRIC_REPORTER_CLASSES_CONFIG))
.asList()
.contains(KafkaStatisticsProvider.class.getCanonicalName());
assertThat(config.get(KafkaStatisticsProvider.METRICS_GAUGE_SERVICE_IMPL)).isSameAs(gaugeService);
assertThat(config.get(KafkaStatisticsProvider.METRICS_PREFIX_PARAM)).isNull();
assertThat(config.get(KafkaStatisticsProvider.METRICS_UPDATE_EXECUTOR_IMPL)).isSameAs(executors);
assertThat(config.get(KafkaStatisticsProvider.METRICS_UPDATE_INTERVAL_PARAM)).isNull();
}
finally {
executors.shutdown();
}
}
示例13: dropwizardInstalledIfPresent
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Test
public void dropwizardInstalledIfPresent() {
this.context = new AnnotationConfigApplicationContext(
MetricsDropwizardAutoConfiguration.class,
MetricRepositoryAutoConfiguration.class, AopAutoConfiguration.class);
GaugeService gaugeService = this.context.getBean(GaugeService.class);
assertNotNull(gaugeService);
gaugeService.submit("foo", 2.7);
DropwizardMetricServices exporter = this.context
.getBean(DropwizardMetricServices.class);
assertEquals(gaugeService, exporter);
MetricRegistry registry = this.context.getBean(MetricRegistry.class);
@SuppressWarnings("unchecked")
Gauge<Double> gauge = (Gauge<Double>) registry.getMetrics().get("gauge.foo");
assertEquals(new Double(2.7), gauge.getValue());
}
示例14: provideAdditionalWriter
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Test
public void provideAdditionalWriter() {
this.context = new AnnotationConfigApplicationContext(WriterConfig.class,
MetricRepositoryAutoConfiguration.class,
MetricExportAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
GaugeService gaugeService = this.context.getBean(GaugeService.class);
assertNotNull(gaugeService);
gaugeService.submit("foo", 2.7);
MetricExporters exporters = this.context.getBean(MetricExporters.class);
MetricCopyExporter exporter = (MetricCopyExporter) exporters.getExporters()
.get("writer");
exporter.setIgnoreTimestamps(true);
exporter.export();
MetricWriter writer = this.context.getBean("writer", MetricWriter.class);
Mockito.verify(writer, Mockito.atLeastOnce()).set(Matchers.any(Metric.class));
}
示例15: TimerAspect
import org.springframework.boot.actuate.metrics.GaugeService; //导入依赖的package包/类
@Autowired
public TimerAspect(GaugeService gaugeService,
CounterService counterService, ObjectMapper mapper) {
this.counterService = counterService;
this.gaugeService = gaugeService;
this.mapper = mapper;
}