Create statement_executor for monitor
parent
ba68e95347
commit
9165a0cf4c
|
@ -113,7 +113,7 @@ func NewServer(c *Config, version string) (*Server, error) {
|
|||
s.QueryExecutor = tsdb.NewQueryExecutor(s.TSDBStore)
|
||||
s.QueryExecutor.MetaStore = s.MetaStore
|
||||
s.QueryExecutor.MetaStatementExecutor = &meta.StatementExecutor{Store: s.MetaStore}
|
||||
s.QueryExecutor.MonitorStatementExecutor = s.Monitor
|
||||
s.QueryExecutor.MonitorStatementExecutor = &monitor.StatementExecutor{Monitor: s.Monitor}
|
||||
s.QueryExecutor.ShardMapper = s.ShardMapper
|
||||
|
||||
// Set the shard writer
|
||||
|
|
|
@ -11,8 +11,6 @@ import (
|
|||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/influxdb/influxdb/influxql"
|
||||
)
|
||||
|
||||
// Client is the interface modules must implement if they wish to register with monitor.
|
||||
|
@ -108,38 +106,8 @@ func (m *Monitor) Register(name string, tags map[string]string, client Client) e
|
|||
return nil
|
||||
}
|
||||
|
||||
// ExecuteStatement executes monitor-related query statements.
|
||||
func (m *Monitor) ExecuteStatement(stmt influxql.Statement) *influxql.Result {
|
||||
switch stmt := stmt.(type) {
|
||||
case *influxql.ShowStatsStatement:
|
||||
return m.executeShowStatistics(stmt)
|
||||
default:
|
||||
panic(fmt.Sprintf("unsupported statement type: %T", stmt))
|
||||
}
|
||||
}
|
||||
|
||||
// executeShowStatistics returns the statistics of the registered monitor client in
|
||||
// the standard form expected by users of the InfluxDB system.
|
||||
func (m *Monitor) executeShowStatistics(q *influxql.ShowStatsStatement) *influxql.Result {
|
||||
stats, _ := m.statistics()
|
||||
rows := make([]*influxql.Row, len(stats))
|
||||
|
||||
for n, stat := range stats {
|
||||
row := &influxql.Row{Name: stat.Name, Tags: stat.Tags}
|
||||
|
||||
values := make([]interface{}, 0, len(stat.Values))
|
||||
for _, k := range stat.valueNames() {
|
||||
row.Columns = append(row.Columns, k)
|
||||
values = append(values, stat.Values[k])
|
||||
}
|
||||
row.Values = [][]interface{}{values}
|
||||
rows[n] = row
|
||||
}
|
||||
return &influxql.Result{Series: rows}
|
||||
}
|
||||
|
||||
// statistics returns the combined statistics for all registered clients.
|
||||
func (m *Monitor) statistics() ([]*statistic, error) {
|
||||
func (m *Monitor) Statistics() ([]*statistic, error) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package monitor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/influxdb/influxdb/influxql"
|
||||
)
|
||||
|
||||
// StatementExecutor translates InfluxQL queries to Monitor methods.
|
||||
type StatementExecutor struct {
|
||||
Monitor interface {
|
||||
Statistics() ([]*statistic, error)
|
||||
}
|
||||
}
|
||||
|
||||
// ExecuteStatement executes monitor-related query statements.
|
||||
func (s *StatementExecutor) ExecuteStatement(stmt influxql.Statement) *influxql.Result {
|
||||
switch stmt := stmt.(type) {
|
||||
case *influxql.ShowStatsStatement:
|
||||
return s.executeShowStatistics()
|
||||
case *influxql.ShowDiagnosticsStatement:
|
||||
return s.executeShowDiagnostics()
|
||||
default:
|
||||
panic(fmt.Sprintf("unsupported statement type: %T", stmt))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *StatementExecutor) executeShowStatistics() *influxql.Result {
|
||||
stats, _ := s.Monitor.Statistics()
|
||||
rows := make([]*influxql.Row, len(stats))
|
||||
|
||||
for n, stat := range stats {
|
||||
row := &influxql.Row{Name: stat.Name, Tags: stat.Tags}
|
||||
|
||||
values := make([]interface{}, 0, len(stat.Values))
|
||||
for _, k := range stat.valueNames() {
|
||||
row.Columns = append(row.Columns, k)
|
||||
values = append(values, stat.Values[k])
|
||||
}
|
||||
row.Values = [][]interface{}{values}
|
||||
rows[n] = row
|
||||
}
|
||||
return &influxql.Result{Series: rows}
|
||||
}
|
||||
|
||||
func (s *StatementExecutor) executeShowDiagnostics() *influxql.Result {
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue