From a65b6d520f8177ee14af7b7c6c7c84395c14e5b4 Mon Sep 17 00:00:00 2001 From: Alexandre Leveille Date: Wed, 14 Aug 2019 09:41:27 -0400 Subject: [PATCH] Fix for InfluxDB --- check/influxdb.go | 18 +++++++++--------- datasource/grafana.go | 9 +++++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/check/influxdb.go b/check/influxdb.go index 58550d2..2eb9b5b 100644 --- a/check/influxdb.go +++ b/check/influxdb.go @@ -19,14 +19,14 @@ var ( |> window(every: 1m) |> unique(column: "fqn") |> aggregateWindow(every: 1m, fn: count, columns: ["fqn"])` - influxdbQuery1Timeserie = `SELECT "value" FROM "randomint-1" WHERE ("worker" = '1' AND "node" = 'lg1') AND time >= now() - %s` - influxdbQuery100Timeseries = `SELECT "value" FROM "randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" = 'lg1') AND time >= now() - %s` - influxdbQuery400Timeseries = `SELECT "value" FROM "randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" =~ /lg[0-4]/) AND time >= now() - %s` + influxdbQuery1Timeserie = `SELECT "mean" FROM "1m"."randomint-1" WHERE ("worker" = '1' AND "node" = 'lg1') AND time >= now() - %s` + influxdbQuery100Timeseries = `SELECT "mean" FROM "1m"."randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" = 'lg1') AND time >= now() - %s` + influxdbQuery400Timeseries = `SELECT "mean" FROM "1m"."randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" =~ /lg[0-4]/) AND time >= now() - %s` //find("lagrande.latency.lg1.*")|Stats:percentile(99) - influxdbQuery100TimeseriesP99 = `SELECT percentile("value", 99) FROM "randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" = 'lg1') AND time >= now() - %s GROUP BY time(5s)` - influxdbQuery400TimeseriesP99 = `SELECT percentile("value", 99) FROM "randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" =~ /lg[0-4]/) AND time >= now() - %s GROUP BY time(5s)` - influxdbQuery100TimeseriesMean = `SELECT mean("value") FROM "randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" = 'lg1') AND time >= now() - %s GROUP BY time(5s)` - influxdbQuery400TimeseriesMean = `SELECT mean("value") FROM "randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" =~ /lg[0-4]/) AND time >= now() - %s GROUP BY time(5s)` + influxdbQuery100TimeseriesP99 = `SELECT percentile("max", 99) FROM "1m"."randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" = 'lg1') AND time >= now() - %s GROUP BY time(5s)` + influxdbQuery400TimeseriesP99 = `SELECT percentile("max", 99) FROM "1m"."randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" =~ /lg[0-4]/) AND time >= now() - %s GROUP BY time(5s)` + influxdbQuery100TimeseriesMean = `SELECT mean("mean") FROM "1m"."randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" = 'lg1') AND time >= now() - %s GROUP BY time(5s)` + influxdbQuery400TimeseriesMean = `SELECT mean("mean") FROM "1m"."randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" =~ /lg[0-4]/) AND time >= now() - %s GROUP BY time(5s)` ) // EvaluateInfluxDB will launch the AWS and InfluxDB queries to assess InfluxDB performances @@ -63,8 +63,8 @@ func EvaluateInfluxDB() { } time.Sleep(2 * time.Second) - go datasource.GrafanaProxyInstance.FluxDBQuery("metrics-count", influxdbQueryMetricCount) - time.Sleep(2 * time.Second) + //go datasource.GrafanaProxyInstance.FluxDBQuery("metrics-count", influxdbQueryMetricCount) + //time.Sleep(2 * time.Second) go datasource.GrafanaProxyInstance.SimpleInfluxDBQuery("1-ts-24-hour-range", influxdbQuery1Timeserie, "24h") time.Sleep(2 * time.Second) go datasource.GrafanaProxyInstance.SimpleInfluxDBQuery("1-ts-1-week-range", influxdbQuery1Timeserie, "7d") diff --git a/datasource/grafana.go b/datasource/grafana.go index 68b7e1e..a09df98 100644 --- a/datasource/grafana.go +++ b/datasource/grafana.go @@ -29,8 +29,8 @@ var ( // Response body ~= "data":[[6000]],"meta".... // Match everything from the double [[ until a ] caqlResultRegex = regexp.MustCompile("data\":\\[\\[([^\\]]*)") - influxLastResultRegex = regexp.MustCompile(".*,([0-9]*)]]") - fluxLastResultRegex = regexp.MustCompile("(?s).*,([0-9]*)") + influxLastResultRegex = regexp.MustCompile(".*,\\[[0-9]*,([0-9\\.]*)\\]") + fluxLastResultRegex = regexp.MustCompile("(?s).*,([0-9\\.]*)") // InfluxDB specific variables: influxdbQueryURL = "%s/api/datasources/proxy/1/query?db=%s&q=%s%%20&epoch=%s" // Source 1 = InfluxDB current plugin (InfluxQL) @@ -266,6 +266,10 @@ func (g *GrafanaProxy) doProxiedInfluxDBHTTPQuery(db string, queryString string, match := influxLastResultRegex.FindStringSubmatch(stringBody) if len(match) < 2 { + fmt.Println("No match error:") + fmt.Println(rangeQuery) + fmt.Println(stringBody) + return "nan", nil } @@ -342,6 +346,7 @@ func (g *GrafanaProxy) doProxiedFluxDBHTTPQuery(db string, queryString string) ( } return match[1], nil + } // {"query":"\ndashboardTime = -5m\nupperDashboardTime = 2019-07-24T20:32:04.653Z\n\nfrom(bucket: \"mydb/autogen\")\n |> range(start: -23m, stop: -3m)\n |> filter(fn: (r) => r.run == \"4\" and r.process == \"lagrande\" and (r._field == \"value\"))\n |> map(fn: (r) => ({\n _time: r._time,\n fqn: r.process + \".\" + r.node + \".\" + r._measurement + \".\" + r.worker\n }))\n |> keep(columns: [\"_time\", \"fqn\"])\n |> window(every: 1m)\n |> unique(column: \"fqn\")\n |> aggregateWindow(every: 1m, fn: count, columns: [\"fqn\"])","dialect":{"annotations":["group","datatype","default"]}}