当前位置: 首页>>代码示例>>Java>>正文


Java CreateTimeSeriesRequest类代码示例

本文整理汇总了Java中com.google.api.services.monitoring.v3.model.CreateTimeSeriesRequest的典型用法代码示例。如果您正苦于以下问题:Java CreateTimeSeriesRequest类的具体用法?Java CreateTimeSeriesRequest怎么用?Java CreateTimeSeriesRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CreateTimeSeriesRequest类属于com.google.api.services.monitoring.v3.model包,在下文中一共展示了CreateTimeSeriesRequest类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleTimeSeriesResponseException

import com.google.api.services.monitoring.v3.model.CreateTimeSeriesRequest; //导入依赖的package包/类
/**
 * Helper function for logging time series errors in more detail.
 *
 * @see #findProblematicTimeSeriesElement
 */
private void handleTimeSeriesResponseException(
     HttpResponseException rex, String msg, List<TimeSeries> nextN) {
  Matcher matcher = INVALID_LABEL_REGEX.matcher(rex.getContent());
  TimeSeries ts = null;
  String label = null;
  if (matcher.find()) {
    int tsIndex = Integer.parseInt(matcher.group(1));
    ts = nextN.get(tsIndex);
    label = matcher.group(2);
    log.error("{}:  time series element: {}",
              rex.getMessage(), ts.toString());
    cache.addLabel(ts.getMetric().getType(), label);
    try {
      log.info("Retrying individual time series element");
      CreateTimeSeriesRequest tsRequest = new CreateTimeSeriesRequest();
      tsRequest.setTimeSeries(nextN.subList(tsIndex, tsIndex + 1));
      service.projects().timeSeries().create(projectResourceName, tsRequest)
          .execute();
    } catch (IOException ioex) {
      log.error("Retry failed with " + ioex);
    }
  } else {
    log.error("Caught HttpResponseException {}", msg, rex);
  }
}
 
开发者ID:spinnaker,项目名称:kork,代码行数:31,代码来源:StackdriverWriter.java

示例2: reportMetrics

