我尝试使用此模块编写Prometheus配置:Cubbi
但我似乎无法为Prometheus生成有效的重新标记配置。
这是我当前配置的相关部分:
relabel_configs:
- source_labels: '[__meta_consul_node]'
regex: ^(.*)$
target_label: instance
replacement: $1
- source_labels: '[__meta_consul_service]'
regex: ^(.*)$
target_label: job
replacement: $1
这是我在prometheus.yml中获得的:
relabel_configs:
- source_labels: ['__meta_consul_node']
regex: '^(.*)$'
target_label: 'instance'
replacement: '$1'
- source_labels: ['__meta_consul_service']
regex: '^(.*)$'
target_label: 'job'
replacement: '$1'
我想要的是:
'
我尝试了很多东西,但是无法弄清楚如何在清单中格式化哈希值,以便为Prometheus获取正确的配置文件。
这似乎是ruby解析器的一个问题?如何正确逃避public class MainActivity extends AppCompatActivity{
private static final String JSON_URL =
"http://**.***.***.***:5495/api/StudentAPI/GetAllStudent";
private boolean networkOk;
TextView output;
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String message =
intent.getStringExtra(myService.MY_SERVICE_PAYLOAD);
output.append(message + "\n");
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
output = (TextView) findViewById(R.id.output);
LocalBroadcastManager.getInstance(getApplicationContext())
.registerReceiver(mBroadcastReceiver,
new IntentFilter(myService.MY_SERVICE_MESSAGE));
networkOk = NetworkHelper.hasNetworkAccess(this);
output.append("Network ok: " + networkOk);
}
@Override
protected void onDestroy() {
super.onDestroy();
LocalBroadcastManager.getInstance(getApplicationContext())
.unregisterReceiver(mBroadcastReceiver);
}
public void runClickHandler(View view){
Intent intent = new Intent(this, myService.class);
intent.setData(Uri.parse(JSON_URL));
startService(intent);
}
public void clearClickHandler(View view){output.setText(""); }
}
?
答案 0 :(得分:2)
我认为这里的混淆是如何在Puppet和YAML中处理变量数组,以及如何在YAML中解析字符串。
在YAML中,变量数组可以是:
array:
- element
- another_element
或:
array: [element, another_element]
在Puppet中,它们看起来像:
$array = [element, another_element]
因此,只需在source_labels
键的Puppet散列中指定一个字符串数组,就可以对数组进行一对一的干净映射,如:
'relabel_configs' => [
{
'source_labels' => ['__meta_consul_node'], # single element string array
'regex' => '^(.*)$',
'target_label' => 'instance',
'replacement' => '$1',
},
{
'source_labels' => ['__meta_consul_service'], # single element string array
'regex' => '^(.*)$',
'target_label' => 'job',
'replacement' => '$1',
}
],
这将为您source_labels
正确生成一系列字符串,如您所描述的那样。
relabel_configs:
- source_labels: ['__meta_consul_node'] # single element string array
regex: ^(.*)$
target_label: instance
replacement: $1
- source_labels: ['__meta_consul_service'] # single element string array
regex: ^(.*)$
target_label: job
replacement: $1
请注意,对于引用和未引用的字符串,YAML的解析方式完全相同(例如target_label: job
与target_label: 'job'
相同)。