<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel rdf:about="https://dwt.life/feed/rss/tag/loki/">
<title>dwt&#039;s life - loki</title>
<link>https://dwt.life/tag/loki/</link>
<description></description>
<items>
<rdf:Seq>
<rdf:li resource="https://dwt.life/archives/244/"/>
<rdf:li resource="https://dwt.life/archives/243/"/>
</rdf:Seq>
</items>
</channel>
<item rdf:about="https://dwt.life/archives/244/">
<title>loki腾讯云cos存储配置</title>
<link>https://dwt.life/archives/244/</link>
<dc:date>2022-05-16T19:15:04+08:00</dc:date>
<description>仅用于参考auth_enabled: false

server:
  http_listen_port: 3100
  # grpc_listen_port: 9096

common:
  path_prefix: /tmp/loki
  replication_factor: 1
  ring:
    instance_addr: 127.0.0.1
    kvstore:
      store: inmemory

schema_config:
  configs:
    - from: 2020-10-24
      store: boltdb-shipper
      object_store: aws
      schema: v11
      index:
        prefix: index_
        period: 24h
storage_config:
  aws:
    bucketnames: loki-logs-123123                                # 请在腾讯云创建一个对象存储存储桶，并把存储桶名称写到这里
    endpoint: cos.ap-guangzhou.myqcloud.com                            # 腾讯云的对象存储域名后缀
    access_key_id: &lt;Your access key id from TencentCloud&gt;            # 腾讯云 AK
    secret_access_key: &lt;Your secret access key from TencentCloud&gt;    # 腾讯云 SK
    region: ap-guang                                               # 对象存储存储桶地域
  boltdb_shipper:
    active_index_directory: /loki/index
    shared_store: s3
    cache_location: /loki/boltdb-cache
compactor:
  working_directory: /loki/boltdb-shipper-compactor
  shared_store: aws

ruler:
  alertmanager_url: http://localhost:9093

analytics:
  reporting_enabled: false</description>
</item>
<item rdf:about="https://dwt.life/archives/243/">
<title>golang启动loki</title>
<link>https://dwt.life/archives/243/</link>
<dc:date>2022-05-16T19:07:30+08:00</dc:date>
<description>package main

import (
    &quot;flag&quot;
    &quot;fmt&quot;
    &quot;os&quot;
    &quot;reflect&quot;
    &quot;runtime&quot;

    &quot;github.com/go-kit/log/level&quot;
    &quot;github.com/prometheus/client_golang/prometheus&quot;
    &quot;github.com/prometheus/common/version&quot;
    &quot;github.com/weaveworks/common/logging&quot;
    &quot;github.com/weaveworks/common/tracing&quot;

    &quot;github.com/grafana/loki/pkg/loki&quot;
    &quot;github.com/grafana/loki/pkg/util&quot;
    _ &quot;github.com/grafana/loki/pkg/util/build&quot;
    &quot;github.com/grafana/loki/pkg/util/cfg&quot;
    util_log &quot;github.com/grafana/loki/pkg/util/log&quot;
    &quot;github.com/grafana/loki/pkg/validation&quot;
)

func main() {
    var config loki.ConfigWrapper

    if err := cfg.DynamicUnmarshal(&amp;config, os.Args[1:], flag.CommandLine); err != nil {
        fmt.Fprintf(os.Stderr, &quot;failed parsing config: %v\n&quot;, err)
        os.Exit(1)
    }
    if config.PrintVersion {
        fmt.Println(version.Print(&quot;loki&quot;))
        os.Exit(0)
    }

    // This global is set to the config passed into the last call to `NewOverrides`. If we don&#039;t
    // call it atleast once, the defaults are set to an empty struct.
    // We call it with the flag values so that the config file unmarshalling only overrides the values set in the config.
    validation.SetDefaultLimitsForYAMLUnmarshalling(config.LimitsConfig)

    // Init the logger which will honor the log level set in config.Server
    if reflect.DeepEqual(&amp;config.Server.LogLevel, &amp;logging.Level{}) {
        level.Error(util_log.Logger).Log(&quot;msg&quot;, &quot;invalid log level&quot;)
        os.Exit(1)
    }
    util_log.InitLogger(&amp;config.Server, prometheus.DefaultRegisterer)

    // Validate the config once both the config file has been loaded
    // and CLI flags parsed.
    err := config.Validate()
    if err != nil {
        level.Error(util_log.Logger).Log(&quot;msg&quot;, &quot;validating config&quot;, &quot;err&quot;, err.Error())
        os.Exit(1)
    }

    if config.PrintConfig {
        err := util.PrintConfig(os.Stderr, &amp;config)
        if err != nil {
            level.Error(util_log.Logger).Log(&quot;msg&quot;, &quot;failed to print config to stderr&quot;, &quot;err&quot;, err.Error())
        }
    }

    if config.LogConfig {
        err := util.LogConfig(&amp;config)
        if err != nil {
            level.Error(util_log.Logger).Log(&quot;msg&quot;, &quot;failed to log config object&quot;, &quot;err&quot;, err.Error())
        }
    }

    if config.VerifyConfig {
        level.Info(util_log.Logger).Log(&quot;msg&quot;, &quot;config is valid&quot;)
        os.Exit(0)
    }

    if config.Tracing.Enabled {
        // Setting the environment variable JAEGER_AGENT_HOST enables tracing
        trace, err := tracing.NewFromEnv(fmt.Sprintf(&quot;loki-%s&quot;, config.Target))
        if err != nil {
            level.Error(util_log.Logger).Log(&quot;msg&quot;, &quot;error in initializing tracing. tracing will not be enabled&quot;, &quot;err&quot;, err)
        }
        defer func() {
            if trace != nil {
                if err := trace.Close(); err != nil {
                    level.Error(util_log.Logger).Log(&quot;msg&quot;, &quot;error closing tracing&quot;, &quot;err&quot;, err)
                }
            }

        }()
    }

    // Allocate a block of memory to reduce the frequency of garbage collection.
    // The larger the ballast, the lower the garbage collection frequency.
    // https://github.com/grafana/loki/issues/781
    ballast := make([]byte, config.BallastBytes)
    runtime.KeepAlive(ballast)

    // Start Loki
    t, err := loki.New(config.Config)
    util_log.CheckFatal(&quot;initialising loki&quot;, err, util_log.Logger)

    if config.ListTargets {
        t.ListTargets()
        os.Exit(0)
    }

    level.Info(util_log.Logger).Log(&quot;msg&quot;, &quot;Starting Loki&quot;, &quot;version&quot;, version.Info())

    err = t.Run(loki.RunOpts{})
    util_log.CheckFatal(&quot;running loki&quot;, err, util_log.Logger)
}https://github.com/grafana/loki/blob/main/cmd/loki/main.go</description>
</item>
</rdf:RDF>