import com.google.api.services.monitoring.v3.model.CreateTimeSeriesRequest; //导入依赖的package包/类
private void reportMetrics(LatencyDistribution distribution) {
  if (distribution.getCount() == 0) {
    return;
  }
  CreateTimeSeriesRequest request;
  synchronized (this) {
    String now = dateFormatter.format(new Date());
    request = new CreateTimeSeriesRequest().setTimeSeries(Collections.singletonList(
        new TimeSeries()
            .setMetric(new Metric()
                .setType("custom.googleapis.com/cloud-pubsub/loadclient/" + metricName)
                .setLabels(ImmutableMap.of("client_type", clientType)))
            .setMetricKind("GAUGE")
            .setValueType("DISTRIBUTION")
            .setPoints(Collections.singletonList(new Point()
                .setValue(new TypedValue()
                    .setDistributionValue(new Distribution()
                        .setBucketCounts(distribution.getBucketValuesAsList())
                        .setCount(distribution.getCount())
                        .setMean(distribution.getMean())
                        .setSumOfSquaredDeviation(distribution.getSumOfSquareDeviations())
                        .setBucketOptions(new BucketOptions()
                            .setExplicitBuckets(new Explicit().setBounds(
                                Arrays.asList(ArrayUtils.toObject(
                                    LatencyDistribution.LATENCY_BUCKETS)))))))
                .setInterval(new TimeInterval()
                    .setStartTime(now)
                    .setEndTime(now))))
            .setResource(monitoredResource)));
  }
  try {
    monitoring.projects().timeSeries().create("projects/" + project, request).execute();
  } catch (IOException e) {
    log.error("Error reporting latency.", e);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:37,代码来源:MetricsHandler.java

示例3: setUp

import com.google.api.services.monitoring.v3.model.CreateTimeSeriesRequest; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  when(metric.getValueClass()).thenReturn(Long.class);
  when(metric.getCardinality()).thenReturn(1);
  when(metric.getMetricSchema())
      .thenReturn(
          MetricSchema.create(
              "/name",
              "desc",
              "vdn",
              Kind.CUMULATIVE,
              ImmutableSet.of(LabelDescriptor.create("label1", "desc1"))));
  // Store in an intermediate value, because Mockito hates when mocks are evaluated inside of
  // thenReturn() methods.
  MetricPoint<Long> longPoint =
      MetricPoint.create(
          metric,
          ImmutableList.of("value1"),
          Instant.ofEpochMilli(1337),
          Instant.ofEpochMilli(1338),
          5L);
  when(metric.getTimestampedValues()).thenReturn(ImmutableList.of(longPoint));

  when(boolMetric.getValueClass()).thenReturn(Boolean.class);
  when(boolMetric.getMetricSchema())
      .thenReturn(
          MetricSchema.create(
              "/name",
              "desc",
              "vdn",
              Kind.GAUGE,
              ImmutableSet.of(LabelDescriptor.create("label1", "desc1"))));
  // Store in an intermediate value, because Mockito hates when mocks are evaluated inside of
  // thenReturn() methods.
  MetricPoint<Boolean> boolPoint =
      MetricPoint.create(boolMetric, ImmutableList.of("foo"), Instant.ofEpochMilli(1337), true);
  when(boolMetric.getTimestampedValues()).thenReturn(ImmutableList.of(boolPoint));

  when(distributionMetric.getMetricSchema())
      .thenReturn(
          MetricSchema.create(
              "/name",
              "desc",
              "vdn",
              Kind.GAUGE,
              ImmutableSet.of(LabelDescriptor.create("label1", "desc1"))));
  when(distributionMetric.getValueClass()).thenReturn(Distribution.class);

  MetricDescriptor descriptor = StackdriverWriter.encodeMetricDescriptor(metric);
  when(client.projects()).thenReturn(projects);
  when(projects.metricDescriptors()).thenReturn(metricDescriptors);
  when(projects.timeSeries()).thenReturn(timeSeries);
  when(metricDescriptors.create(anyString(), any(MetricDescriptor.class)))
      .thenReturn(metricDescriptorCreate);
  when(metricDescriptorCreate.execute()).thenReturn(descriptor);
  when(metricDescriptors.get(anyString())).thenReturn(metricDescriptorGet);
  when(metricDescriptorGet.execute()).thenReturn(descriptor);
  when(timeSeries.create(anyString(), any(CreateTimeSeriesRequest.class)))
      .thenReturn(timeSeriesCreate);
}
 
开发者ID:google,项目名称:java-monitoring-client-library,代码行数:61,代码来源:StackdriverWriterTest.java

示例4: writeRegistryHelper

import com.google.api.services.monitoring.v3.model.CreateTimeSeriesRequest; //导入依赖的package包/类
/**
 * Implementation of writeRegistry wrapped for timing.
 */
private void writeRegistryHelper(Registry registry) {
  MonitoredResource resource = determineMonitoredResource();
  if (resource == null) {
    log.warn("Cannot determine the managed resource - not flushing metrics.");
    return;
  }
  List<TimeSeries> tsList = registryToTimeSeries(registry);
  if (tsList.isEmpty()) {
     log.debug("No metric data points.");
     return;
  }

  CreateTimeSeriesRequest tsRequest = new CreateTimeSeriesRequest();
  int offset = 0;
  int failed = 0;
  List<TimeSeries> nextN;

  log.debug("Writing metrics...");
  while (offset < tsList.size()) {
    if (offset + MAX_TS_PER_REQUEST < tsList.size()) {
      nextN = tsList.subList(offset, offset + MAX_TS_PER_REQUEST);
      offset += MAX_TS_PER_REQUEST;
    } else {
      nextN = tsList.subList(offset, tsList.size());
      offset = tsList.size();
    }
    tsRequest.setTimeSeries(nextN);
    try {
      service.projects().timeSeries().create(projectResourceName, tsRequest)
             .execute();
    } catch (HttpResponseException rex) {
      handleTimeSeriesResponseException(rex, "creating time series", nextN);
      failed += nextN.size();
    } catch (IOException ioex) {
      log.error("Caught Exception creating time series " + ioex);
      failed += nextN.size();
    }
  }
  log.debug("Wrote {} values", tsList.size() - failed);
}
 
开发者ID:spinnaker,项目名称:kork,代码行数:44,代码来源:StackdriverWriter.java


注:本文中的com.google.api.services.monitoring.v3.model.CreateTimeSeriesRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。