loki

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 14 Imported by: 0

README

loki

通过API将日志提交到loki, 不推荐该方式, 推荐使用promtail来抓取日志

# 日志组件配置
logger:
  level: info
  logfile:
    enable: true
    errorfilename: ./runtime/logs/cago.err.log
    filename: ./runtime/logs/cago.log
  # 不推荐该方式, 推荐使用`promtail`来抓取日志
  loki:
    level: info
    url: http://127.0.0.1:3100/loki/api/v1/push
    username: ""
    password: ""

k8s helm promtail配置

拉取promtail的helm chart, scrapeConfigs添加job

      - job_name: cago
        pipeline_stages:
          - cri: { }
        kubernetes_sd_configs:
          - role: pod
        relabel_configs:
          - source_labels:
              - __meta_kubernetes_pod_label_app_kubernetes_io_name
            action: keep
            regex: cago
          - source_labels:
              - __meta_kubernetes_pod_label_app_cago_io_name
            action: replace
            target_label: app
          - source_labels:
              - __meta_kubernetes_pod_label_app_cago_io_version
            action: replace
            target_label: version
          - source_labels:
              - __meta_kubernetes_pod_label_app_cago_io_environment
            action: replace
            target_label: env
          { { - toYaml .Values.config.snippets.common | nindent 4 } }
          { { - with .Values.config.snippets.extraRelabelConfigs } }
          { { - toYaml . | nindent 4 } }
          { { - end } }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLokiCore

func NewLokiCore(ctx context.Context, opt ...Option) zapcore.Core

func NewLokiEncode

func NewLokiEncode(labels ...zap.Field) zapcore.Encoder

Types

type Config

type Config struct {
	Enable   bool   `yaml:"enable"`
	Url      string `yaml:"url"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

type Option

type Option func(*Options)

func AppendLabels

func AppendLabels(labels ...zap.Field) Option

func BasicAuth

func BasicAuth(username string, password string) Option

func WithEnv

func WithEnv() Option

func WithHost

func WithHost() Option

func WithKubernetes

func WithKubernetes() Option

func WithLevelEnable

func WithLevelEnable(enab zap.LevelEnablerFunc) Option

func WithLokiUrl

func WithLokiUrl(u *url.URL) Option

type Options

type Options struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL