docker run -d --net=host --name pushgateway prom/pushgateway:v1.4.1
ss -nltp
localhost:9091
scrape_configs:
- job_name: 'pushgateway'
follow_redirects: false
scrape_interval: 2s
scrape_timeout: 1s
static_configs:
- targets:
- localhost:9091
- 파일로부터 전송할 데이터를 불러오는것 , stdin으로부터 data를 받아오겠다는 말
echo "test_metric 1" | curl --data-binary @- http://localhost:9091/metrics/job/test_job
localhost:9091 들어가서 데이터 확인
echo "test_metric 1 1" | curl --data-binary @- http://localhost:9091/metrics/job/test_job
위처럼 "failed!" 경고창과 [push_failure_time_seconds]에 value 가 생김
현재 동작중인 pushgateway 정보와 설치 시 옵션 나옴
http://localhost:9091/#
다른 label 들 입력해보기
echo "test_metric 1" | curl --data-binary @- http://localhost:9091/metrics/job/test_job/instance/batch-server
echo "test_metric 1" | curl --data-binary @- http://localhost:9091/metrics/job/test_job/instance/batch-server/region/kr
(region=kr 이라는 label이 새로 추가됨)
curl -XDELETE http://localhost:9091/metrics/job/test_job/instance/batch-server/region/kr
curl -XDELETE http://localhost:9091/metrics/job/test_job/
삭제하려면 모든레이블이 일치하게끔 작성해서 DELETE 해줘야 함.
[batch 코드 실습]
폴더 생성 후 cd $폴더
npm init -y
npm i waait
npm i prom-client
worker.js 파일 생성
const wait = require('waait');
const { Registry, Pushgateway, Gauge } = require('prom-client');
const register = new Registry()
const gauge = new Gauge({
name:'batch_process_time_second',
help:'Time taken for batch job to complete',
registers : [register],
})
async function batchJob(){
if (Math.random() < 0.3) throw new Error('batch job failed')
else {
await wait(2*Math.random() * 1000)
}
}
const main = (async function() {
try{
const startTime = Date.now()
await batchJob()
gauge.set((Date.now()- startTime) / 1000)
}catch (e){
gauge.set(-1)
}
const gateway = new Pushgateway('http://localhost:9091', [], register)
return gateway.push({
jobName:'batch',
groupings: { instance: 'batch-server'}
})
})()
node worker.js 실행
pushgateway 확인