1 Star 0 Fork 0

tianmaotalk/promtail_embedded

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
scrapeconfig.go 2.88 KB
一键复制 编辑 原始数据 按行查看 历史
zhimin.tian 提交于 2023-09-08 10:23 +08:00 . init
package scrapeconfig
import (
"fmt"
"gitee.com/tianmaotalk/promtail_embedded/pkg/omclient/promtail/discovery"
"gitee.com/tianmaotalk/promtail_embedded/pkg/omclient/promtail/discovery/file"
"gitee.com/tianmaotalk/promtail_embedded/pkg/omclient/promtail/discovery/relabel"
"gitee.com/tianmaotalk/promtail_embedded/pkg/omclient/promtail/logentry/stages"
"reflect"
"github.com/prometheus/common/model"
)
// Config describes a job to scrape.
type Config struct {
JobName string `yaml:"job_name,omitempty"`
PipelineStages stages.PipelineStages `yaml:"pipeline_stages,omitempty"`
JournalConfig *JournalTargetConfig `yaml:"journal,omitempty"`
RelabelConfigs []*relabel.Config `yaml:"relabel_configs,omitempty"`
ServiceDiscoveryConfig ServiceDiscoveryConfig `yaml:",inline"`
}
type ServiceDiscoveryConfig struct {
// List of static configurations
StaticConfigs discovery.StaticConfig `yaml:"static_configs"`
// List of file service discovery configurations.
FileSDConfigs []*file.SDConfig `yaml:"file_sd_configs,omitempty"`
}
func (cfg ServiceDiscoveryConfig) Configs() (res discovery.Configs) {
if x := cfg.StaticConfigs; len(x) > 0 {
res = append(res, x)
}
for _, x := range cfg.FileSDConfigs {
res = append(res, x)
}
return res
}
// JournalTargetConfig describes systemd journal records to scrape.
type JournalTargetConfig struct {
// MaxAge determines the oldest relative time from process start that will
// be read and sent to Loki. Values like 14h means no entry older than
// 14h will be read. If unspecified, defaults to 7h.
//
// A relative time specified here takes precedence over the saved position;
// if the cursor is older than the MaxAge value, it will not be used.
MaxAge string `yaml:"max_age"`
// JSON forces the output message of entries read from the journal to be
// JSON. The message will contain all original fields from the source
// journal entry.
JSON bool `yaml:"json"`
// Labels optionally holds labels to associate with each record coming out
// of the journal.
Labels model.LabelSet `yaml:"labels"`
// Path to a directory to read journal entries from. Defaults to system path
// if empty.
Path string `yaml:"path"`
}
// DefaultScrapeConfig is the default Config.
var DefaultScrapeConfig = Config{
PipelineStages: stages.PipelineStages{},
}
// HasServiceDiscoveryConfig checks to see if the service discovery used for
// file targets is non-zero.
func (c *Config) HasServiceDiscoveryConfig() bool {
return !reflect.DeepEqual(c.ServiceDiscoveryConfig, ServiceDiscoveryConfig{})
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultScrapeConfig
type plain Config
if err := unmarshal((*plain)(c)); err != nil {
return err
}
if len(c.JobName) == 0 {
return fmt.Errorf("job_name is empty")
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tianmaotalk/promtail_embedded.git
git@gitee.com:tianmaotalk/promtail_embedded.git
tianmaotalk
promtail_embedded
promtail_embedded
10aecdb7d823

搜索帮助