Query field keys in regex-using Springboot and Influxdb

291 Views Asked by At

Spring-Boot has a Metrics look like

metrics_counter.status.200.hello                        20
metrics_counter.status.200.jolokia.star-star            1
metrics_counter.status.200.metrics                      2
metrics_counter.status.200.star-star.favicon.ico        4
metrics_counter.status.304.star-star                    3
metrics_counter.status.404.star-star                    1

it is dynamic by url ; for this example /hello have http status 200 for 20 time .

in influxdb the fields look like this

> show field keys
name: jolokia
fieldKey                                                fieldType
--------                                                ---------
metrics_counter.status.200.jolokia.star-star            float
metrics_counter.status.200.metrics                      float
metrics_counter.status.200.persons                      float
metrics_counter.status.200.star-star                    float
metrics_counter.status.200.star-star.favicon.ico        float
metrics_counter.status.304.star-star                    float
metrics_counter.status.404.star-star                    float

if I query by regex , the result is

> SELECT mean(/status.200.*/) FROM jolokia
name: jolokia
time    mean_metrics_counter.status.200.hello   mean_metrics_counter.status.200.jolokia.star-star       mean_metrics_counter.status.200.metrics mean_metrics_counter.status.200.persons mean_metrics_counter.status.200.star-star       mean_metrics_counter.status.200.star-star.favicon.ico
----    -------------------------------------   -------------------------------------------------       --------------------------------------- --------------------------------------- -----------------------------------------       -----------------------------------------------------
0       3.8686440677966103                      112.582995951417                                        8.935643564356436                       651.429718875502                        1                                               7.7923728813559325

how can I sum all http status like

200 27
304 3
404 1

by dynamic field keys query?

1

There are 1 best solutions below

0
On

You'll have to modify your schema a bit, but it should be possible.

Instead of inserting data that looks like graphite format

jolokia metrics_counter.status.200.jolokia.star-star=100 <timestamp>

Use tags

jolokia,type=metrics_counter,status=200 star-star=100 <timestamp>

In fact, I would actually recommend that you structure your data like so

metrics_counter,status=200,app=jolokia star-star=100
metrics_counter,status=200,app=jolokia star-star.favicon=100
metrics_counter,status=304,app=jolokia star-star=100
metrics_counter,status=400,app=jolokia star-star.favicon=100

Then you can issue a query like

SELECT mean(*) FROM metrics_counter GROUP BY status