Documentation ¶
Index ¶
- Variables
- func EnvToPrometheusFlags(prefix string) []string
- func GetAlertConfig(alerts map[string]Alert) string
- func WriteConfig(configPath string, scrapes map[string]Scrape, alerts map[string]Alert, ...)
- type Alert
- type AlertingConfig
- type AlertmanagerConfig
- type BasicAuth
- type Config
- func (c *Config) CreateFileStaticConfig(scrapes map[string]Scrape, nodeLabels map[string]map[string]string, ...)
- func (c *Config) InsertAlertManagerURL(alertURLs string)
- func (c *Config) InsertEnv(envKey string, envValue string) error
- func (c *Config) InsertScrapes(scrapes map[string]Scrape)
- func (c *Config) InsertScrapesFromDir(dir string)
- type DNSSDConfig
- type FileStaticConfig
- type GlobalConfig
- type HTTPClientConfig
- type NodeIP
- type NodeIPSet
- type QueueConfig
- type RelabelConfig
- type RemoteReadConfig
- type RemoteWriteConfig
- type SDConfig
- type Scrape
- type ScrapeConfig
- type ServiceDiscoveryConfig
- type TLSConfig
- type TargetGroup
Constants ¶
This section is empty.
Variables ¶
var FS = afero.NewOsFs()
FS defines file system used to read and write configuration files
var Reload = func() error { mu.Lock() defer mu.Unlock() logPrintf("Reloading Prometheus") cmd := exec.Command("pkill", "-HUP", "prometheus") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr err := cmdRun(cmd) if err != nil { logPrintf(err.Error()) } logPrintf("Prometheus was reloaded") return err }
Reload sends `pkill -HUP` signal to `prometheus` process.
var Run = func() error { logPrintf("Starting Prometheus") cmdString := "prometheus" flags := EnvToPrometheusFlags("ARG") if len(flags) > 0 { allFlags := strings.Join(flags, " ") cmdString = fmt.Sprintf("%s %s", cmdString, allFlags) } cmd := exec.Command("/bin/sh", "-c", cmdString) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return cmdRun(cmd) }
Run starts `prometheus` process
Functions ¶
func EnvToPrometheusFlags ¶
EnvToPrometheusFlags converts environmental variables into a string of flags to be used with prometheus v2 CLI
func GetAlertConfig ¶
GetAlertConfig returns Prometheus configuration snippet related to alerts.
Types ¶
type Alert ¶
type Alert struct { AlertAnnotations map[string]string `json:"alertAnnotations,omitempty"` AlertFor string `json:"alertFor,omitempty"` AlertIf string `json:"alertIf,omitempty"` AlertLabels map[string]string `json:"alertLabels,omitempty"` AlertName string `json:"alertName"` AlertPersistent bool `json:"alertPersistent"` AlertNameFormatted string ServiceName string `json:"serviceName"` Replicas int `json:"replicas"` }
Alert defines data used to create alert configuration snippet
type AlertingConfig ¶
type AlertingConfig struct { AlertRelabelConfigs []*RelabelConfig `yaml:"alert_relabel_configs,omitempty"` AlertmanagerConfigs []*AlertmanagerConfig `yaml:"alertmanagers,omitempty"` }
AlertingConfig configures alerting and alertmanager related configs.
type AlertmanagerConfig ¶
type AlertmanagerConfig struct { ServiceDiscoveryConfig ServiceDiscoveryConfig `yaml:",inline"` HTTPClientConfig HTTPClientConfig `yaml:",inline"` // The URL scheme to use when talking to Alertmanagers. Scheme string `yaml:"scheme,omitempty"` // Path prefix to add in front of the push endpoint path. PathPrefix string `yaml:"path_prefix,omitempty"` // The timeout used when sending alerts. Timeout string `yaml:"timeout,omitempty"` // List of Alertmanager relabel configurations. RelabelConfigs []*RelabelConfig `yaml:"relabel_configs,omitempty"` }
AlertmanagerConfig configures how Alertmanagers can be discovered and communicated with.
type Config ¶
type Config struct { GlobalConfig GlobalConfig `yaml:"global,omitempty"` AlertingConfig AlertingConfig `yaml:"alerting,omitempty"` RuleFiles []string `yaml:"rule_files,omitempty"` ScrapeConfigs []*ScrapeConfig `yaml:"scrape_configs,omitempty"` RemoteWriteConfigs []*RemoteWriteConfig `yaml:"remote_write,omitempty"` RemoteReadConfigs []*RemoteReadConfig `yaml:"remote_read,omitempty"` }
Config is the top-level configuration for Prometheus's config files.
func (*Config) CreateFileStaticConfig ¶
func (c *Config) CreateFileStaticConfig(scrapes map[string]Scrape, nodeLabels map[string]map[string]string, fileSDDir string)
CreateFileStaticConfig creates static config files
func (*Config) InsertAlertManagerURL ¶
InsertAlertManagerURL inserts alert into config
func (*Config) InsertScrapes ¶
InsertScrapes inserts scrapes into config
func (*Config) InsertScrapesFromDir ¶
InsertScrapesFromDir inserts scrapes from directory
type DNSSDConfig ¶
type DNSSDConfig struct { Names []string `yaml:"names"` RefreshInterval string `yaml:"refresh_interval,omitempty"` Type string `yaml:"type"` Port int `yaml:"port"` // Ignored for SRV records }
DNSSDConfig is the configuration for DNS based service discovery.
type FileStaticConfig ¶
type FileStaticConfig []*TargetGroup
FileStaticConfig configures File-based service discovery
type GlobalConfig ¶
type GlobalConfig struct { // How frequently to scrape targets by default. ScrapeInterval string `yaml:"scrape_interval,omitempty"` // The default timeout when scraping targets. ScrapeTimeout string `yaml:"scrape_timeout,omitempty"` // How frequently to evaluate rules by default. EvaluationInterval string `yaml:"evaluation_interval,omitempty"` // The labels to add to any timeseries that this Prometheus instance scrapes. ExternalLabels map[string]string `yaml:"external_labels,omitempty"` }
GlobalConfig configures values that are used across other configuration objects.
type HTTPClientConfig ¶
type HTTPClientConfig struct { // The HTTP basic authentication credentials for the targets. BasicAuth *BasicAuth `yaml:"basic_auth,omitempty"` // The bearer token for the targets. BearerToken string `yaml:"bearer_token,omitempty"` // The bearer token file for the targets. BearerTokenFile string `yaml:"bearer_token_file,omitempty"` // HTTP proxy server to use to connect to the targets. ProxyURL string `yaml:"proxy_url,omitempty"` // TLSConfig to use to connect to the targets. TLSConfig TLSConfig `yaml:"tls_config,omitempty"` }
HTTPClientConfig configures an HTTP client.
type NodeIPSet ¶
type NodeIPSet map[NodeIP]struct{}
NodeIPSet is a set of NodeIPs
func (NodeIPSet) Cardinality ¶
Cardinality returns the size of set
func (NodeIPSet) MarshalJSON ¶
MarshalJSON creates JSON array from NodeIPSet
func (*NodeIPSet) UnmarshalJSON ¶
UnmarshalJSON recreates NodeIPSet from a JSON array
type QueueConfig ¶
type QueueConfig struct { // Number of samples to buffer per shard before we start dropping them. Capacity int `yaml:"capacity,omitempty"` // Max number of shards, i.e. amount of concurrency. MaxShards int `yaml:"max_shards,omitempty"` // Maximum number of samples per send. MaxSamplesPerSend int `yaml:"max_samples_per_send,omitempty"` // Maximum time sample will wait in buffer. BatchSendDeadline string `yaml:"batch_send_deadline,omitempty"` // Max number of times to retry a batch on recoverable errors. MaxRetries int `yaml:"max_retries,omitempty"` // On recoverable errors, backoff exponentially. MinBackoff string `yaml:"min_backoff,omitempty"` MaxBackoff string `yaml:"max_backoff,omitempty"` }
QueueConfig is the configuration for the queue used to write to remote storage.
type RelabelConfig ¶
type RelabelConfig struct { // A list of labels from which values are taken and concatenated // with the configured separator in order. SourceLabels []string `yaml:"source_labels,flow,omitempty"` // Separator is the string between concatenated values from the source labels. Separator string `yaml:"separator,omitempty"` // Regex against which the concatenation is matched. Regex string `yaml:"regex,omitempty"` // Modulus to take of the hash of concatenated values from the source labels. Modulus uint64 `yaml:"modulus,omitempty"` // TargetLabel is the label to which the resulting string is written in a replacement. // Regexp interpolation is allowed for the replace action. TargetLabel string `yaml:"target_label,omitempty"` // Replacement is the regex replacement pattern to be used. Replacement string `yaml:"replacement,omitempty"` // Action is the action to be performed for the relabeling. Action string `yaml:"action,omitempty"` }
RelabelConfig is the configuration for relabeling of target label sets.
type RemoteReadConfig ¶
type RemoteReadConfig struct { URL string `yaml:"url"` RemoteTimeout string `yaml:"remote_timeout,omitempty"` ReadRecent bool `yaml:"read_recent,omitempty"` HTTPClientConfig HTTPClientConfig `yaml:",inline"` // RequiredMatchers is an optional list of equality matchers which have to // be present in a selector to query the remote read endpoint. RequiredMatchers map[string]string `yaml:"required_matchers,omitempty"` }
RemoteReadConfig is the configuration for reading from remote storage.
type RemoteWriteConfig ¶
type RemoteWriteConfig struct { URL string `yaml:"url"` RemoteTimeout string `yaml:"remote_timeout,omitempty"` WriteRelabelConfigs []*RelabelConfig `yaml:"write_relabel_configs,omitempty"` HTTPClientConfig HTTPClientConfig `yaml:",inline"` QueueConfig QueueConfig `yaml:"queue_config,omitempty"` }
RemoteWriteConfig is the configuration for writing to remote storage.
type SDConfig ¶
type SDConfig struct { Files []string `yaml:"files"` RefreshInterval string `yaml:"refresh_interval,omitempty"` }
SDConfig is the configuration for file based discovery.
type Scrape ¶
type Scrape struct { MetricsPath string `json:"metricsPath,string,omitempty"` ScrapeInterval string `json:"scrapeInterval,string,omitempty"` ScrapeLabels *map[string]string `json:"scrapeLabels,omitempty"` ScrapePort int `json:"scrapePort,string,omitempty"` ScrapeTimeout string `json:"scrapeTimeout,string,omitempty"` ScrapeType string `json:"scrapeType"` ServiceName string `json:"serviceName"` NodeInfo NodeIPSet `json:"nodeInfo,omitempty"` }
Scrape defines data used to create scraping configuration snippet
type ScrapeConfig ¶
type ScrapeConfig struct { // The job name to which the job label is set by default. JobName string `yaml:"job_name"` // Indicator whether the scraped metrics should remain unmodified. HonorLabels bool `yaml:"honor_labels,omitempty"` // A set of query parameters with which the target is scraped. Params map[string][]string `yaml:"params,omitempty"` // How frequently to scrape the targets of this scrape config. ScrapeInterval string `yaml:"scrape_interval,omitempty"` // The timeout for scraping targets of this config. ScrapeTimeout string `yaml:"scrape_timeout,omitempty"` // The HTTP resource path on which to fetch metrics from targets. MetricsPath string `yaml:"metrics_path,omitempty"` // The URL scheme with which to fetch metrics from targets. Scheme string `yaml:"scheme,omitempty"` // More than this many samples post metric-relabelling will cause the scrape to fail. SampleLimit uint `yaml:"sample_limit,omitempty"` ServiceDiscoveryConfig ServiceDiscoveryConfig `yaml:",inline"` HTTPClientConfig HTTPClientConfig `yaml:",inline"` // List of target relabel configurations. RelabelConfigs []*RelabelConfig `yaml:"relabel_configs,omitempty"` // List of metric relabel configurations. MetricRelabelConfigs []*RelabelConfig `yaml:"metric_relabel_configs,omitempty"` }
ScrapeConfig configures a scraping unit for Prometheus.
type ServiceDiscoveryConfig ¶
type ServiceDiscoveryConfig struct { // List of labeled target groups for this job. StaticConfigs []*TargetGroup `yaml:"static_configs,omitempty"` // List of DNS service discovery configurations. DNSSDConfigs []*DNSSDConfig `yaml:"dns_sd_configs,omitempty"` // List of file service discovery configurations. FileSDConfigs []*SDConfig `yaml:"file_sd_configs,omitempty"` }
ServiceDiscoveryConfig configures lists of different service discovery mechanisms.
type TLSConfig ¶
type TLSConfig struct { // The CA cert to use for the targets. CAFile string `yaml:"ca_file,omitempty"` // The client cert file for the targets. CertFile string `yaml:"cert_file,omitempty"` // The client key file for the targets. KeyFile string `yaml:"key_file,omitempty"` // Used to verify the hostname for the targets. ServerName string `yaml:"server_name,omitempty"` // Disable target certificate validation. InsecureSkipVerify bool `yaml:"insecure_skip_verify"` }
TLSConfig configures the options for TLS connections.
type TargetGroup ¶
type TargetGroup struct { // Targets is a list of targets identified by a label set. Each target is // uniquely identifiable in the group by its address label. Targets []string `yaml:"targets,omitempty" json:"targets,omitempty"` // Labels is a set of labels that is common across all targets in the group. Labels map[string]string `yaml:"labels,omitempty" json:"labels,omitempty"` // Source is an identifier that describes a group of targets. Source string `yaml:"source,omitempty" json:"source,omitempty"` }
TargetGroup is a set of targets with a common label set(production , test, staging etc.).