func init() { Connectors["graphite"] = func(settings map[string]interface{}) (Connector, error) { var err error connector := &GraphiteConnector{ insecureTLS: false, } if connector.URL, err = config.GetString(settings, "url", true); err != nil { return nil, err } if connector.insecureTLS, err = config.GetBool(settings, "allow_insecure_tls", false); err != nil { return nil, err } if connector.timeout, err = config.GetFloat(settings, "timeout", false); err != nil { return nil, err } if connector.timeout <= 0 { connector.timeout = graphiteDefaultTimeout } return connector, nil } }
func init() { Connectors["facette"] = func(settings map[string]interface{}) (Connector, error) { var err error connector := &FacetteConnector{} if connector.upstream, err = config.GetString(settings, "upstream", true); err != nil { return nil, err } if connector.timeout, err = config.GetFloat(settings, "timeout", false); err != nil { return nil, err } if connector.timeout <= 0 { connector.timeout = facetteDefaultTimeout } return connector, nil } }
func makePlotsResponse(plotSeries map[string][]plot.Series, plotReq *PlotRequest, graph *library.Graph) (*PlotResponse, error) { response := &PlotResponse{ ID: graph.ID, Start: plotReq.startTime.Format(time.RFC3339), End: plotReq.endTime.Format(time.RFC3339), Name: graph.Name, Description: graph.Description, Title: graph.Title, Type: graph.Type, StackMode: graph.StackMode, UnitType: graph.UnitType, UnitLegend: graph.UnitLegend, Modified: graph.Modified, } for _, groupItem := range graph.Groups { var ( groupConsolidate int groupSeries []plot.Series err error ) seriesOptions := make(map[string]map[string]interface{}) for _, seriesItem := range groupItem.Series { if _, ok := plotSeries[seriesItem.Name]; !ok { return nil, fmt.Errorf("unable to find plots for `%s' series", seriesItem.Name) } for _, plotItem := range plotSeries[seriesItem.Name] { var optionKey string // Apply series scale if any if scale, _ := config.GetFloat(seriesItem.Options, "scale", false); scale != 0 { plotItem.Scale(plot.Value(scale)) } // Merge options from group and series if groupItem.Type == plot.OperTypeAverage || groupItem.Type == plot.OperTypeSum { optionKey = groupItem.Name } else { optionKey = seriesItem.Name } seriesOptions[optionKey] = make(map[string]interface{}) for key, value := range groupItem.Options { seriesOptions[optionKey][key] = value } if groupItem.Type != plot.OperTypeAverage && groupItem.Type != plot.OperTypeSum { for key, value := range seriesItem.Options { seriesOptions[optionKey][key] = value } } groupSeries = append(groupSeries, plotItem) } } if len(groupSeries) == 0 { continue } // Normalize all series plots on the same time step groupConsolidate, err = config.GetInt(groupItem.Options, "consolidate", true) if err != nil { groupConsolidate = plot.ConsolidateAverage } groupSeries, err = plot.Normalize( groupSeries, plotReq.startTime, plotReq.endTime, plotReq.Sample, groupConsolidate, ) if err != nil { return nil, fmt.Errorf("unable to consolidate series: %s", err) } // Perform requested series operations if groupItem.Type == plot.OperTypeAverage || groupItem.Type == plot.OperTypeSum { var ( operSeries plot.Series err error ) if groupItem.Type == plot.OperTypeAverage { operSeries, err = plot.AverageSeries(groupSeries) if err != nil { return nil, fmt.Errorf("unable to average series: %s", err) } } else { operSeries, err = plot.SumSeries(groupSeries) if err != nil { return nil, fmt.Errorf("unable to sum series: %s", err) } } operSeries.Name = groupItem.Name groupSeries = []plot.Series{operSeries} } // Apply group scale if any if scale, _ := config.GetFloat(groupItem.Options, "scale", false); scale != 0 { for _, seriesItem := range groupSeries { seriesItem.Scale(plot.Value(scale)) } } for _, seriesItem := range groupSeries { // Summarize each series (compute min/max/avg/last values) seriesItem.Summarize(plotReq.Percentiles) response.Series = append(response.Series, &SeriesResponse{ Name: seriesItem.Name, StackID: groupItem.StackID, Plots: seriesItem.Plots, Summary: seriesItem.Summary, Options: seriesOptions[seriesItem.Name], }) } } return response, nil }