influxdb command: directly write to db rather than stdout
This commit is contained in:
parent
4b8fd09b27
commit
4c1ae6d045
1 changed files with 30 additions and 15 deletions
|
@ -28,10 +28,11 @@ sub run {
|
||||||
my $now = DateTime->now( time_zone => 'Europe/Berlin' );
|
my $now = DateTime->now( time_zone => 'Europe/Berlin' );
|
||||||
my $active = $now->clone->subtract( months => 1 );
|
my $active = $now->clone->subtract( months => 1 );
|
||||||
|
|
||||||
my @out;
|
my @stats;
|
||||||
|
my @traewelling;
|
||||||
|
|
||||||
push(
|
push(
|
||||||
@out,
|
@stats,
|
||||||
query_to_influx(
|
query_to_influx(
|
||||||
'pending_user_count',
|
'pending_user_count',
|
||||||
$db->select( 'users', 'count(*) as count', { status => 0 } )
|
$db->select( 'users', 'count(*) as count', { status => 0 } )
|
||||||
|
@ -39,7 +40,7 @@ sub run {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
push(
|
push(
|
||||||
@out,
|
@stats,
|
||||||
query_to_influx(
|
query_to_influx(
|
||||||
'reg_user_count',
|
'reg_user_count',
|
||||||
$db->select( 'users', 'count(*) as count', { status => 1 } )
|
$db->select( 'users', 'count(*) as count', { status => 1 } )
|
||||||
|
@ -47,7 +48,7 @@ sub run {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
push(
|
push(
|
||||||
@out,
|
@stats,
|
||||||
query_to_influx(
|
query_to_influx(
|
||||||
'active_user_count',
|
'active_user_count',
|
||||||
$db->select(
|
$db->select(
|
||||||
|
@ -62,30 +63,30 @@ sub run {
|
||||||
);
|
);
|
||||||
|
|
||||||
push(
|
push(
|
||||||
@out,
|
@stats,
|
||||||
query_to_influx(
|
query_to_influx(
|
||||||
'checked_in_count',
|
'checked_in_count',
|
||||||
$db->select( 'in_transit', 'count(*) as count' )->hash->{count}
|
$db->select( 'in_transit', 'count(*) as count' )->hash->{count}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
push(
|
push(
|
||||||
@out,
|
@stats,
|
||||||
query_to_influx(
|
query_to_influx(
|
||||||
'checkin_count',
|
'checkin_count',
|
||||||
$db->select( 'journeys', 'count(*) as count' )->hash->{count}
|
$db->select( 'journeys', 'count(*) as count' )->hash->{count}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
push(
|
push(
|
||||||
@out,
|
@stats,
|
||||||
query_to_influx(
|
query_to_influx(
|
||||||
'polyline_count',
|
'polyline_count',
|
||||||
$db->select( 'polylines', 'count(*) as count' )->hash->{count}
|
$db->select( 'polylines', 'count(*) as count' )->hash->{count}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
push(
|
push(
|
||||||
@out,
|
@traewelling,
|
||||||
query_to_influx(
|
query_to_influx(
|
||||||
'traewelling_pull_count',
|
'pull_user_count',
|
||||||
$db->select(
|
$db->select(
|
||||||
'traewelling',
|
'traewelling',
|
||||||
'count(*) as count',
|
'count(*) as count',
|
||||||
|
@ -94,9 +95,9 @@ sub run {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
push(
|
push(
|
||||||
@out,
|
@traewelling,
|
||||||
query_to_influx(
|
query_to_influx(
|
||||||
'traewelling_push_count',
|
'push_user_count',
|
||||||
$db->select(
|
$db->select(
|
||||||
'traewelling',
|
'traewelling',
|
||||||
'count(*) as count',
|
'count(*) as count',
|
||||||
|
@ -105,7 +106,7 @@ sub run {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
push(
|
push(
|
||||||
@out,
|
@stats,
|
||||||
query_to_influx(
|
query_to_influx(
|
||||||
'polyline_ratio',
|
'polyline_ratio',
|
||||||
$db->query(
|
$db->query(
|
||||||
|
@ -114,7 +115,21 @@ sub run {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
say join( ',', @out );
|
if ( $self->app->config->{influxdb}->{url} ) {
|
||||||
|
$self->app->ua->post_p(
|
||||||
|
$self->app->config->{influxdb}->{url},
|
||||||
|
'stats ' . join( ',', @stats )
|
||||||
|
)->wait;
|
||||||
|
$self->app->ua->post_p(
|
||||||
|
$self->app->config->{influxdb}->{url},
|
||||||
|
'traewelling ' . join( ',', @traewelling )
|
||||||
|
)->wait;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$self->app->log->warn(
|
||||||
|
"influxdb command called, but no influxdb url has been configured");
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +139,6 @@ __END__
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
Usage: index.pl influx
|
Usage: index.pl influxdb
|
||||||
|
|
||||||
Write statistics for InfluxDB to stdout
|
Write statistics to InfluxDB
|
||||||
|
|
Loading…
Reference in a new issue