func NewExporter()

in benchmarks/benchmark/tools/locust-load-inference/locust-custom-exporter/main.go [41:94]


func NewExporter(uri string, timeout time.Duration) (*Exporter, error) {
	u, err := url.Parse(uri)
	if err != nil {
		return nil, err
	}

	var fetch func(endpoint string) (io.ReadCloser, error)
	switch u.Scheme {
	case "http", "https", "file":
		fetch = fetchHTTP(uri, timeout)
	default:
		return nil, fmt.Errorf("unsupported scheme: %q", u.Scheme)
	}

	return &Exporter{
		uri:   uri,
		fetch: fetch,
		locustAvgTokensSent: prometheus.NewGauge(
			prometheus.GaugeOpts{
				Namespace: namespace,
				Subsystem: "custom_metrics",
				Name:      "avg_tokens_sent",
			},
		),
		locustAvgTokensReceived: prometheus.NewGauge(
			prometheus.GaugeOpts{
				Namespace: namespace,
				Subsystem: "custom_metrics",
				Name:      "avg_tokens_received",
			},
		),
		locustAvgTestTime: prometheus.NewGauge(
			prometheus.GaugeOpts{
				Namespace: namespace,
				Subsystem: "custom_metrics",
				Name:      "avg_test_time",
			},
		),
		locustAvgOutputTokenLatency: prometheus.NewGauge(
			prometheus.GaugeOpts{
				Namespace: namespace,
				Subsystem: "custom_metrics",
				Name:      "avg_output_token_latency",
			},
		),
		locustTimeToFirstToken: prometheus.NewGauge(
			prometheus.GaugeOpts{
				Namespace: namespace,
				Subsystem: "custom_metrics",
				Name:      "avg_time_to_first_token",
			},
		),
	}, nil
}