Alertmanager

简要概述

配置示例

alertmanager:
  data_dir: "/data/cortex/alertmanager"
  retention: 120h0m0s
  external_url: "http://192.168.31.201:9009/alertmanager"
  poll_interval: 15s
  max_recv_msg_size: 16777216
  sharding_enabled: true
  sharding_ring:
    kvstore:
      store: "etcd"
      prefix: "/cortex/alertmanagers/"
      etcd:
        endpoints: ["192.168.31.201:2379","192.168.31.202:2379","192.168.31.203:2379"]
        dial_timeout: 10s
        max_retries: 10
        tls_enabled: true
        tls_cert_path: "/opt/cortex/pki/server.crt"
        tls_key_path: "/opt/cortex/pki/server.key"
        tls_ca_path: "/opt/cortex/pki/ca.crt"
        tls_insecure_skip_verify: true
    heartbeat_period: 5s
    heartbeat_timeout: 1m0s
    replication_factor: 3
    instance_id: node1
    instance_port: 9005
    instance_addr: "192.168.31.201"
  cluster:
    listen_address: 192.168.31.201:9094
    advertise_address: 192.168.31.201:9094
    peers: "192.168.31.201:9094,192.168.31.202:9094,192.168.31.203:9094"
    gossip_interval: 10s
  enable_api: true

alertmanager_storage:
  backend: s3
  s3:
    endpoint: "192.168.31.200:9000"
    insecure: false
    bucket_name: "uptime"
    access_key_id: "minioadmin"
    secret_access_key: "minioadmin"

数据结构

MultitenantAlertmanagerConfig

github.com/cortexproject/cortex/pkg/alertmanager/multitenant.go

// MultitenantAlertmanagerConfig is the configuration for a multitenant Alertmanager.
type MultitenantAlertmanagerConfig struct {
    // 存放告警模版、静默规则等
    DataDir        string           `yaml:"data_dir"`
    // 静默规则被删除后保留该时间后释放
    Retention      time.Duration    `yaml:"retention"`
    // 通过 webhook 回调通知中的 externalURL 属性
    ExternalURL    flagext.URLValue `yaml:"external_url"`
    // 多久从存储中同步一次数据至本地
    PollInterval   time.Duration    `yaml:"poll_interval"`
    // 允许传输的最大字节,保留默认 16M 既可
    MaxRecvMsgSize int64            `yaml:"max_recv_msg_size"`

    // Enable sharding for the Alertmanager
    // 是否开启集群分片
    ShardingEnabled bool       `yaml:"sharding_enabled"`
    // 配置集群哈希环
    ShardingRing    RingConfig `yaml:"sharding_ring"`

    // 如果实例未配置,则默认使用此文件内容
    FallbackConfigFile string `yaml:"fallback_config_file"`
    AutoWebhookRoot    string `yaml:"auto_webhook_root"`

    // 集群配置
    Cluster ClusterConfig `yaml:"cluster"`

    // 开启接口
    EnableAPI bool `yaml:"enable_api"`

    // For distributor.
    AlertmanagerClient ClientConfig `yaml:"alertmanager_client"`

    // For the state persister.
    Persister PersisterConfig `yaml:",inline"`

    // 配置哪些租户可以使用 alertmanager 功能
    EnabledTenants  flagext.StringSliceCSV `yaml:"enabled_tenants"`
    DisabledTenants flagext.StringSliceCSV `yaml:"disabled_tenants"`
}

RingConfig

// RingConfig masks the ring lifecycler config which contains
// many options not really required by the alertmanager ring. This config
// is used to strip down the config to the minimum, and avoid confusion
// to the user.
type RingConfig struct {
    KVStore              kv.Config     `yaml:"kvstore" doc:"description=The key-value store used to share the hash ring across multiple instances."`
    HeartbeatPeriod      time.Duration `yaml:"heartbeat_period"`
    HeartbeatTimeout     time.Duration `yaml:"heartbeat_timeout"`
    ReplicationFactor    int           `yaml:"replication_factor"`
    ZoneAwarenessEnabled bool          `yaml:"zone_awareness_enabled"`

    // Instance details
    InstanceID             string   `yaml:"instance_id" doc:"hidden"`
    InstanceInterfaceNames []string `yaml:"instance_interface_names"`
    InstancePort           int      `yaml:"instance_port" doc:"hidden"`
    InstanceAddr           string   `yaml:"instance_addr" doc:"hidden"`
    InstanceZone           string   `yaml:"instance_availability_zone"`

    // Injected internally
    ListenPort      int           `yaml:"-"`
    RingCheckPeriod time.Duration `yaml:"-"`

    // Used for testing
    SkipUnregister bool `yaml:"-"`
}

ClusterConfig

type ClusterConfig struct {
    ListenAddr       string                 `yaml:"listen_address"`
    AdvertiseAddr    string                 `yaml:"advertise_address"`
    Peers            flagext.StringSliceCSV `yaml:"peers"`
    PeerTimeout      time.Duration          `yaml:"peer_timeout"`
    GossipInterval   time.Duration          `yaml:"gossip_interval"`
    PushPullInterval time.Duration          `yaml:"push_pull_interval"`
}

ClientConfig

// ClientConfig is the configuration struct for the alertmanager client.
type ClientConfig struct {
    RemoteTimeout   time.Duration    `yaml:"remote_timeout"`
    TLSEnabled      bool             `yaml:"tls_enabled"`
    TLS             tls.ClientConfig `yaml:",inline"`
    GRPCCompression string           `yaml:"grpc_compression"`
}

PersisterConfig

type PersisterConfig struct {
    Interval time.Duration `yaml:"persist_interval"`
}

kv.Config

Distributor

tls.ClientConfig

TODO;

alertstore.Config

github.com/cortexproject/cortex/pkg/alertmanager/alertstore/config.go

Ruler rulestore.Config




最后修改 2023.07.06: refactor: update some (5fe4b38)