Monitor


Monitor 미들웨어는 express-status-monitor에서 영감을 받아 Fiber를 위해 서버 메트릭을 보고합니다.

Monitor는 아직 베타 버전이며, 향후 API가 변경될 수 있습니다!

monitor

Signatures

func New() fiber.Handler

Examples

Fiber 웹 프레임워크의 일부인 미들웨어 패키지를 import 합니다.

import (
  "github.com/gofiber/fiber/v2"
  "github.com/gofiber/fiber/v2/middleware/monitor"
)

Fiber 앱을 초기화한 후 다음과 같은 가능성이 있습니다:

// 기본 구성 초기화 (미들웨어를 /metrics에 할당)
app.Get("/metrics", monitor.New())

// 또는 사용자 지정을 위해 구성 확장
// 미들웨어를 /metrics에 할당
// 그리고 제목을 `MyService Metrics Page`로 변경
app.Get("/metrics", monitor.New(monitor.Config{Title: "MyService Metrics Page"}))

또한 curl -X GET -H "Accept: application/json" http://localhost:3000/metrics로 API 엔드포인트에 액세스할 수 있으며, 다음을 반환합니다:

{
  "pid": {
    "cpu": 0.4568381746582226,
    "ram": 20516864,
    "conns": 3
  },
  "os": {
    "cpu": 8.759124087593099,
    "ram": 3997155328,
    "conns": 44,
    "total_ram": 8245489664,
    "load_avg": 0.51
  }
}

Config

Property
Type
Description
Default

Title

string

메트릭 페이지 제목

"Fiber Monitor"

Refresh

time.Duration

새로 고침 주기

3초

APIOnly

bool

서비스가 모니터링 API만 노출해야 하는지 여부

false

Next

func(*fiber.Ctx) bool

Next는 true를 반환할 때 이 미들웨어를 건너뛰는 함수를 정의합니다.

nil

CustomHead

string

Head 섹션에 사용자 지정 HTML 코드 (끝 전)

빈 문자열

FontURL

string

FontURL은 글꼴 리소스 경로 또는 URL을 지정합니다.

"https://fonts.googleapis.com/css2?family=Roboto:wght@400;900&display=swap"

ChartJsURL

string

ChartJsURL은 ChartJS 라이브러리 경로 또는 URL을 지정합니다.

"https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.bundle.min.js"

Default Config

var ConfigDefault = Config{
  Title:       defaultTitle,
  Refresh:     defaultRefresh,
  FontURL:     defaultFontURL,
  ChartJsURL:  defaultChartJSURL,
  CustomHead:  defaultCustomHead,
  APIOnly:     false,
  Next:        nil,
  index:       newIndex(viewBag{
    defaultTitle,
    defaultRefresh,
    defaultFontURL,
    defaultChartJSURL, 
    defaultCustomHead,
  }),
}

Last updated