You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/06/07 02:45:34 UTC

[GitHub] [skywalking-satellite] mrproliu commented on a change in pull request #42: feat: add prometheus fetcher

mrproliu commented on a change in pull request #42:
URL: https://github.com/apache/skywalking-satellite/pull/42#discussion_r646238683



##########
File path: plugins/fetcher/prometheus/fetcher.go
##########
@@ -0,0 +1,146 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package prometheus
+
+import (
+	"context"
+	"time"
+
+	"github.com/apache/skywalking-satellite/internal/pkg/config"
+	"github.com/apache/skywalking-satellite/internal/pkg/log"
+	"github.com/apache/skywalking-satellite/internal/satellite/event"
+
+	promConfig "github.com/prometheus/prometheus/config"
+	"github.com/prometheus/prometheus/discovery"
+	"github.com/prometheus/prometheus/scrape"
+	yaml "gopkg.in/yaml.v3"
+	v1 "skywalking.apache.org/repo/goapi/satellite/data/v1"
+)
+
+const (
+	Name      = "prometheus-metrics-fetcher"
+	eventName = "prometheus-metrics-event"
+)
+
+type scrapeConfig struct {
+	JobName        string                   `yaml:"job_name" mapstructure:"job_name"`
+	ScrapeInterval time.Duration            `yaml:"scrape_interval,omitempty" mapstructure:"scrape_interval,omitempty"`
+	StaticConfigs  []map[string]interface{} `yaml:"static_configs" mapstructure:"static_configs"`
+	MetricsPath    string                   `yaml:"metrics_path,omitempty" mapstructure:"metrics_path,omitempty"`
+}
+
+// Fetcher is the struct for Prometheus fetcher
+type Fetcher struct {
+	config.CommonFields
+	// config is the top level configuratScrapeConfigsMapion of prometheus
+	ScrapeConfigsMap []*scrapeConfig `mapstructure:"scrape_configs" yaml:"scrape_configs"`
+
+	ScrapeConfigs []*promConfig.ScrapeConfig
+	// events
+	OutputEvents event.BatchEvents
+	// outputChannel
+	OutputChannel chan *v1.SniffData
+
+	cancelFunc context.CancelFunc
+}
+
+func (f *Fetcher) Name() string {
+	return Name
+}
+
+func (f *Fetcher) Description() string {
+	return "This is a fetcher for Skywalking prometheus metrics format, " +
+		"which will translate Prometheus metrics to Skywalking meter system."
+}
+
+func (f *Fetcher) DefaultConfig() string {
+	return `
+## some config here
+scrape_configs:
+ - job_name: 'prometheus'
+   metrics_path: '/metrics'
+   scrape_interval: 10s
+   static_configs:
+   - targets: ['127.0.0.1:2020']
+`
+}
+
+func (f *Fetcher) Prepare() {}
+
+func (f *Fetcher) Fetch() event.BatchEvents {

Review comment:
       I can't see when this method will be called? Do I miss anything?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org