1818import de .qaware .chronix .ChronixClient ;
1919import de .qaware .chronix .converter .MetricTimeSeriesConverter ;
2020import de .qaware .chronix .examples .exploration .ui .dt .DateAxis ;
21+ import de .qaware .chronix .examples .exploration .ui .dt .ResultRow ;
2122import de .qaware .chronix .examples .exploration .ui .log .TextAreaLogger ;
2223import de .qaware .chronix .solr .client .ChronixSolrStorage ;
2324import de .qaware .chronix .timeseries .MetricTimeSeries ;
2425import de .qaware .chronix .timeseries .dts .Point ;
2526import javafx .application .Platform ;
27+ import javafx .collections .FXCollections ;
28+ import javafx .collections .ObservableList ;
2629import javafx .concurrent .Task ;
2730import javafx .event .EventHandler ;
2831import javafx .fxml .FXML ;
2932import javafx .fxml .Initializable ;
3033import javafx .scene .chart .LineChart ;
3134import javafx .scene .chart .NumberAxis ;
3235import javafx .scene .chart .XYChart ;
36+ import javafx .scene .control .TableColumn ;
37+ import javafx .scene .control .TableView ;
3338import javafx .scene .control .TextArea ;
3439import javafx .scene .input .KeyCode ;
3540import javafx .scene .input .KeyEvent ;
@@ -76,6 +81,24 @@ public class MainController implements Initializable {
7681 @ FXML
7782 private LineChart <DateAxis , NumberAxis > chart ;
7883
84+ /**
85+ * Table stuff below
86+ */
87+ @ FXML
88+ private TableView <ResultRow > resultTable ;
89+ @ FXML
90+ private TableColumn <ResultRow , String > timeSeries ;
91+ @ FXML
92+ private TableColumn <ResultRow , String > aggregationOrAnalysis ;
93+ @ FXML
94+ private TableColumn <ResultRow , String > arguments ;
95+ @ FXML
96+ private TableColumn <ResultRow , String > values ;
97+ @ FXML
98+ private TableColumn <ResultRow , String > order ;
99+
100+ private ObservableList <ResultRow > rows = FXCollections .observableArrayList ();
101+
79102 //Chronix stuff
80103 private ChronixClient <MetricTimeSeries , SolrClient , SolrQuery > chronix ;
81104 private SolrClient solr ;
@@ -87,6 +110,14 @@ public void initialize(URL location, ResourceBundle resources) {
87110 //Pipe logs to ui
88111 TextAreaLogger .setTextArea (logs );
89112
113+ //Init table
114+ timeSeries .setCellValueFactory (cellData -> cellData .getValue ().timeSeriesProperty ());
115+ aggregationOrAnalysis .setCellValueFactory (cellData -> cellData .getValue ().aggregationOrAnalysisProperty ());
116+ arguments .setCellValueFactory (cellData -> cellData .getValue ().argumentsProperty ());
117+ values .setCellValueFactory (cellData -> cellData .getValue ().valuesProperty ());
118+ order .setCellValueFactory (cellData -> cellData .getValue ().orderProperty ());
119+ resultTable .setItems (rows );
120+
90121 EventHandler <KeyEvent > queryExecuteHandler = event -> {
91122 if (event .getCode () == KeyCode .ENTER && event .isShiftDown ()) {
92123 queryTimeSeries ();
@@ -107,7 +138,7 @@ public void initChronix(String solrUrl) {
107138 public Void call () {
108139
109140 LOGGER .info ("Setting up Chronix with a remote Solr to URL {}" , solrUrl );
110- solr = new HttpSolrClient (solrUrl );
141+ solr = new HttpSolrClient . Builder (solrUrl ). build ( );
111142
112143 boolean solrAvailable = solrAvailable ();
113144 LOGGER .info ("Checking connection to Solr. Result {}" , solrAvailable );
@@ -146,19 +177,18 @@ protected Void call() throws Exception {
146177
147178 Platform .runLater (() -> {
148179 chart .getData ().clear ();
180+ rows .clear ();
149181 //Start the query
150182 chart .setTitle ("Your Query was q=" + queryString + " fq=" + fq );
151183 });
152184
153185 SolrQuery query = new SolrQuery (queryString );
186+ query .addField ("+data" );
187+
154188 boolean hasFilterQueries = !fq .isEmpty ();
155189
156190 if (hasFilterQueries ) {
157191 query .addFilterQuery (fq );
158-
159- if (fq .contains ("function=" )) {
160- query .addField ("+data" );
161- }
162192 }
163193
164194 long queryStart = System .currentTimeMillis ();
@@ -167,12 +197,10 @@ protected Void call() throws Exception {
167197 LOGGER .info ("Query took: {} ms for {} points" , (queryEnd - queryStart ), size (result ));
168198 queryStart = System .currentTimeMillis ();
169199 result .forEach (ts -> {
170-
171200 if (hasFilterQueries ) {
172- convertAggregationOrAnalysisTs (ts , fq .contains ("function=" ));
173- } else {
174- convertTsToSeries (ts );
201+ addFunctionsToTable (ts );
175202 }
203+ convertTsToSeries (ts );
176204 });
177205 queryEnd = System .currentTimeMillis ();
178206 LOGGER .info ("Charting took: {} ms" , (queryEnd - queryStart ));
@@ -183,47 +211,32 @@ protected Void call() throws Exception {
183211
184212 }
185213
186- private void convertAggregationOrAnalysisTs (MetricTimeSeries ts , boolean analysis ) {
214+ private void addFunctionsToTable (MetricTimeSeries ts ) {
187215
188216 //find the aggregations / and analyses
189217
190218 ts .getAttributesReference ().forEach ((key , value ) -> {
191219 //we have function value
192220 if (key .contains ("function" ) && !key .contains ("arguments" )) {
193221 String [] splits = key .split ("_" );
194- XYChart .Series <DateAxis , NumberAxis > series = new XYChart .Series <>();
195222
196223 //function name
197- String name = splits [1 ];
198- series .setName (join (ts ) + "-" + name );
199-
200- //function value
201- if (analysis ) {
202- ts .sort ();
203- List <Point > points ;
204- if (ts .size () > 200_000 ) {
205- points = ts .points ().filter (point -> point .getIndex () % 1000 == 0 ).collect (Collectors .toList ());
206- } else {
207- points = ts .points ().collect (Collectors .toList ());
208- }
209- //reduce the amount shown in the chart we add every 100ths point
210- addPointsToSeries (series , points );
211- Platform .runLater (() -> chart .getData ().add (series ));
224+ String name = splits [2 ];
212225
226+ //Check if the function has an argument
227+ Object arguments = ts .attribute (splits [0 ] + "_" + splits [1 ] + "_arguments_" + splits [2 ]);
213228
214- } else {
215- Instant start = Instant .ofEpochMilli (ts .getStart ());
216- Instant end = Instant .ofEpochMilli (ts .getEnd ());
217-
218- series .getData ().add (new XYChart .Data (start , value ));
219- series .getData ().add (new XYChart .Data (end , value ));
220- Platform .runLater (() -> chart .getData ().add (series ));
229+ ResultRow row = new ResultRow ();
230+ row .setTimeSeries (join (ts ));
231+ row .setAggregationOrAnalysis (name );
232+ if (arguments != null ) {
233+ row .setArguments (arguments .toString ());
221234 }
235+ row .setValues (value .toString ());
236+ row .setOrder (key );
222237
223238
224- } else {
225- //function arguments
226- //currently ignored
239+ rows .add (row );
227240 }
228241
229242
@@ -276,7 +289,7 @@ private String join(MetricTimeSeries ts) {
276289 if (ts == null ) {
277290 return "" ;
278291 }
279- return String . valueOf ( ts .attribute ("host" ) ) + "-" +
292+ return ts .attribute ("host" ) + "-" +
280293 ts .attribute ("source" ) + "-" +
281294 ts .attribute ("group" ) + "-" +
282295 ts .getMetric ();
0 commit comments