本文整理匯總了Golang中github.com/influxdata/kapacitor.DBRP類的典型用法代碼示例。如果您正苦於以下問題:Golang DBRP類的具體用法?Golang DBRP怎麽用?Golang DBRP使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DBRP類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Set
// Parse string of the form "db"."rp" where the quotes are optional but can include escaped quotes
// within the strings.
func (d *dbrps) Set(value string) error {
dbrp := kapacitor.DBRP{}
if len(value) == 0 {
return errors.New("dbrp cannot be empty")
}
var n int
if value[0] == '"' {
dbrp.Database, n = parseQuotedStr(value)
} else {
n = strings.IndexRune(value, '.')
if n == -1 {
return errors.New("does not contain a '.', it must be in the form \"dbname\".\"rpname\" where the quotes are optional.")
}
dbrp.Database = value[:n]
}
if value[n] != '.' {
return errors.New("dbrp must specify retention policy, do you have a missing or extra '.'?")
}
value = value[n+1:]
if value[0] == '"' {
dbrp.RetentionPolicy, n = parseQuotedStr(value)
} else {
dbrp.RetentionPolicy = value
}
*d = append(*d, dbrp)
return nil
}
示例2: execQuery
func (s *Service) execQuery(q, cluster string) (kapacitor.DBRP, *influxdb.Response, error) {
// Parse query to determine dbrp
dbrp := kapacitor.DBRP{}
stmt, err := influxql.ParseStatement(q)
if err != nil {
return dbrp, nil, err
}
if slct, ok := stmt.(*influxql.SelectStatement); ok && len(slct.Sources) == 1 {
if m, ok := slct.Sources[0].(*influxql.Measurement); ok {
dbrp.Database = m.Database
dbrp.RetentionPolicy = m.RetentionPolicy
}
}
if dbrp.Database == "" || dbrp.RetentionPolicy == "" {
return dbrp, nil, errors.New("could not determine database and retention policy. Is the query fully qualified?")
}
if s.InfluxDBService == nil {
return dbrp, nil, errors.New("InfluxDB not configured, cannot record query")
}
// Query InfluxDB
con, err := s.InfluxDBService.NewNamedClient(cluster)
if err != nil {
return dbrp, nil, errors.Wrap(err, "failed to get InfluxDB client")
}
query := influxdb.Query{
Command: q,
}
resp, err := con.Query(query)
if err != nil {
return dbrp, nil, errors.Wrap(err, "InfluxDB query failed")
}
return dbrp, resp, nil
}
示例3: Set
// Parse string of the form "db"."rp" where the quotes are optional but can include escaped quotes
// within the strings.
func (d *dbrps) Set(value string) error {
dbrp := kapacitor.DBRP{}
if len(value) == 0 {
return fmt.Errorf("dbrp cannot be empty")
}
var n int
if value[0] == '"' {
dbrp.Database, n = parseQuotedStr(value)
} else {
n = strings.IndexRune(value, '.')
dbrp.Database = value[:n]
}
if value[n] != '.' {
return fmt.Errorf("dbrp must specify retention policy, do you have a missing or extra '.'?")
}
value = value[n+1:]
if value[0] == '"' {
dbrp.RetentionPolicy, n = parseQuotedStr(value)
} else {
dbrp.RetentionPolicy = value
}
*d = append(*d, dbrp)
return nil
}