- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
Google 已警告 v2 监控 API 现已弃用,并将很快消失。然而,事实证明迁移到 v3 有点困难。我正在尝试编写自定义指标并收到以下错误响应:
服务 > Google Monitoring API v3 > monitoring.projects.timeSeries.create
{
"timeSeries": [{
"metric": {
"type": "custom.googleapis.com/test_metric",
"labels": {
"payment_type": "Paypal"
}
},
"resource": {
"type": "custom.googleapis.com/test_metric",
"labels": {
"payment_type": "Paypal"
}
},
"metricKind": "GAUGE",
"valueType": "INT64",
"points": [{
"interval": {
"endTime": "2016-03-20T15:01:23.045123456Z",
"startTime": "2016-03-20T15:01:23.045123456Z"
},
"value": {
"int64Value": "2"
}
}]
}]
}
{
"error": {
"code": 400,
"message": "Field timeSeries[0].resource.type had an invalid value of \"custom.googleapis.com/test_metric\": Unrecognized resource name.",
"status": "INVALID_ARGUMENT"
}
“资源”字段是必需的,文档说它是“MonitoredResource”...但我没有看到任何用于创建一个的 api,仅用于列表。大胆猜测并将其设置为“全局”似乎让我走得更远,并给了我这个不同的错误:
{
"error": {
"code": 400,
"message": "Field timeSeries[0].resource.labels[0] had an invalid value of \"payment_type\": Unrecognized resource label.",
"status": "INVALID_ARGUMENT"
}
}
列出指标描述符表明 payment_type 存在:
服务 > Google Monitoring API v3 > monitoring.projects.metricDescriptors.list
{
"name": "projects/gearlaunch-hub-sandbox/metricDescriptors/custom.googleapis.com/test_metric",
"labels": [
{
"key": "payment_type"
}
],
"metricKind": "GAUGE",
"valueType": "INT64",
"description": "Test",
"type": "custom.googleapis.com/test_metric"
}
我已经通读了迁移指南和相关文档,但仍然受阻。有人知道我在这里缺少什么吗?
更新:虽然看起来可以通过从 json 中删除“resource.labels”来实现这一点,但我仍在寻找一种通过 java 客户端 api 实现这一点的方法.
更新 2:接受的( self 回答的)问题显示了如何使用 java api 执行此操作。
最佳答案
看起来答案是使用“类型”的“资源”:“全局”但不要使用“标签”:
{
"timeSeries": [{
"metric": {
"type": "custom.googleapis.com/test_metric",
"labels": {
"payment_type": "Paypal"
}
},
"resource": {
"type": "global"
},
"metricKind": "GAUGE",
"valueType": "INT64",
"points": [{
"interval": {
"endTime": "2016-03-23T01:01:23.045123456Z",
"startTime": "2016-03-23T01:01:23.045123456Z"
},
"value": {
"int64Value": "2"
}
}]
}]
}
这给了我 200 OK 响应并将数据添加到时间序列。
这直接在 api 资源管理器中工作。使用 java 客户端 api 的等效代码是:
public String writeCustomMetricValue(final String name, final Map<String, String> labels, final Long value) {
Preconditions.checkNotNull(name);
Preconditions.checkNotNull(labels);
Preconditions.checkNotNull(value);
final String now = DateTime.now().withZone(DateTimeZone.UTC).toString();
final TimeInterval interval = new TimeInterval();
interval.setStartTime(now);
interval.setEndTime(now);
final TypedValue pointValue = new TypedValue();
pointValue.setInt64Value(value);
final Point point = new Point();
point.setInterval(interval);
point.setValue(pointValue);
final MonitoredResource resource = new MonitoredResource();
resource.setType("global");
final Metric metric = new Metric();
metric.setType("custom.googleapis.com/" + name);
final TimeSeries series = new TimeSeries();
series.setMetric(metric);
series.setPoints(Arrays.asList(point));
series.setResource(resource);
series.setMetricKind("GAUGE");
final List<TimeSeries> timeseries = new ArrayList<>();
timeseries.add(series);
final CreateTimeSeriesRequest content = new CreateTimeSeriesRequest();
content.setTimeSeries(timeseries);
metric.setLabels(labels);
try {
return service().projects().timeSeries().create("projects/" + env.getProjectId().getId(), content).execute().toPrettyString();
} catch (Exception e) {
throw new RuntimeException("Name=" + name + ", labels=" + labels + ", value=" + value, e);
}
}
使用:
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-monitoring</artifactId>
<version>v3-rev3-1.21.0</version>
</dependency>
关于google-app-engine - 使用 Google Cloud Monitoring v3 api 写入自定义时间序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36164939/
我是 iOS 开发新手。我正在解决的是如何在 iPhone 中运行我的应用程序时获取有关该应用程序的信息。 例如:当我在 Android 中开发时,我连接手机(使用净化模式)并打开 Android M
我仍然不确定这两个调用之间的区别。来自 MSDN, Monitor.Enter(Object) 获取指定对象的独占锁。 Monitor.Wait(Object) 释放对象上的锁并阻塞当前线程,直到它重
我是 GCP 的新手并且来自 Azure 背景。在 GCP 端是否有等效的“Azure Application Insights”用于监控应用程序? 让我用一个例子更清楚地解释我的用例:如果我有一个基
这是说明问题的最小代码: StringBuilder input = new StringBuilder(); void ToUpper() { lock (input) {
我在 ASP.NET 中有一个生产者-消费者场景。我设计了一个Producer 类,一个Consumer 类和一个用于保存共享对象并负责Producer 和Consumer 之间通信的类,我们称它为M
是否可以检测是否是同一个线程试图释放锁?我们在代码中有很多地方看起来像: try { try { if(!Monitor.TryEnter(obj, 2000))
我对并发编程有点陌生,正在尝试了解使用 Monitor.Pulse 和 Monitor.Wait 的好处。 MSDN 的例子如下: class MonitorSample { const in
如果您想在退出和清理对象时阻止执行某些代码块,是否可以使用锁来阻止执行? Monitor.TryEnter(cleanupLock, ref acquiredLock); TryEnter 可用于确保
Monitor.Enter 和 Monitor.Exit 设计为从同一线程调用。但是,如果我需要在与获得的线程不同的线程中释放锁怎么办? 例如:有共享资源和使用该资源的异步操作。该操作以 BeginO
Monitor.PulseAll 通知队列中的所有等待线程。 Monitor.Pulse 通知等待队列中的一个线程。 (下一个等待线程) 只有下一个线程(一个线程)才能获取锁。那有什么区别呢? 什么时
我正在尝试在我的 terraform 代码库中集成对 sshd 进程的 Datadog 监视器检查,但我收到 datadog_monitor.host_is_up2: error updating m
这里的问题是:如果获取对象独占锁的线程(例如通过使用 Monitor.Enter)终止,是否会神奇地释放该对象的独占锁?如果那是真的,那么假设我们从另一个线程调用 Monitor.Exit - 因为我
我正在研究 .NET 中的 Monitor 类,所以我找到了一段似乎可以正常工作的代码,但是当我将它循环一段时间时,它会抛出 OutOfMemoryException。 我在具有 8 GB RAM 的
ECMA-335 规范规定如下: *获取锁(System.Threading.Monitor.Enter 或进入同步方法)应隐式执行 volatile 读取操作,并释放锁(System.Threadi
我在 dll 中使用 OmniThreadLibrary 2.09,主应用程序和 dll 使用相同的 SimpleShareMem 内存管理器。 我用以下代码创建了自己的监视器: FMonitor
我正在使用 R 包 monitoR并收到一条我无法理解的错误消息。 我正在尝试使用 dbUploadTemplate 命令将关联模板列表(“bithTemps”)上传到 MySQL 数据库(“noh”
我想我遗漏了一些关于 Monitor.Enter 和 Monitor.TryEnter 正确行为的信息。这是我编写的一段代码,用于将问题与其余代码分开: object lockObj = new ob
我正在尝试实现一个多线程库,该库将使用线程池同时运行任务。基本上它会从它收到的收集参数中将任务添加到线程池,然后等待直到正在处理的最后一个任务发送脉冲信号。我在早期的测试中取得了成功,但是当我想测试处
我想用redis lua来实现monitor命令,而不是redis-cli monitor。但我不知道怎么办。 redis.call('monitor') 不起作用。 最佳答案 您不能从 Redis
根据语言规范,lock(obj) statement; 会被编译为: object lockObj = obj; // (the langspec doesn't mention this var,
我是一名优秀的程序员,十分优秀!