Get Started
Configurationglobalscrape_configtargetrule_filesPushing MetricsWhen to use pushgatewayJava SDKlog file exporter
Get Started
[ Prometheus docs ] Get started
[ Blog ] Docker를 이용하여 Prometheus 설치하기
docker run -d -p 9090:9090 --name=prom -v $PWD/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
docker run \ -d --name=prometheus \ -p 9090:9090 \ -v /prometheus/config:/etc/prometheus \ -v /prometheus/data:/data \ prom/prometheus:v2.29.2 \ --config.file=/etc/prometheus/prometheus.yml \ --storage.tsdb.path=/data \ --web.enable-lifecycle
Configuration
[ Prometheus Docs ] Configuration
- command-line flags configure immutable system parameters (such as storage locations, amount of data to keep on disk and in memory, etc.)
- the configuration file defines everything related to scraping jobs and their instances , as well as which rule files to load
global
scrape_config
- 프로메테우스가 target 으로부터 데이터를 어떻게 scrape 할 것인지를 정하는 섹션임
- target은
static_configs
파라미터를 통해 정적으로 구성될 수도 있고 지원되는 service-discovery mechanism 에 의해 동적으로 발견될 수도 있음
scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: "pushgateway" honor_labels: true # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ["host.docker.internal:9091"]
target
[Prometheus Docs ] Monitoring Linux Host metrics with the node exporter
rule_files
[ Prometheus docs ] defining recording rules
- rule 파일을 이용하여 스크래핑된 데이터에 집계 함수를 적용하여 새로운 시계열 데이터로 바꿔버릴 수 있음
- 수 천개의 시계열 데이터를 집계하는(aggregate) 쿼리를 ad-hoc하게 실행하게 되면 많이 느려짐. 그래서
recording rules
를 구성함으로 표현식을 미리 정의하여 새로운 시계열 데이터로 변환을 효율적으로 할 수 있음
Pushing Metrics
[ Prometheus Docs ] Pushing metrics
[ Github ] Pushgateway
When to use pushgateway
[ Prometheus Docs ] When to use the pushgateway
- Usually, the only valid use case for the Pushgateway is for capturing the outcome of a service-level batch job
Java SDK
[ Github ] prometheus/java_client
public class Main { public static void main(String[] args) throws IOException, InterruptedException { PushGateway pushGateway = new PushGateway("localhost:9091"); CollectorRegistry registry = new CollectorRegistry(); Gauge value = Gauge.build() .name("test_value").help("Test").register(registry); while (true) { // value.inc(0.001); pushGateway.pushAdd(registry, "pushgateway"); Thread.sleep(5L * 1000); } } }
log file exporter
[ StackOverflow ] Monitoring log files using some metrics exporter + Prometheus + grafana
[ Github ] grok_exporter : star 777
[ Github ] google/mtail : start 3.4K
[ Github ] influxdata/telegraf : star 12.4k
Telegraf