@@ -40,22 +40,30 @@ impl Queries for ChContext {
4040 T : DeserializeOwned + Debug + Send + Clone + Sync + ' static ,
4141 {
4242 let query = format ! (
43- "SELECT
44- toInt64(toUnixTimestamp(toDateTime(argMax(Timestamp, Timestamp)))) AS timestamp,
45- Path AS metric,
46- toFloat64(argMax(Value, Timestamp)) AS value
47- FROM default.graphite_data
48- WHERE Path LIKE '{}.{}.{}.heartbeat'
49- GROUP BY Path" ,
43+ r#"SELECT Path AS metric,
44+ toFloat64(argMax(Value, Timestamp)) AS value,
45+ toInt64(toUnixTimestamp(toDateTime(argMax(Timestamp, Timestamp)))) AS timestamp
46+ FROM default.graphite_data
47+ WHERE Path = '{}.{}.{}.heartbeat'
48+ GROUP BY Path"# ,
5049 env, hostname, uuid
5150 ) ;
5251
53- log :: debug !( "CH Query {}" , query) ;
52+ println ! ( "CH Query\n {}" , query) ;
5453
5554 let client = self . client ( ) ;
56- let client = client. lock ( ) . await ;
5755
5856 let result = client. query ( & query) . fetch_all :: < Metric < T > > ( ) . await ;
57+
58+ match result {
59+ Ok ( ref rows) => {
60+ log:: debug!( "Fetched {} rows from CH" , rows. len( ) ) ;
61+ }
62+ Err ( ref e) => {
63+ log:: error!( "Failed to fetch heartbeat from CH: {:?}" , e) ;
64+ }
65+ }
66+
5967 result. ok ( ) . and_then ( |mut rows| rows. pop ( ) )
6068 }
6169
@@ -69,30 +77,28 @@ impl Queries for ChContext {
6977 {
7078 let start_str = start. format ( "%Y-%m-%d %H:%M:%S" ) . to_string ( ) ;
7179 let query = format ! (
72- "SELECT
73- anyLast(timestamp) as timestamp,
74- metric,
75- toInt64(sum(metric_value)) AS value
76- FROM (
77- SELECT
78- toInt64(toUnixTimestamp(toDateTime(anyLast(Timestamp)))) AS timestamp,
79- extract(Path, '[^.]+$') AS metric,
80- anyLast(Value) AS metric_value
81- FROM default.graphite_data
82- WHERE Path LIKE '%.%.{conn_id}.conn_stat.%'
83- AND Timestamp >= toDateTime('{start}')
84- AND Timestamp < toDateTime('{start}') + INTERVAL 1 DAY
85- GROUP BY Path
86- )
87- GROUP BY metric" ,
80+ r#"SELECT metric,
81+ toInt64(sum(metric_value)) AS value,
82+ anyLast(timestamp) AS timestamp
83+ FROM (
84+ SELECT
85+ toInt64(toUnixTimestamp(toDateTime(anyLast(Timestamp)))) AS timestamp,
86+ extract(Path, '[^.]+$') AS metric,
87+ anyLast(Value) AS metric_value
88+ FROM default.graphite_data
89+ WHERE Path LIKE '%.%.{conn_id}.conn_stat.%'
90+ AND Timestamp >= toDateTime('{start}')
91+ AND Timestamp < toDateTime('{start}') + INTERVAL 1 DAY
92+ GROUP BY Path
93+ )
94+ GROUP BY metric"# ,
8895 conn_id = conn_id,
8996 start = start_str,
9097 ) ;
9198
92- log :: debug !( "CH Query {}" , query) ;
99+ println ! ( "CH Query\n {}" , query) ;
93100
94101 let client = self . client ( ) ;
95- let client = client. lock ( ) . await ;
96102
97103 let result = client. query ( & query) . fetch_all :: < Metric < T > > ( ) . await ;
98104
0 commit comments