diff --git a/CHANGELOG.md b/CHANGELOG.md index 69ce635295..b51269bc3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - [#4140](https://github.com/influxdb/influxdb/pull/4140): Make storage engine configurable - [#4161](https://github.com/influxdb/influxdb/pull/4161): Implement bottom selector function - [#4204](https://github.com/influxdb/influxdb/pull/4204): Allow module-level selection for SHOW STATS +- [#4208](https://github.com/influxdb/influxdb/pull/4208): Allow module-level selection for SHOW DIAGNOSTICS - [#4196](https://github.com/influxdb/influxdb/pull/4196): Export tsdb.Iterator - [#4198](https://github.com/influxdb/influxdb/pull/4198): Add basic cluster-service stats diff --git a/influxql/ast.go b/influxql/ast.go index befdbafabf..fb32da1920 100644 --- a/influxql/ast.go +++ b/influxql/ast.go @@ -1999,6 +1999,7 @@ func (s *ShowStatsStatement) String() string { var buf bytes.Buffer _, _ = buf.WriteString("SHOW STATS ") if s.Module != "" { + _, _ = buf.WriteString("FOR ") _, _ = buf.WriteString(s.Module) } return buf.String() @@ -2021,10 +2022,21 @@ func (s *ShowShardsStatement) RequiredPrivileges() ExecutionPrivileges { } // ShowDiagnosticsStatement represents a command for show node diagnostics. -type ShowDiagnosticsStatement struct{} +type ShowDiagnosticsStatement struct { + // Module + Module string +} // String returns a string representation of the ShowDiagnosticsStatement. -func (s *ShowDiagnosticsStatement) String() string { return "SHOW DIAGNOSTICS" } +func (s *ShowDiagnosticsStatement) String() string { + var buf bytes.Buffer + _, _ = buf.WriteString("SHOW DIAGNOSTICS ") + if s.Module != "" { + _, _ = buf.WriteString("FOR ") + _, _ = buf.WriteString(s.Module) + } + return buf.String() +} // RequiredPrivileges returns the privilege required to execute a ShowDiagnosticsStatement func (s *ShowDiagnosticsStatement) RequiredPrivileges() ExecutionPrivileges { diff --git a/influxql/parser.go b/influxql/parser.go index 51063ddd04..b3d6eed398 100644 --- a/influxql/parser.go +++ b/influxql/parser.go @@ -1445,7 +1445,15 @@ func (p *Parser) parseShowStatsStatement() (*ShowStatsStatement, error) { // parseShowDiagnostics parses a string and returns a ShowDiagnosticsStatement. func (p *Parser) parseShowDiagnosticsStatement() (*ShowDiagnosticsStatement, error) { stmt := &ShowDiagnosticsStatement{} - return stmt, nil + var err error + + if tok, _, _ := p.scanIgnoreWhitespace(); tok == FOR { + stmt.Module, err = p.parseString() + } else { + p.unscan() + } + + return stmt, err } // parseDropContinuousQueriesStatement parses a string and returns a DropContinuousQueryStatement. diff --git a/influxql/parser_test.go b/influxql/parser_test.go index a1958f7a49..a0497d4e21 100644 --- a/influxql/parser_test.go +++ b/influxql/parser_test.go @@ -1417,6 +1417,12 @@ func TestParser_ParseStatement(t *testing.T) { s: `SHOW DIAGNOSTICS`, stmt: &influxql.ShowDiagnosticsStatement{}, }, + { + s: `SHOW DIAGNOSTICS FOR 'build'`, + stmt: &influxql.ShowDiagnosticsStatement{ + Module: "build", + }, + }, // Errors {s: ``, err: `found EOF, expected SELECT, DELETE, SHOW, CREATE, DROP, GRANT, REVOKE, ALTER, SET at line 1, char 1`}, @@ -1501,6 +1507,7 @@ func TestParser_ParseStatement(t *testing.T) { {s: `SHOW RETENTION POLICIES ON`, err: `found EOF, expected identifier at line 1, char 28`}, {s: `SHOW FOO`, err: `found FOO, expected CONTINUOUS, DATABASES, FIELD, GRANTS, MEASUREMENTS, RETENTION, SERIES, SERVERS, TAG, USERS at line 1, char 6`}, {s: `SHOW STATS FOR`, err: `found EOF, expected string at line 1, char 16`}, + {s: `SHOW DIAGNOSTICS FOR`, err: `found EOF, expected string at line 1, char 22`}, {s: `SHOW GRANTS`, err: `found EOF, expected FOR at line 1, char 13`}, {s: `SHOW GRANTS FOR`, err: `found EOF, expected identifier at line 1, char 17`}, {s: `DROP CONTINUOUS`, err: `found EOF, expected QUERY at line 1, char 17`}, diff --git a/monitor/README.md b/monitor/README.md index cf0e5d09ee..5e09cff385 100644 --- a/monitor/README.md +++ b/monitor/README.md @@ -14,7 +14,7 @@ An example of statistical information would be the number of points received ove All statistics are written, by default, by each node to a "monitor" database within the InfluxDB system, allowing analysis of aggregated statistical data using the standard InfluxQL language. This allows users to track the performance of their system. Importantly, this allows cluster-level statistics to be viewed, since by querying the monitor database, statistics from all nodes may be queried. This can be a very powerful approach for troubleshooting your InfluxDB system and understanding its behaviour. ## System Diagnostics -`SHOW DIAGNOSTICS` displays various diagnostic information about the `influxd` process. This information is not stored persistently within the InfluxDB system. +`SHOW DIAGNOSTICS [FOR ]` displays various diagnostic information about the `influxd` process. This information is not stored persistently within the InfluxDB system. If _module_ is specified, it must be single-quoted. For example `SHOW STATS FOR 'build'`. ## Standard expvar support All statistical information is available at HTTP API endpoint `/debug/vars`, in [expvar](https://golang.org/pkg/expvar/) format, allowing external systems to monitor an InfluxDB node. By default, the full path to this endpoint is `http://localhost:8086/debug/vars`. diff --git a/monitor/statement_executor.go b/monitor/statement_executor.go index 6b0efe3507..ad0261a1b8 100644 --- a/monitor/statement_executor.go +++ b/monitor/statement_executor.go @@ -21,7 +21,7 @@ func (s *StatementExecutor) ExecuteStatement(stmt influxql.Statement) *influxql. case *influxql.ShowStatsStatement: return s.executeShowStatistics(stmt.Module) case *influxql.ShowDiagnosticsStatement: - return s.executeShowDiagnostics() + return s.executeShowDiagnostics(stmt.Module) default: panic(fmt.Sprintf("unsupported statement type: %T", stmt)) } @@ -51,7 +51,7 @@ func (s *StatementExecutor) executeShowStatistics(module string) *influxql.Resul return &influxql.Result{Series: rows} } -func (s *StatementExecutor) executeShowDiagnostics() *influxql.Result { +func (s *StatementExecutor) executeShowDiagnostics(module string) *influxql.Result { diags, err := s.Monitor.Diagnostics() if err != nil { return &influxql.Result{Err: err} @@ -59,6 +59,10 @@ func (s *StatementExecutor) executeShowDiagnostics() *influxql.Result { rows := make([]*models.Row, 0, len(diags)) for k, v := range diags { + if module != "" && k != module { + continue + } + row := &models.Row{Name: k} row.Columns = v.Columns