mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-27 18:56:30 +00:00
Fix stats dymanic reload (#87)
This commit is contained in:
@@ -60,7 +60,7 @@ mod sharding;
|
|||||||
mod stats;
|
mod stats;
|
||||||
|
|
||||||
use config::{get_config, reload_config};
|
use config::{get_config, reload_config};
|
||||||
use pool::{get_pool, ClientServerMap, ConnectionPool};
|
use pool::{ClientServerMap, ConnectionPool};
|
||||||
use stats::{Collector, Reporter, REPORTER};
|
use stats::{Collector, Reporter, REPORTER};
|
||||||
|
|
||||||
#[tokio::main(worker_threads = 4)]
|
#[tokio::main(worker_threads = 4)]
|
||||||
@@ -120,8 +120,6 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let pool = get_pool();
|
|
||||||
|
|
||||||
// Statistics collector task.
|
// Statistics collector task.
|
||||||
let collector_tx = tx.clone();
|
let collector_tx = tx.clone();
|
||||||
|
|
||||||
@@ -129,16 +127,13 @@ async fn main() {
|
|||||||
let reload_client_server_map = client_server_map.clone();
|
let reload_client_server_map = client_server_map.clone();
|
||||||
let autoreload_client_server_map = client_server_map.clone();
|
let autoreload_client_server_map = client_server_map.clone();
|
||||||
|
|
||||||
let addresses = pool.databases();
|
|
||||||
tokio::task::spawn(async move {
|
tokio::task::spawn(async move {
|
||||||
let mut stats_collector = Collector::new(rx, collector_tx);
|
let mut stats_collector = Collector::new(rx, collector_tx);
|
||||||
stats_collector.collect(addresses).await;
|
stats_collector.collect().await;
|
||||||
});
|
});
|
||||||
|
|
||||||
info!("Waiting for clients");
|
info!("Waiting for clients");
|
||||||
|
|
||||||
drop(pool);
|
|
||||||
|
|
||||||
// Client connection loop.
|
// Client connection loop.
|
||||||
tokio::task::spawn(async move {
|
tokio::task::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ use parking_lot::Mutex;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
||||||
|
|
||||||
|
use crate::pool::get_pool;
|
||||||
|
|
||||||
pub static REPORTER: Lazy<ArcSwap<Reporter>> =
|
pub static REPORTER: Lazy<ArcSwap<Reporter>> =
|
||||||
Lazy::new(|| ArcSwap::from_pointee(Reporter::default()));
|
Lazy::new(|| ArcSwap::from_pointee(Reporter::default()));
|
||||||
|
|
||||||
@@ -285,7 +287,7 @@ impl Collector {
|
|||||||
|
|
||||||
/// The statistics collection handler. It will collect statistics
|
/// The statistics collection handler. It will collect statistics
|
||||||
/// for `address_id`s starting at 0 up to `addresses`.
|
/// for `address_id`s starting at 0 up to `addresses`.
|
||||||
pub async fn collect(&mut self, addresses: usize) {
|
pub async fn collect(&mut self) {
|
||||||
info!("Events reporter started");
|
info!("Events reporter started");
|
||||||
|
|
||||||
let stats_template = HashMap::from([
|
let stats_template = HashMap::from([
|
||||||
@@ -329,6 +331,7 @@ impl Collector {
|
|||||||
tokio::time::interval(tokio::time::Duration::from_millis(STAT_PERIOD / 15));
|
tokio::time::interval(tokio::time::Duration::from_millis(STAT_PERIOD / 15));
|
||||||
loop {
|
loop {
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
|
let addresses = get_pool().databases();
|
||||||
for address_id in 0..addresses {
|
for address_id in 0..addresses {
|
||||||
let _ = tx.try_send(Event {
|
let _ = tx.try_send(Event {
|
||||||
name: EventName::UpdateStats,
|
name: EventName::UpdateStats,
|
||||||
@@ -346,6 +349,7 @@ impl Collector {
|
|||||||
tokio::time::interval(tokio::time::Duration::from_millis(STAT_PERIOD));
|
tokio::time::interval(tokio::time::Duration::from_millis(STAT_PERIOD));
|
||||||
loop {
|
loop {
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
|
let addresses = get_pool().databases();
|
||||||
for address_id in 0..addresses {
|
for address_id in 0..addresses {
|
||||||
let _ = tx.try_send(Event {
|
let _ = tx.try_send(Event {
|
||||||
name: EventName::UpdateAverages,
|
name: EventName::UpdateAverages,
|
||||||
|
|||||||
Reference in New Issue
Block a user