2021-03-15 20:37:13 +01:00
package influxutils
import (
"fmt"
"net/http"
"strings"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
)
2022-10-01 17:26:05 +02:00
var influxDatabaseNames = flagutil . NewArrayString ( "influx.databaseNames" , "Comma-separated list of database names to return from /query and /influx/query API. " +
2021-03-15 20:37:13 +01:00
"This can be needed for accepting data from Telegraf plugins such as https://github.com/fangli/fluent-plugin-influxdb" )
// WriteDatabaseNames writes influxDatabaseNames to w.
func WriteDatabaseNames ( w http . ResponseWriter ) {
// Emulate fake response for influx query.
// This is required for TSBS benchmark and some Telegraf plugins.
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1124
2021-11-09 17:03:50 +01:00
w . Header ( ) . Set ( "Content-Type" , "application/json" )
2021-03-15 20:37:13 +01:00
dbNames := * influxDatabaseNames
if len ( dbNames ) == 0 {
dbNames = [ ] string { "_internal" }
}
dbs := make ( [ ] string , len ( dbNames ) )
for i := range dbNames {
2021-03-15 21:03:52 +01:00
dbs [ i ] = fmt . Sprintf ( ` [%q] ` , dbNames [ i ] )
2021-03-15 20:37:13 +01:00
}
2021-03-15 21:18:15 +01:00
fmt . Fprintf ( w , ` { "results":[ { "statement_id":0,"series":[ { "name":"databases","columns":["name"],"values":[%s]}]}]} ` , strings . Join ( dbs , "," ) )
2021-03-15 20:37:13 +01:00
}