Skip to content

Latest commit

 

History

History
45 lines (38 loc) · 1.05 KB

08. exporter.md

File metadata and controls

45 lines (38 loc) · 1.05 KB

Ghi chép một chút về exporter

Viết exporter cơ bản để test tải prometheus

Tạo một exporter

yum install python3.6 python36-pip -y
pip3 install --upgrade pip
pip  install virtualenv
mkdir env
virtualenv  env/
source env/bin/activate
pip install ipython
cat <<EOF > exporter.py
from prometheus_client import start_http_server, Summary
import random
import time

# Create a metric to track time spent and requests made.
for i in range(1,20000):
    request='request_processing_seconds'+ str(i)
    Summary(request, 'Time spent processing request3')

# Decorate function with metric.
@REQUEST_TIME.time()
def process_request(t):
    """A dummy function that takes some time."""
    time.sleep(t)

if __name__ == '__main__':
    # Start up the server to expose the metrics.
    start_http_server(8000)
    # Generate some requests.
    while True:
        process_request(random.random())
EOF
cat <<EOF > requirements.txt
prometheus_client>=0.0.19
requests==2.13.0
EOF
pip install --no-cache-dir -r requirements.txt
python  exporter.py