출처

https://ichi.pro/ko/prometheus-mich-grafanaleul-sayonghan-node-js-aepeullikeisyeon-moniteoling-194123578535907

 

const http = require('http')
const url = require('url')
const client = require('prom-client')
// Create a Registry which registers the metrics
const register = new client.Registry()
// Add a default label which is added to all metrics
register.setDefaultLabels({
  app: 'example-nodejs-app'
})
// Enable the collection of default metrics
client.collectDefaultMetrics({ register })
// Create a histogram metric
const httpRequestDurationMicroseconds = new client.Histogram({
  name: 'http_request_duration_seconds',
  help: 'Duration of HTTP requests in microseconds',
  labelNames: ['method', 'route', 'code'],
  buckets: [0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10]
})
// Register the histogram
register.registerMetric(httpRequestDurationMicroseconds)
// Define the HTTP server
const server = http.createServer(async (req, res) => {
    // Start the timer
  const end = httpRequestDurationMicroseconds.startTimer()
// Retrieve route from request object
  const route = url.parse(req.url).pathname
if (route === '/metrics') {
    // Return all metrics the Prometheus exposition format
    res.setHeader('Content-Type', register.contentType)
    res.end(register.metrics())
  }
// End timer and add labels
  end({ route, code: res.statusCode, method: req.method })
})
// Start the HTTP server which exposes the metrics on http://localhost:8080/metrics
server.listen(8080)

nodejs server.js

 

프로메테우스 설치 

#apt install prometheus

#cd /etc/prometheus

#vi prometheus.yml

global:
  scrape_interval: 5s
scrape_configs:
  - job_name: "example-nodejs-app"
    static_configs:
      - targets: ["localhost:8080"]

#service prometheus restart

 

prometheus_http_request_duration_seconds_bucket

프로메테우스 실행 완료  

 

Grafana

#cd /etc/prometheus

#vi datasources.ym


apiVersion: 1
datasources:
  - name: Prometheus
    type: prometheus
    access: proxy
    orgId: 1
    url: http://docker.for.mac.host.internal:9090
    basicAuth: false
    isDefault: true
    editable: true

 


docker run --rm -p 3000:3000 \
  -e GF_AUTH_DISABLE_LOGIN_FORM=true \
  -e GF_AUTH_ANONYMOUS_ENABLED=true \
  -e GF_AUTH_ANONYMOUS_ORG_ROLE=Admin \
  -v `pwd`/datasources.yml://etc/prometheus \
  grafana/grafana-enterprise:8.3.6-ubuntu


 

 

'시스템' 카테고리의 다른 글

MongoDB Replica Set  (0) 2023.01.10
s3 권한이 없는 경우  (0) 2022.05.17
nginx/1.18.0 (Ubuntu20.04) gzip  (0) 2022.03.07
nginx/1.18.0 (Ubuntu20.04) brotli  (0) 2022.01.11
Gitlab CI react app 배포  (0) 2021.12.31
블로그 이미지

iesay

,

wasm 파일에  gzip을 적용하는게 목표 타입 추가

cd /etc/nginx

vi mime.types

application/xspf+xml xspf;
application/zip zip;
application/wasm wasm;

 

nginx.conf  http 부분에서 내용 변환

cd /etc/nginx

vi nginx.conf


        ##
        # Gzip Settings
        ##
        gzip on;
        gzip_disable "msie6";

        gzip_comp_level 6;
        gzip_min_length 500;
        gzip_buffers 16 8k;
        gzip_proxied any;
        gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/rss+xml application/wasm image/svg+xml image/png;


nginx 재부팅

nginx -t

service nginx restart

 

 

gzip on;
gzip_static on;
gzip_disable     "msie6"; # 자동으로 IE6, 5.5를 감지해서 disable한다.
# gzip_disable "MSIE [1-6]\.(?!.*SV1)"; # nginx 0.7 이하에서만
gzip_types application/x-javascript application/javascript application/xml text/javascript application/json text/json text/css text/plain application/xhtml+xml application/rss+xml application/wasm ;

개발자 도구에서 동작 확인

'시스템' 카테고리의 다른 글

s3 권한이 없는 경우  (0) 2022.05.17
프로메테우스 모니터링  (0) 2022.03.30
nginx/1.18.0 (Ubuntu20.04) brotli  (0) 2022.01.11
Gitlab CI react app 배포  (0) 2021.12.31
AWS Amplify 설치  (0) 2021.12.28
블로그 이미지

iesay

,

 

출처 : https://gist.github.com/jivanpal/ce90c0d34ead57bc33d10099278ab423

        https://stackoverflow.com/questions/43862412/why-is-brotli-not-supported-on-http

 

Why is Brotli not supported on HTTP?

I noticed an odd thing where apparently Firefox says it supports Brotli on HTTPS, but not HTTP? As Brotli is like gzip but more efficient, why would it limit it to HTTPS? On a HTTPS tab I see: Acc...

stackoverflow.com

환경 : nginx/1.18.0 (Ubuntu20.04) brotli

        https에서만 동작

 

출처에 있는 셀 스크립트 소스르 vi해서 파일을 만든다.

vi compile-nginx-brotli-modules.sh
chmod 777 compile-nginx-brotli-modules.sh
./compile-nginx-brotli-modules.sh

 

디렉토리 이동후 SO파일을 복사 한다.

cd /root/build/nginx-1.18.0/objs

cp *.so /usr/lib/nginx/modules/

cp *.so /usr/share/nginx/modules

vi /etc/nginx/nginx.conf

최상단에 추가

load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;

vi /etc/nginx/nginx.conf     http 안에 추가 

brotli on;
brotli_comp_level 6;
brotli_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/wasm application/xml+rss text/javascript image/x-icon image/vnd.microsoft.icon image/bmp image/svg+xml;
brotli_static on;

 

nginx 재부팅 

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
service nginx restart

 

 

개발자 도구 네트워크 탭에서 확인 할수 있다.

 

적용 전 

 

 

적용 후 

 

 

'시스템' 카테고리의 다른 글

프로메테우스 모니터링  (0) 2022.03.30
nginx/1.18.0 (Ubuntu20.04) gzip  (0) 2022.03.07
Gitlab CI react app 배포  (0) 2021.12.31
AWS Amplify 설치  (0) 2021.12.28
ipfs 사용법  (0) 2021.12.06
블로그 이미지

iesay

,