带有 set_function 的 Perl prometheus gauge add label 没有给出预期的结果
Perl prometheus gauge add label with set_function does not give the expected result
我正在尝试为普罗米修斯仪表添加标签。使用 set 方法工作得很好,但我似乎无法正确使用 set_function 方法。
结果是我在使用 set_function 方法的地方看不到仪表指标。
结果(清理)如下:
# HELP Test Test help
# TYPE Test gauge
第三行应该是“Test{color="red"} 123"
Pastebin 到代码。
#!/usr/bin/env perl
use Net::Prometheus;
my $client = Net::Prometheus->new;
$client->new_gauge(name => "Test", help => "Test help", labels => [qw/color/])->set_function('red', sub { return 123 });
print $client->render;
不确定我做错了什么,或者这是一个错误?
普罗米修斯new_gauge->new_function()
METHODS
set
$gauge->set( [ @label_values ], $value )
$child->set($value )
Sets the current value for the gauge.
If the gauge has any labels defined, the values for them must be given
first.
set_function
$gauge->set_function( [ @label_values ], $func )
$child->set_function( $func )
Sets a value-returning callback function
for the gauge. If the gauge is labeled, each label combination
requires its own function.
When invoked, the function will be passed no arguments and is expected
to return a single value
我不确定这是否是 Net::Prometheus 的预期方法,但创建一个仪表、设置一个值然后设置一个函数对我有用:
my $c = Net::Prometheus->new;
my $g = $c->new_gauge(name=>'Test',help=>'help',labels=>['color']);
$g->set('red',1);
$g->set_function('red',sub { warn 'Getter called'; 123 });
print $c->render
这输出
Getter called at ...
# HELP Test help
# TYPE Test gauge
Test{color="red"} 123
我认为文档对此可能更清楚一些。
这已在 0.06 release 中解决。
我正在尝试为普罗米修斯仪表添加标签。使用 set 方法工作得很好,但我似乎无法正确使用 set_function 方法。
结果是我在使用 set_function 方法的地方看不到仪表指标。
结果(清理)如下:
# HELP Test Test help
# TYPE Test gauge
第三行应该是“Test{color="red"} 123"
Pastebin 到代码。
#!/usr/bin/env perl
use Net::Prometheus;
my $client = Net::Prometheus->new;
$client->new_gauge(name => "Test", help => "Test help", labels => [qw/color/])->set_function('red', sub { return 123 });
print $client->render;
不确定我做错了什么,或者这是一个错误?
普罗米修斯new_gauge->new_function()
METHODS
set
$gauge->set( [ @label_values ], $value )
$child->set($value )Sets the current value for the gauge.
If the gauge has any labels defined, the values for them must be given first.
set_function
$gauge->set_function( [ @label_values ], $func )
$child->set_function( $func )Sets a value-returning callback function for the gauge. If the gauge is labeled, each label combination requires its own function.
When invoked, the function will be passed no arguments and is expected to return a single value
我不确定这是否是 Net::Prometheus 的预期方法,但创建一个仪表、设置一个值然后设置一个函数对我有用:
my $c = Net::Prometheus->new;
my $g = $c->new_gauge(name=>'Test',help=>'help',labels=>['color']);
$g->set('red',1);
$g->set_function('red',sub { warn 'Getter called'; 123 });
print $c->render
这输出
Getter called at ...
# HELP Test help
# TYPE Test gauge
Test{color="red"} 123
我认为文档对此可能更清楚一些。
这已在 0.06 release 中解决。