├── .all-contributorsrc
├── .github
├── FUNDING.yml
├── dependabot.yml
├── stale.yml
└── workflows
│ ├── auto-approve.yml
│ ├── auto-merge.yml
│ ├── codeql-analysis.yml
│ ├── release.yml
│ ├── test_pr.yml
│ └── test_push.yml
├── .gitignore
├── .golangci.yml
├── .goreleaser.yml
├── .pre-commit-config.yaml
├── .releaserc
├── CODE_OF_CONDUCT.md
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── cmd
├── get.go
├── root.go
├── server.go
└── version.go
├── go.mod
├── go.sum
├── grafana
└── kubernetes-php-fpm.json
├── main.go
├── phpfpm
├── exporter.go
├── phpfpm.go
└── phpfpm_test.go
├── renovate.json
├── sonar-project.properties
└── test
├── docker-compose-e2e.yml
├── docker-compose-local.yml
├── docker-compose.yml
├── e2e.bats
└── prometheus.yml
/.all-contributorsrc:
--------------------------------------------------------------------------------
1 | {
2 | "projectName": "php-fpm_exporter",
3 | "projectOwner": "hipages",
4 | "repoType": "github",
5 | "repoHost": "https://github.com",
6 | "files": [
7 | "README.md"
8 | ],
9 | "imageSize": 100,
10 | "commit": false,
11 | "contributors": [
12 | {
13 | "login": "estahn",
14 | "name": "Enrico Stahn",
15 | "avatar_url": "https://avatars3.githubusercontent.com/u/362174?v=4",
16 | "profile": "http://enricostahn.com",
17 | "contributions": [
18 | "question",
19 | "code",
20 | "doc",
21 | "maintenance",
22 | "test"
23 | ]
24 | },
25 | {
26 | "login": "XooR",
27 | "name": "Stanislav Antic",
28 | "avatar_url": "https://avatars2.githubusercontent.com/u/120429?v=4",
29 | "profile": "https://github.com/XooR",
30 | "contributions": [
31 | "code"
32 | ]
33 | },
34 | {
35 | "login": "herb123456",
36 | "name": "herb",
37 | "avatar_url": "https://avatars1.githubusercontent.com/u/1568165?v=4",
38 | "profile": "http://herb123456.blogspot.com/",
39 | "contributions": [
40 | "code"
41 | ]
42 | },
43 | {
44 | "login": "Nyoroon",
45 | "name": "Smoked Cheese",
46 | "avatar_url": "https://avatars1.githubusercontent.com/u/182203?v=4",
47 | "profile": "https://github.com/Nyoroon",
48 | "contributions": [
49 | "bug",
50 | "code"
51 | ]
52 | },
53 | {
54 | "login": "sas1024",
55 | "name": "Alexander",
56 | "avatar_url": "https://avatars3.githubusercontent.com/u/7388179?v=4",
57 | "profile": "https://www.old-games.ru",
58 | "contributions": [
59 | "code"
60 | ]
61 | },
62 | {
63 | "login": "stanxing",
64 | "name": "Stan Xing",
65 | "avatar_url": "https://avatars2.githubusercontent.com/u/23288646?v=4",
66 | "profile": "https://github.com/stanxing",
67 | "contributions": [
68 | "code"
69 | ]
70 | },
71 | {
72 | "login": "itcsoft54",
73 | "name": "itcsoft54",
74 | "avatar_url": "https://avatars2.githubusercontent.com/u/22459145?v=4",
75 | "profile": "https://github.com/itcsoft54",
76 | "contributions": [
77 | "code"
78 | ]
79 | },
80 | {
81 | "login": "adduc",
82 | "name": "John S Long",
83 | "avatar_url": "https://avatars0.githubusercontent.com/u/44527?v=4",
84 | "profile": "http://128.io",
85 | "contributions": [
86 | "infra"
87 | ]
88 | },
89 | {
90 | "login": "danielocallaghan",
91 | "name": "Daniel O'Callaghan",
92 | "avatar_url": "https://avatars.githubusercontent.com/u/62488?v=4",
93 | "profile": "https://github.com/danielocallaghan",
94 | "contributions": [
95 | "code"
96 | ]
97 | },
98 | {
99 | "login": "stchr",
100 | "name": "Simon Stücher",
101 | "avatar_url": "https://avatars.githubusercontent.com/u/166079?v=4",
102 | "profile": "https://github.com/stchr",
103 | "contributions": [
104 | "bug"
105 | ]
106 | },
107 | {
108 | "login": "andresterba",
109 | "name": "André Sterba",
110 | "avatar_url": "https://avatars.githubusercontent.com/u/48120735?v=4",
111 | "profile": "https://sterba.dev",
112 | "contributions": [
113 | "code"
114 | ]
115 | }
116 | ],
117 | "contributorsPerLine": 7,
118 | "skipCi": true
119 | }
120 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: [estahn]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: hipages/php-fpm_exporter
11 | otechie: # Replace with a single Otechie username
12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "github-actions"
4 | directory: "/"
5 | target-branch: "master"
6 | schedule:
7 | interval: "monthly"
8 |
9 | - package-ecosystem: "docker"
10 | directory: "/"
11 | target-branch: "master"
12 | schedule:
13 | interval: "daily"
14 |
15 | - package-ecosystem: "gomod"
16 | directory: "/"
17 | target-branch: "master"
18 | schedule:
19 | interval: "monthly"
20 |
--------------------------------------------------------------------------------
/.github/stale.yml:
--------------------------------------------------------------------------------
1 | ---
2 | # https://github.com/probot/stale
3 | # Number of days of inactivity before an issue becomes stale
4 | daysUntilStale: 60
5 | # Number of days of inactivity before a stale issue is closed
6 | daysUntilClose: 7
7 | # Issues with these labels will never be considered stale
8 | exemptLabels:
9 | - pinned
10 | - security
11 | # Label to use when marking an issue as stale
12 | staleLabel: wontfix
13 | # Comment to post when marking an issue as stale. Set to `false` to disable
14 | markComment: >
15 | This issue has been automatically marked as stale because it has not had
16 | recent activity. It will be closed if no further activity occurs. Thank you
17 | for your contributions.
18 | # Comment to post when closing a stale issue. Set to `false` to disable
19 | closeComment: false
20 |
--------------------------------------------------------------------------------
/.github/workflows/auto-approve.yml:
--------------------------------------------------------------------------------
1 | name: Auto approve
2 |
3 | on:
4 | pull_request_target
5 |
6 | jobs:
7 | auto-approve:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: hmarr/auto-approve-action@v4
11 | if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
12 | with:
13 | github-token: "${{ secrets.GITHUB_TOKEN }}"
14 |
--------------------------------------------------------------------------------
/.github/workflows/auto-merge.yml:
--------------------------------------------------------------------------------
1 | name: Auto-Merge
2 | on:
3 | pull_request_target
4 |
5 | jobs:
6 | enable-auto-merge:
7 | runs-on: ubuntu-latest
8 |
9 | if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
10 | steps:
11 | - uses: alexwilson/enable-github-automerge-action@main
12 | with:
13 | github-token: "${{ secrets.GITHUB_TOKEN }}"
14 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL"
13 |
14 | on:
15 | push:
16 | branches: [ master ]
17 | pull_request:
18 | # The branches below must be a subset of the branches above
19 | branches: [ master ]
20 | schedule:
21 | - cron: '28 21 * * 6'
22 |
23 | jobs:
24 | analyze:
25 | name: Analyze
26 | runs-on: ubuntu-latest
27 |
28 | strategy:
29 | fail-fast: false
30 | matrix:
31 | language: [ 'go' ]
32 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
33 | # Learn more:
34 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
35 |
36 | steps:
37 | - name: Checkout repository
38 | uses: actions/checkout@v3
39 |
40 | # Initializes the CodeQL tools for scanning.
41 | - name: Initialize CodeQL
42 | uses: github/codeql-action/init@v2
43 | with:
44 | languages: ${{ matrix.language }}
45 | # If you wish to specify custom queries, you can do so here or in a config file.
46 | # By default, queries listed here will override any specified in a config file.
47 | # Prefix the list here with "+" to use these queries and those in the config file.
48 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
49 |
50 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
51 | # If this step fails, then you should remove it and run the build manually (see below)
52 | - name: Autobuild
53 | uses: github/codeql-action/autobuild@v2
54 |
55 | # ℹ️ Command-line programs to run using the OS shell.
56 | # 📚 https://git.io/JvXDl
57 |
58 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
59 | # and modify them (or add more) to build your code if your project
60 | # uses a compiled language
61 |
62 | #- run: |
63 | # make bootstrap
64 | # make release
65 |
66 | - name: Perform CodeQL Analysis
67 | uses: github/codeql-action/analyze@v2
68 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Release
2 | on:
3 | workflow_dispatch:
4 | # Release patches and secruity updates on a schedule
5 | schedule:
6 | - cron: "0 0 1 * *"
7 |
8 | jobs:
9 | tag:
10 | name: Tag
11 | runs-on: ubuntu-latest
12 | if: github.ref == 'refs/heads/master'
13 | steps:
14 |
15 | - name: Setup Node.js for use with actions
16 | uses: actions/setup-node@v4
17 |
18 | - name: Checkout
19 | uses: actions/checkout@v3
20 | with:
21 | fetch-depth: 0
22 |
23 | - name: Install semantic-release
24 | run: yarn global add --no-progress --non-interactive "semantic-release" "@semantic-release/exec"
25 |
26 | - name: Run semantic-release
27 | run: $(yarn global bin)/semantic-release
28 | env:
29 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30 |
31 | release:
32 | runs-on: ubuntu-latest
33 | # if: startsWith(github.ref, 'refs/tags/')
34 | needs: [tag]
35 | steps:
36 | - name: Checkout
37 | uses: actions/checkout@v3
38 | with:
39 | fetch-depth: 0
40 |
41 | - name: Set up Go
42 | uses: actions/setup-go@v5.3.0
43 | with:
44 | go-version: 1.17
45 | id: go
46 |
47 | - name: Login to DockerHub
48 | uses: docker/login-action@v3.4.0
49 | with:
50 | username: ${{ secrets.DOCKER_USER }}
51 | password: ${{ secrets.DOCKER_PASS }}
52 |
53 | - name: Login to GitHub Container Registry
54 | uses: docker/login-action@v3.4.0
55 | with:
56 | registry: ghcr.io
57 | username: ${{ github.actor }}
58 | password: ${{ secrets.GITHUB_TOKEN }}
59 |
60 | - name: Run GoReleaser
61 | uses: goreleaser/goreleaser-action@v4.3.0
62 | with:
63 | version: latest
64 | args: release --rm-dist
65 | env:
66 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67 |
--------------------------------------------------------------------------------
/.github/workflows/test_pr.yml:
--------------------------------------------------------------------------------
1 | name: Test PR
2 | on:
3 | pull_request_target:
4 | workflow_dispatch:
5 |
6 | jobs:
7 |
8 | lint:
9 | name: Lint
10 | runs-on: ubuntu-latest
11 | steps:
12 |
13 | - name: Set up Go
14 | uses: actions/setup-go@v5.3.0
15 | with:
16 | go-version: 1.17
17 | id: go
18 |
19 | - name: Checkout
20 | uses: actions/checkout@v3
21 | with:
22 | fetch-depth: 0
23 |
24 | - name: golangci-lint
25 | uses: golangci/golangci-lint-action@v6.5.0
26 | with:
27 | version: v1.44
28 |
29 | test:
30 | name: Test
31 | runs-on: ubuntu-latest
32 | steps:
33 |
34 | - name: Setup Go
35 | uses: actions/setup-go@v5.3.0
36 | with:
37 | go-version: 1.17
38 | id: go
39 |
40 | - name: Checkout
41 | uses: actions/checkout@v3
42 | with:
43 | ref: "refs/pull/${{ github.event.number }}/merge"
44 |
45 | - name: Test
46 | run: go test -coverprofile cover.out ./...
47 |
48 | - name: SonarCloud Scan
49 | uses: sonarsource/sonarcloud-github-action@master
50 | env:
51 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
53 |
54 | image-scan:
55 | name: Image Scan
56 | runs-on: ubuntu-latest
57 | steps:
58 | - name: Checkout
59 | uses: actions/checkout@v3
60 | with:
61 | fetch-depth: 0
62 | ref: "refs/pull/${{ github.event.number }}/merge"
63 |
64 | - name: Setup Go
65 | uses: actions/setup-go@v5.3.0
66 | with:
67 | go-version: 1.17
68 | id: go
69 |
70 | - name: Run GoReleaser
71 | uses: goreleaser/goreleaser-action@v4.3.0
72 | with:
73 | version: latest
74 | args: release --rm-dist --snapshot
75 | env:
76 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77 |
78 | - name: Scan image
79 | uses: anchore/scan-action@v6.2.0
80 | id: scan
81 | with:
82 | image: "hipages/php-fpm_exporter:latest"
83 | acs-report-enable: true
84 | fail-build: false
85 |
86 | - name: Upload Anchore scan SARIF report
87 | uses: github/codeql-action/upload-sarif@v2
88 | with:
89 | sarif_file: ${{ steps.scan.outputs.sarif }}
90 |
--------------------------------------------------------------------------------
/.github/workflows/test_push.yml:
--------------------------------------------------------------------------------
1 | name: Test Push
2 | on:
3 | workflow_dispatch:
4 | push:
5 | branches:
6 | - master
7 | - 'releases/*'
8 |
9 | jobs:
10 |
11 | lint:
12 | name: Lint
13 | runs-on: ubuntu-latest
14 | steps:
15 |
16 | - name: Set up Go
17 | uses: actions/setup-go@v5.3.0
18 | with:
19 | go-version: 1.17
20 | id: go
21 |
22 | - name: Checkout
23 | uses: actions/checkout@v3
24 | with:
25 | fetch-depth: 0
26 |
27 | - name: golangci-lint
28 | uses: golangci/golangci-lint-action@v6.5.0
29 | with:
30 | version: v1.44
31 |
32 | test:
33 | name: Test
34 | runs-on: ubuntu-latest
35 | steps:
36 |
37 | - name: Setup Go
38 | uses: actions/setup-go@v5.3.0
39 | with:
40 | go-version: 1.17
41 | id: go
42 |
43 | - name: Checkout
44 | uses: actions/checkout@v3
45 |
46 | - name: Test
47 | run: go test -coverprofile cover.out ./...
48 |
49 | - name: SonarCloud Scan
50 | uses: sonarsource/sonarcloud-github-action@master
51 | env:
52 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
54 |
55 | image-scan:
56 | name: Image Scan
57 | runs-on: ubuntu-latest
58 | steps:
59 | - name: Checkout
60 | uses: actions/checkout@v3
61 | with:
62 | fetch-depth: 0
63 |
64 | - name: Setup Go
65 | uses: actions/setup-go@v5.3.0
66 | with:
67 | go-version: 1.17
68 | id: go
69 |
70 | - name: Run GoReleaser
71 | uses: goreleaser/goreleaser-action@v4.3.0
72 | with:
73 | version: latest
74 | args: release --rm-dist --snapshot
75 | env:
76 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77 |
78 | - name: Scan image
79 | uses: anchore/scan-action@v6.2.0
80 | id: scan
81 | with:
82 | image: "hipages/php-fpm_exporter:latest"
83 | acs-report-enable: true
84 | fail-build: false
85 |
86 | - name: Upload Anchore scan SARIF report
87 | uses: github/codeql-action/upload-sarif@v2
88 | with:
89 | sarif_file: ${{ steps.scan.outputs.sarif }}
90 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Binaries for programs and plugins
2 | *.exe
3 | *.dll
4 | *.so
5 | *.dylib
6 |
7 | # Test binary, build with `go test -c`
8 | *.test
9 |
10 | # Output of the go coverage tool, specifically when used with LiteIDE
11 | *.out
12 |
13 | # dependencies
14 | vendor/
15 |
16 | # IDEs
17 | .idea/
18 |
19 | # goreleaser
20 | dist/
21 |
--------------------------------------------------------------------------------
/.golangci.yml:
--------------------------------------------------------------------------------
1 | linters:
2 | # please, do not use `enable-all`: it's deprecated and will be removed soon.
3 | # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
4 | disable-all: true
5 | enable:
6 | - deadcode
7 | - depguard
8 | - dupl
9 | - errcheck
10 | # - gochecknoinits
11 | - goconst
12 | - gocritic
13 | - gocyclo
14 | - gofmt
15 | - goimports
16 | - revive
17 | - gosec
18 | - gosimple
19 | - govet
20 | - ineffassign
21 | # - lll
22 | - misspell
23 | - nakedret
24 | - exportloopref
25 | - staticcheck
26 | - structcheck
27 | # - typecheck
28 | - unconvert
29 | - unparam
30 | - unused
31 | - varcheck
32 |
--------------------------------------------------------------------------------
/.goreleaser.yml:
--------------------------------------------------------------------------------
1 | builds:
2 | - binary: php-fpm_exporter
3 | env:
4 | - CGO_ENABLED=0
5 | goos:
6 | - windows
7 | - darwin
8 | - linux
9 | goarch:
10 | - amd64
11 | - arm64
12 |
13 | dockers:
14 | - use: buildx
15 | goos: linux
16 | goarch: amd64
17 | image_templates:
18 | - "hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
19 | - "ghcr.io/hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
20 | build_flag_templates:
21 | - "--platform=linux/amd64"
22 | - "--build-arg=VERSION={{.Version}}"
23 | - "--build-arg=BUILD_DATE={{.Date}}"
24 | - "--build-arg=VCS_REF={{.FullCommit}}"
25 | - use: buildx
26 | goos: linux
27 | goarch: arm64
28 | image_templates:
29 | - "hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64"
30 | - "ghcr.io/hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64"
31 | build_flag_templates:
32 | - "--platform=linux/arm64/v8"
33 | - "--build-arg=VERSION={{.Version}}"
34 | - "--build-arg=BUILD_DATE={{.Date}}"
35 | - "--build-arg=VCS_REF={{.FullCommit}}"
36 | docker_manifests:
37 | - name_template: "hipages/php-fpm_exporter:latest"
38 | image_templates:
39 | - "hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
40 | - "hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64"
41 | - name_template: "hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}"
42 | image_templates:
43 | - "hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
44 | - "hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64"
45 | - name_template: "hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}"
46 | image_templates:
47 | - "hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
48 | - "hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64"
49 | - name_template: "hipages/php-fpm_exporter:{{ .Major }}"
50 | image_templates:
51 | - "hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
52 | - "hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64"
53 | - name_template: "ghcr.io/hipages/php-fpm_exporter:latest"
54 | image_templates:
55 | - "ghcr.io/hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
56 | - "ghcr.io/hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64"
57 | - name_template: "ghcr.io/hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}"
58 | image_templates:
59 | - "ghcr.io/hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
60 | - "ghcr.io/hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64"
61 | - name_template: "ghcr.io/hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}"
62 | image_templates:
63 | - "ghcr.io/hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
64 | - "ghcr.io/hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64"
65 | - name_template: "ghcr.io/hipages/php-fpm_exporter:{{ .Major }}"
66 | image_templates:
67 | - "ghcr.io/hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
68 | - "ghcr.io/hipages/php-fpm_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64"
69 |
70 | changelog:
71 | filters:
72 | exclude:
73 | - '^docs:'
74 |
75 | archives:
76 | - id: default
77 | format: binary
78 | - id: targz
79 | format: tar.gz
80 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | repos:
2 | - repo: https://github.com/pre-commit/pre-commit-hooks
3 | rev: v3.3.0
4 | hooks:
5 | - id: trailing-whitespace
6 | - id: check-added-large-files
7 | - id: check-json
8 | - id: pretty-format-json
9 | args: ['--autofix']
10 | - id: check-merge-conflict
11 | - id: check-symlinks
12 | - id: check-yaml
13 | - id: detect-private-key
14 | - id: check-merge-conflict
15 | - id: check-executables-have-shebangs
16 | - id: end-of-file-fixer
17 | - id: mixed-line-ending
18 | - repo: https://github.com/golangci/golangci-lint
19 | rev: v1.32.2
20 | hooks:
21 | - id: golangci-lint
22 |
--------------------------------------------------------------------------------
/.releaserc:
--------------------------------------------------------------------------------
1 | ---
2 | repositoryUrl: https://github.com/hipages/php-fpm_exporter
3 | verifyConditions: ['@semantic-release/github']
4 | prepare: []
5 | publish: ['@semantic-release/github']
6 | success: ['@semantic-release/github']
7 | fail: ['@semantic-release/github']
8 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at devops@hipages.com.au. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM alpine:3.21.2
2 |
3 | ARG BUILD_DATE
4 | ARG VCS_REF
5 | ARG VERSION
6 |
7 | COPY php-fpm_exporter /
8 |
9 | EXPOSE 9253
10 | ENTRYPOINT [ "/php-fpm_exporter", "server" ]
11 |
12 | LABEL org.label-schema.build-date=$BUILD_DATE \
13 | org.label-schema.name="php-fpm_exporter" \
14 | org.label-schema.description="A prometheus exporter for PHP-FPM." \
15 | org.label-schema.url="https://hipages.com.au/" \
16 | org.label-schema.vcs-ref=$VCS_REF \
17 | org.label-schema.vcs-url="https://github.com/hipages/php-fpm_exporter" \
18 | org.label-schema.vendor="hipages" \
19 | org.label-schema.version=$VERSION \
20 | org.label-schema.schema-version="1.0" \
21 | org.label-schema.docker.cmd="docker run -it --rm -e PHP_FPM_SCRAPE_URI=\"tcp://127.0.0.1:9000/status\" hipages/php-fpm_exporter"
22 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: test
2 |
3 | .DEFAULT_GOAL := help
4 | help: ## List targets & descriptions
5 | @cat Makefile* | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
6 |
7 | deps: ## Get dependencies
8 | go get -d -v ./...
9 |
10 | test: ## Run tests
11 | go test -short ./...
12 |
13 | test-coverage: ## Create a code coverage report
14 | mkdir -p .cover
15 | go test -coverprofile .cover/cover.out ./...
16 |
17 | test-coverage-html: ## Create a code coverage report in HTML
18 | mkdir -p .cover
19 | go test -coverprofile .cover/cover.out ./...
20 | go tool cover -html .cover/cover.out
21 |
22 | test-e2e:
23 | bats test/e2e.bats
24 |
25 | lint: ## Run linters
26 | golangci-lint run
27 |
28 | fmt: ## Fix formatting issues
29 | goimports -w .
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # php-fpm_exporter
2 |
3 | 
4 | [](https://goreportcard.com/report/github.com/hipages/php-fpm_exporter)
5 | [](https://godoc.org/github.com/hipages/php-fpm_exporter)
6 | [](https://sonarcloud.io/dashboard?id=hipages_php-fpm_exporter)
7 | [](https://hub.docker.com/r/hipages/php-fpm_exporter/)
8 | [](http://isitmaintained.com/project/hipages/php-fpm_exporter "Average time to resolve an issue")
9 | [](http://isitmaintained.com/project/hipages/php-fpm_exporter "Percentage of issues still open")
10 | [](https://www.codetriage.com/hipages/php-fpm_exporter)
11 | [](#contributors)
12 |
13 | A [prometheus](https://prometheus.io/) exporter for PHP-FPM.
14 | The exporter connects directly to PHP-FPM and exports the metrics via HTTP.
15 |
16 | A webserver such as NGINX or Apache is **NOT** needed!
17 |
18 | ## Table of Contents
19 |
20 |
21 |
22 | - [Features](#features)
23 | - [Usage](#usage)
24 | * [Options and defaults](#options-and-defaults)
25 | * [Why `--phpfpm.fix-process-count`?](#why---phpfpmfix-process-count)
26 | * [CLI Examples](#cli-examples)
27 | * [Docker Examples](#docker-examples)
28 | * [Kubernetes Example](#kubernetes-example)
29 | - [Metrics collected](#metrics-collected)
30 | - [Grafana Dasbhoard for Kubernetes](#grafana-dasbhoard-for-kubernetes)
31 | - [FAQ](#faq)
32 | - [Development](#development)
33 | * [E2E Tests](#e2e-tests)
34 | - [Contributing](#contributing)
35 | - [Contributors](#contributors)
36 | - [Alternatives](#alternatives)
37 |
38 |
39 |
40 | ## Features
41 |
42 | * Export single or multiple pools
43 | * Export to CLI as text or JSON
44 | * Connects directly to PHP-FPM via TCP or Socket
45 | * Maps environment variables to CLI options
46 | * Fix for PHP-FPM metrics oddities
47 | * [Grafana Dashboard](https://grafana.com/dashboards/4912) for Kubernetes
48 |
49 | ## Usage
50 |
51 | `php-fpm_exporter` is released as [binary](https://github.com/hipages/php-fpm_exporter/releases) and [docker](https://hub.docker.com/r/hipages/php-fpm_exporter/) image.
52 | It uses sensible defaults which usually avoids the need to use command parameters or environment variables.
53 |
54 | `php-fpm_exporter` supports 2 commands, `get` and `server`.
55 | The `get` command allows to retrieve information from PHP-FPM without running as a server and exposing an endpoint.
56 | The `server` command runs the server required for prometheus to retrieve the statistics.
57 |
58 | ### Options and defaults
59 |
60 | | Option | Description | Environment variable | Default value |
61 | |------------------------|-------------------------------------------------------|------------------------------|-----------------|
62 | | `--web.listen-address` | Address on which to expose metrics and web interface. | `PHP_FPM_WEB_LISTEN_ADDRESS` | [`:9253`](https://github.com/prometheus/prometheus/wiki/Default-port-allocations) |
63 | | `--web.telemetry-path` | Path under which to expose metrics. | `PHP_FPM_WEB_TELEMETRY_PATH` | `/metrics` |
64 | | `--phpfpm.scrape-uri` | FastCGI address, e.g. unix:///tmp/php.sock;/status or tcp://127.0.0.1:9000/status | `PHP_FPM_SCRAPE_URI` | `tcp://127.0.0.1:9000/status` |
65 | | `--phpfpm.fix-process-count` | Enable to calculate process numbers via php-fpm_exporter since PHP-FPM sporadically reports wrong active/idle/total process numbers. | `PHP_FPM_FIX_PROCESS_COUNT`| `false` |
66 | | `--log.level` | Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal] (default "error") | `PHP_FPM_LOG_LEVEL` | info |
67 |
68 | ### Why `--phpfpm.fix-process-count`?
69 |
70 | `php-fpm_exporter` implements an option to "fix" the reported metrics based on the provided processes list by PHP-FPM.
71 |
72 | We have seen PHP-FPM provide metrics (e.g. active processes) which don't match reality.
73 | Specially `active processes` being larger than `max_children` and the actual number of running processes on the host.
74 | Looking briefly at the source code of PHP-FPM it appears a scoreboard is being kept and the values are increased/decreased once an action is executed.
75 | The metric `active processes` is also an accumulation of multiple states (e.g. Reading headers, Getting request information, Running).
76 | Which shouldn't matter and `active processes` should still be equal or lower to `max_children`.
77 |
78 | `--phpfpm.fix-process-count` will emulate PHP-FPMs implementation including the accumulation of multiple states.
79 |
80 | If you like to have a more granular reporting please use `phpfpm_process_state`.
81 |
82 | * https://bugs.php.net/bug.php?id=76003
83 | * https://stackoverflow.com/questions/48961556/can-active-processes-be-larger-than-max-children-for-php-fpm
84 |
85 | ### CLI Examples
86 |
87 | * Retrieve information from PHP-FPM running on `127.0.0.1:9000` with status endpoint being `/status`
88 | ```
89 | php-fpm_exporter get
90 | ```
91 |
92 | * Retrieve information from PHP-FPM running on `127.0.0.1:9000` and `127.0.0.1:9001`
93 | ```
94 | php-fpm_exporter get --phpfpm.scrape-uri tcp://127.0.0.1:9000/status,tcp://127.0.0.1:9001/status
95 | ```
96 |
97 | * Run as server with 2 pools:
98 | ```
99 | php-fpm_exporter server --phpfpm.scrape-uri tcp://127.0.0.1:9000/status,tcp://127.0.0.1:9001/status
100 | ```
101 |
102 | * Run as server and enable process count fix via environment variable:
103 | ```
104 | PHP_FPM_FIX_PROCESS_COUNT=1 go run main.go server --web.listen-address ":12345" --log.level=debug
105 | ```
106 |
107 | ### Docker Examples
108 |
109 | * Run docker manually
110 | ```
111 | docker pull hipages/php-fpm_exporter
112 | docker run -it --rm -e PHP_FPM_SCRAPE_URI="tcp://127.0.0.1:9000/status,tcp://127.0.0.1:9001/status" hipages/php-fpm_exporter
113 | ```
114 |
115 | * Run the docker-compose example
116 | ```
117 | git clone git@github.com:hipages/php-fpm_exporter.git
118 | cd php-fpm_exporter/test
119 | docker-compose -p php-fpm_exporter up
120 | ```
121 | You can now access the following links:
122 |
123 | * Prometheus: http://127.0.0.1:9090/
124 | * php-fpm_exporter metrics: http://127.0.0.1:9253/metrics
125 |
126 | [](https://asciinema.org/a/1msR8nqAsFdHzROosUb7PiHvf)
127 |
128 | ### Kubernetes Example
129 |
130 | TBD
131 |
132 | ## Metrics collected
133 |
134 | ```
135 | # HELP phpfpm_accepted_connections The number of requests accepted by the pool.
136 | # TYPE phpfpm_accepted_connections counter
137 | # HELP phpfpm_active_processes The number of active processes.
138 | # TYPE phpfpm_active_processes gauge
139 | # HELP phpfpm_idle_processes The number of idle processes.
140 | # TYPE phpfpm_idle_processes gauge
141 | # HELP phpfpm_listen_queue The number of requests in the queue of pending connections.
142 | # TYPE phpfpm_listen_queue gauge
143 | # HELP phpfpm_listen_queue_length The size of the socket queue of pending connections.
144 | # TYPE phpfpm_listen_queue_length gauge
145 | # HELP phpfpm_max_active_processes The maximum number of active processes since FPM has started.
146 | # TYPE phpfpm_max_active_processes counter
147 | # HELP phpfpm_max_children_reached The number of times, the process limit has been reached, when pm tries to start more children (works only for pm 'dynamic' and 'ondemand').
148 | # TYPE phpfpm_max_children_reached counter
149 | # HELP phpfpm_max_listen_queue The maximum number of requests in the queue of pending connections since FPM has started.
150 | # TYPE phpfpm_max_listen_queue counter
151 | # HELP phpfpm_process_last_request_cpu The %cpu the last request consumed.
152 | # TYPE phpfpm_process_last_request_cpu gauge
153 | # HELP phpfpm_process_last_request_memory The max amount of memory the last request consumed.
154 | # TYPE phpfpm_process_last_request_memory gauge
155 | # HELP phpfpm_process_request_duration The duration in microseconds of the requests.
156 | # TYPE phpfpm_process_request_duration gauge
157 | # HELP phpfpm_process_requests The number of requests the process has served.
158 | # TYPE phpfpm_process_requests counter
159 | # HELP phpfpm_process_state The state of the process (Idle, Running, ...).
160 | # TYPE phpfpm_process_state gauge
161 | # HELP phpfpm_scrape_failures The number of failures scraping from PHP-FPM.
162 | # TYPE phpfpm_scrape_failures counter
163 | # HELP phpfpm_slow_requests The number of requests that exceeded your 'request_slowlog_timeout' value.
164 | # TYPE phpfpm_slow_requests counter
165 | # HELP phpfpm_start_since The number of seconds since FPM has started.
166 | # TYPE phpfpm_start_since counter
167 | # HELP phpfpm_total_processes The number of idle + active processes.
168 | # TYPE phpfpm_total_processes gauge
169 | # HELP phpfpm_up Could PHP-FPM be reached?
170 | # TYPE phpfpm_up gauge
171 | ```
172 |
173 | ## Grafana Dasbhoard for Kubernetes
174 |
175 | The Grafana dashboard can be found [here](https://grafana.com/dashboards/4912).
176 | There is also a more generic version [here](./grafana/kubernetes-php-fpm.json).
177 |
178 |
179 |
180 | ## FAQ
181 |
182 | * **How to update "Metrics collected"?**
183 |
184 | Copy&paste the output from:
185 | ```
186 | curl http://127.0.0.1:12345/metrics | grep phpfpm | grep "#"
187 | ```
188 |
189 | ## Development
190 |
191 | ### E2E Tests
192 |
193 | The E2E tests are based on docker-compose and bats-core. Install the required components, e.g. via brew on MacOS:
194 |
195 | ```bash
196 | brew tap kaos/shell
197 | brew install docker-compose bats-core kaos/shell/bats-assert kaos/shell/bats-support
198 | ```
199 |
200 | After the components are installed run the E2E tests:
201 |
202 | ```bash
203 | make test-e2e
204 | ```
205 |
206 | ## Contributing
207 |
208 | Contributions are greatly appreciated.
209 | The maintainers actively manage the issues list, and try to highlight issues suitable for newcomers.
210 | The project follows the typical GitHub pull request model.
211 | See " [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) " for more details.
212 | Before starting any work, please either comment on an existing issue, or file a new one.
213 |
214 | ## Contributors
215 |
216 | Thanks goes to these wonderful people ([emoji key](https://github.com/all-contributors/all-contributors#emoji-key)):
217 |
218 |
219 |
220 |
221 |
238 |
239 |
240 |
241 |
242 |
243 |
244 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
245 |
246 | ## Stargazers over time
247 |
248 | [](https://starchart.cc/hipages/php-fpm_exporter)
249 |
250 | ## Alternatives
251 |
252 | * [bakins/php-fpm-exporter](https://github.com/bakins/php-fpm-exporter)
253 | * [peakgames/php-fpm-prometheus](https://github.com/peakgames/php-fpm-prometheus)
254 | * [craigmj/phpfpm_exporter](https://github.com/craigmj/phpfpm_exporter)
255 |
--------------------------------------------------------------------------------
/cmd/get.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2018 Enrico Stahn
2 | // Licensed under the Apache License, Version 2.0 (the "License");
3 | // you may not use this file except in compliance with the License.
4 | // You may obtain a copy of the License at
5 | //
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package cmd
15 |
16 | import (
17 | "encoding/json"
18 | "fmt"
19 | "time"
20 |
21 | "github.com/davecgh/go-spew/spew"
22 | "github.com/gosuri/uitable"
23 | "github.com/hipages/php-fpm_exporter/phpfpm"
24 | "github.com/spf13/cobra"
25 | )
26 |
27 | // Configuration variables
28 | var (
29 | output string
30 | )
31 |
32 | // getCmd represents the get command
33 | var getCmd = &cobra.Command{
34 | Use: "get",
35 | Short: "Returns metrics without running as a server",
36 | Long: `"get" fetches metrics from php-fpm. Multiple addresses can be specified as follows:
37 |
38 | * php-fpm_exporter get --phpfpm.scrape-uri 127.0.0.1:9000 --phpfpm.scrape-uri 127.0.0.1:9001 [...]
39 | * php-fpm_exporter get --phpfpm.scrape-uri 127.0.0.1:9000,127.0.0.1:9001,[...]
40 | `,
41 | Run: func(cmd *cobra.Command, args []string) {
42 | pm := phpfpm.PoolManager{}
43 |
44 | for _, uri := range scrapeURIs {
45 | pm.Add(uri)
46 | }
47 |
48 | if err := pm.Update(); err != nil {
49 | log.Fatal("Could not update pool.", err)
50 | }
51 |
52 | switch output {
53 | case "json":
54 | content, err := json.Marshal(pm)
55 | if err != nil {
56 | log.Fatal("Cannot encode to JSON ", err)
57 | }
58 | fmt.Print(string(content))
59 | case "text":
60 | table := uitable.New()
61 | table.MaxColWidth = 80
62 | table.Wrap = true
63 |
64 | pools := pm.Pools
65 |
66 | for _, pool := range pools {
67 | table.AddRow("Address:", pool.Address)
68 | table.AddRow("Pool:", pool.Name)
69 | table.AddRow("Start time:", time.Time(pool.StartTime).Format(time.RFC1123Z))
70 | table.AddRow("Start since:", pool.StartSince)
71 | table.AddRow("Accepted connections:", pool.AcceptedConnections)
72 | table.AddRow("Listen Queue:", pool.ListenQueue)
73 | table.AddRow("Max Listen Queue:", pool.MaxListenQueue)
74 | table.AddRow("Listen Queue Length:", pool.ListenQueueLength)
75 | table.AddRow("Idle Processes:", pool.IdleProcesses)
76 | table.AddRow("Active Processes:", pool.ActiveProcesses)
77 | table.AddRow("Total Processes:", pool.TotalProcesses)
78 | table.AddRow("Max active processes:", pool.MaxActiveProcesses)
79 | table.AddRow("Max children reached:", pool.MaxChildrenReached)
80 | table.AddRow("Slow requests:", pool.SlowRequests)
81 | table.AddRow("")
82 | }
83 |
84 | fmt.Println(table)
85 | case "spew":
86 | spew.Dump(pm)
87 | default:
88 | log.Error("Output format not valid.")
89 | }
90 | },
91 | }
92 |
93 | func init() {
94 | RootCmd.AddCommand(getCmd)
95 |
96 | // Here you will define your flags and configuration settings.
97 |
98 | // Cobra supports Persistent Flags which will work for this command
99 | // and all subcommands, e.g.:
100 | // getCmd.PersistentFlags().String("foo", "", "A help for foo")
101 |
102 | // Cobra supports local flags which will only run when this command
103 | // is called directly, e.g.:
104 | getCmd.Flags().StringSliceVar(&scrapeURIs, "phpfpm.scrape-uri", []string{"tcp://127.0.0.1:9000/status"}, "FastCGI address, e.g. unix:///tmp/php.sock;/status or tcp://127.0.0.1:9000/status")
105 | getCmd.Flags().StringVar(&output, "out", "text", "Output format. One of: text, json, spew")
106 | }
107 |
--------------------------------------------------------------------------------
/cmd/root.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2018 Enrico Stahn
2 | // Licensed under the Apache License, Version 2.0 (the "License");
3 | // you may not use this file except in compliance with the License.
4 | // You may obtain a copy of the License at
5 | //
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | // Package cmd contains the CLI commands.
15 | package cmd
16 |
17 | import (
18 | "fmt"
19 | "os"
20 |
21 | "github.com/hipages/php-fpm_exporter/phpfpm"
22 | homedir "github.com/mitchellh/go-homedir"
23 | "github.com/sirupsen/logrus"
24 | "github.com/spf13/cobra"
25 | "github.com/spf13/viper"
26 | )
27 |
28 | var log = logrus.New()
29 |
30 | // Version that is being reported by the CLI
31 | var Version string
32 |
33 | var cfgFile, logLevel string
34 |
35 | // RootCmd represents the base command when called without any subcommands
36 | var RootCmd = &cobra.Command{
37 | Use: "php-fpm_exporter",
38 | Short: "Exports php-fpm metrics for prometheus",
39 | Long: `php-fpm_exporter exports prometheus compatible metrics from php-fpm.`,
40 | // Uncomment the following line if your bare application
41 | // has an action associated with it:
42 | // Run: func(cmd *cobra.Command, args []string) { },
43 | }
44 |
45 | // Execute adds all child commands to the root command sets flags appropriately.
46 | // This is called by main.main(). It only needs to happen once to the rootCmd.
47 | func Execute() {
48 | if err := RootCmd.Execute(); err != nil {
49 | fmt.Println(err)
50 | os.Exit(1)
51 | }
52 | }
53 |
54 | func init() {
55 | cobra.OnInitialize(initConfig, initLogger)
56 |
57 | RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.php-fpm_exporter.yaml)")
58 | RootCmd.PersistentFlags().StringVar(&logLevel, "log.level", "info", "Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]")
59 | }
60 |
61 | // initConfig reads in config file and ENV variables if set.
62 | func initConfig() {
63 | if cfgFile != "" {
64 | // Use config file from the flag.
65 | viper.SetConfigFile(cfgFile)
66 | } else {
67 | // Find home directory.
68 | home, err := homedir.Dir()
69 | if err != nil {
70 | fmt.Println(err)
71 | os.Exit(1)
72 | }
73 |
74 | // Search config in home directory with name ".php-fpm_exporter" (without extension).
75 | viper.AddConfigPath(home)
76 | viper.SetConfigName(".php-fpm_exporter")
77 | }
78 |
79 | viper.AutomaticEnv() // read in environment variables that match
80 |
81 | // If a config file is found, read it in.
82 | if err := viper.ReadInConfig(); err == nil {
83 | fmt.Println("Using config file:", viper.ConfigFileUsed())
84 | }
85 | }
86 |
87 | // initLogger configures the log level
88 | func initLogger() {
89 | phpfpm.SetLogger(log)
90 |
91 | if value := os.Getenv("PHP_FPM_LOG_LEVEL"); value != "" {
92 | logLevel = value
93 | }
94 |
95 | lvl, err := logrus.ParseLevel(logLevel)
96 | if err != nil {
97 | lvl = logrus.InfoLevel
98 | log.Fatalf("Could not set log level to '%v'.", logLevel)
99 | }
100 |
101 | log.SetLevel(lvl)
102 | }
103 |
104 | func mapEnvVars(envs map[string]string, cmd *cobra.Command) {
105 | for env, flag := range envs {
106 | flag := cmd.Flags().Lookup(flag)
107 | flag.Usage = fmt.Sprintf("%v [env %v]", flag.Usage, env)
108 | if value := os.Getenv(env); value != "" {
109 | if err := flag.Value.Set(value); err != nil {
110 | log.Error(err)
111 | }
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/cmd/server.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2018 Enrico Stahn
2 | // Licensed under the Apache License, Version 2.0 (the "License");
3 | // you may not use this file except in compliance with the License.
4 | // You may obtain a copy of the License at
5 | //
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package cmd
15 |
16 | import (
17 | "context"
18 | "net/http"
19 | "os"
20 | "os/signal"
21 | "syscall"
22 | "time"
23 |
24 | "github.com/hipages/php-fpm_exporter/phpfpm"
25 | "github.com/prometheus/client_golang/prometheus"
26 | "github.com/prometheus/client_golang/prometheus/promhttp"
27 | "github.com/spf13/cobra"
28 | )
29 |
30 | // Configuration variables
31 | var (
32 | listeningAddress string
33 | metricsEndpoint string
34 | scrapeURIs []string
35 | fixProcessCount bool
36 | )
37 |
38 | // serverCmd represents the server command
39 | var serverCmd = &cobra.Command{
40 | Use: "server",
41 | Short: "A brief description of your command",
42 | Long: `A longer description that spans multiple lines and likely contains examples
43 | and usage of using your command. For example:
44 |
45 | Cobra is a CLI library for Go that empowers applications.
46 | This application is a tool to generate the needed files
47 | to quickly create a Cobra application.`,
48 | Run: func(cmd *cobra.Command, args []string) {
49 | log.Infof("Starting server on %v with path %v", listeningAddress, metricsEndpoint)
50 |
51 | pm := phpfpm.PoolManager{}
52 |
53 | for _, uri := range scrapeURIs {
54 | pm.Add(uri)
55 | }
56 |
57 | exporter := phpfpm.NewExporter(pm)
58 |
59 | if fixProcessCount {
60 | log.Info("Idle/Active/Total Processes will be calculated by php-fpm_exporter.")
61 | exporter.CountProcessState = true
62 | }
63 |
64 | prometheus.MustRegister(exporter)
65 |
66 | srv := &http.Server{
67 | Addr: listeningAddress,
68 | // Good practice to set timeouts to avoid Slowloris attacks.
69 | WriteTimeout: time.Second * 15,
70 | ReadTimeout: time.Second * 15,
71 | IdleTimeout: time.Second * 60,
72 | }
73 |
74 | http.Handle(metricsEndpoint, promhttp.Handler())
75 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
76 | _, err := w.Write([]byte(`
77 | php-fpm_exporter
78 |
79 | php-fpm_exporter
80 | Metrics
81 |
82 | `))
83 |
84 | if err != nil {
85 | log.Error()
86 | }
87 | })
88 |
89 | // Run our server in a goroutine so that it doesn't block.
90 | go func() {
91 | if err := srv.ListenAndServe(); err != nil {
92 | log.Error(err)
93 | }
94 | }()
95 |
96 | c := make(chan os.Signal, 1)
97 | // We'll accept graceful shutdowns when quit via SIGINT (Ctrl+C) or SIGTERM
98 | // SIGKILL, SIGQUIT will not be caught.
99 | signal.Notify(c, os.Interrupt, syscall.SIGTERM)
100 |
101 | // Block until we receive our signal.
102 | <-c
103 |
104 | // Create a deadline to wait for.
105 | wait := time.Second * 10
106 | ctx, cancel := context.WithTimeout(context.Background(), wait)
107 | defer cancel()
108 | // Doesn't block if no connections, but will otherwise wait
109 | // until the timeout deadline.
110 | if err := srv.Shutdown(ctx); err != nil {
111 | log.Fatal("Error during shutdown", err)
112 | }
113 | // Optionally, you could run srv.Shutdown in a goroutine and block on
114 | // <-ctx.Done() if your application should wait for other services
115 | // to finalize based on context cancellation.
116 | log.Info("Shutting down")
117 | os.Exit(0)
118 | },
119 | }
120 |
121 | func init() {
122 | RootCmd.AddCommand(serverCmd)
123 |
124 | serverCmd.Flags().StringVar(&listeningAddress, "web.listen-address", ":9253", "Address on which to expose metrics and web interface.")
125 | serverCmd.Flags().StringVar(&metricsEndpoint, "web.telemetry-path", "/metrics", "Path under which to expose metrics.")
126 | serverCmd.Flags().StringSliceVar(&scrapeURIs, "phpfpm.scrape-uri", []string{"tcp://127.0.0.1:9000/status"}, "FastCGI address, e.g. unix:///tmp/php.sock;/status or tcp://127.0.0.1:9000/status")
127 | serverCmd.Flags().BoolVar(&fixProcessCount, "phpfpm.fix-process-count", false, "Enable to calculate process numbers via php-fpm_exporter since PHP-FPM sporadically reports wrong active/idle/total process numbers.")
128 |
129 | // Workaround since vipers BindEnv is currently not working as expected (see https://github.com/spf13/viper/issues/461)
130 |
131 | envs := map[string]string{
132 | "PHP_FPM_WEB_LISTEN_ADDRESS": "web.listen-address",
133 | "PHP_FPM_WEB_TELEMETRY_PATH": "web.telemetry-path",
134 | "PHP_FPM_SCRAPE_URI": "phpfpm.scrape-uri",
135 | "PHP_FPM_FIX_PROCESS_COUNT": "phpfpm.fix-process-count",
136 | }
137 |
138 | mapEnvVars(envs, serverCmd)
139 | }
140 |
--------------------------------------------------------------------------------
/cmd/version.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2018 Enrico Stahn
2 | // Licensed under the Apache License, Version 2.0 (the "License");
3 | // you may not use this file except in compliance with the License.
4 | // You may obtain a copy of the License at
5 | //
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package cmd
15 |
16 | import (
17 | "fmt"
18 |
19 | "github.com/spf13/cobra"
20 | )
21 |
22 | // versionCmd represents the version command
23 | var versionCmd = &cobra.Command{
24 | Use: "version",
25 | Short: "Print the version number of php-fpm_exporter",
26 | Long: `All software has versions. This is php-fpm_exporter's'`,
27 | Run: func(cmd *cobra.Command, args []string) {
28 | fmt.Printf("php-fpm_exporter %v\n", Version)
29 | },
30 | }
31 |
32 | func init() {
33 | RootCmd.AddCommand(versionCmd)
34 | }
35 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/hipages/php-fpm_exporter
2 |
3 | require (
4 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
5 | github.com/gosuri/uitable v0.0.4
6 | github.com/mattn/go-runewidth v0.0.8 // indirect
7 | github.com/mitchellh/go-homedir v1.1.0
8 | github.com/prometheus/client_golang v1.20.5
9 | github.com/sirupsen/logrus v1.9.3
10 | github.com/spf13/cobra v1.9.1
11 | github.com/spf13/viper v1.19.0
12 | github.com/stretchr/testify v1.10.0
13 | github.com/tomasen/fcgi_client v0.0.0-20180423082037-2bb3d819fd19
14 | )
15 |
16 | go 1.13
17 |
--------------------------------------------------------------------------------
/grafana/kubernetes-php-fpm.json:
--------------------------------------------------------------------------------
1 | {
2 | "__inputs": [
3 | {
4 | "name": "DS_PROMETHEUS",
5 | "label": "prometheus",
6 | "description": "Prometheus",
7 | "type": "datasource",
8 | "pluginId": "prometheus",
9 | "pluginName": "Prometheus"
10 | }
11 | ],
12 | "__requires": [
13 | {
14 | "type": "grafana",
15 | "id": "grafana",
16 | "name": "Grafana",
17 | "version": "v4.4.3"
18 | },
19 | {
20 | "type": "panel",
21 | "id": "graph",
22 | "name": "Graph",
23 | "version": ""
24 | },
25 | {
26 | "type": "datasource",
27 | "id": "prometheus",
28 | "name": "prometheus",
29 | "version": "1.0.0"
30 | },
31 | {
32 | "type": "panel",
33 | "id": "singlestat",
34 | "name": "Singlestat",
35 | "version": ""
36 | }
37 | ],
38 | "annotations": {
39 | "list": []
40 | },
41 | "editable": true,
42 | "graphTooltip": 0,
43 | "hideControls": false,
44 | "id": null,
45 | "links": [],
46 | "refresh": false,
47 | "rows": [
48 | {
49 | "collapse": false,
50 | "height": 145,
51 | "panels": [
52 | {
53 | "cacheTimeout": null,
54 | "colorBackground": false,
55 | "colorValue": false,
56 | "colors": ["rgba(50, 172, 45, 0.97)", "rgba(237, 129, 40, 0.89)", "rgba(245, 54, 54, 0.9)"],
57 | "datasource": "prometheus",
58 | "description": "Utilisation of processes based on active/inactive processes",
59 | "format": "percent",
60 | "gauge": {
61 | "maxValue": 100,
62 | "minValue": 0,
63 | "show": true,
64 | "thresholdLabels": false,
65 | "thresholdMarkers": true
66 | },
67 | "id": 2,
68 | "interval": null,
69 | "links": [],
70 | "mappingType": 1,
71 | "mappingTypes": [
72 | {
73 | "name": "value to text",
74 | "value": 1
75 | },
76 | {
77 | "name": "range to text",
78 | "value": 2
79 | }
80 | ],
81 | "maxDataPoints": 100,
82 | "nullPointMode": "connected",
83 | "nullText": null,
84 | "postfix": "",
85 | "postfixFontSize": "50%",
86 | "prefix": "",
87 | "prefixFontSize": "50%",
88 | "rangeMaps": [
89 | {
90 | "from": "null",
91 | "text": "N/A",
92 | "to": "null"
93 | }
94 | ],
95 | "span": 2,
96 | "sparkline": {
97 | "fillColor": "rgba(31, 118, 189, 0.18)",
98 | "full": false,
99 | "lineColor": "rgb(31, 120, 193)",
100 | "show": false
101 | },
102 | "tableColumn": "Value",
103 | "targets": [
104 | {
105 | "alias": "",
106 | "dsType": "influxdb",
107 | "expr": "avg((sum(phpfpm_active_processes{namespace=\"$namespace\"}) by (kubernetes_pod_name) *100) / sum(phpfpm_total_processes{namespace=\"$namespace\"}) by (kubernetes_pod_name))",
108 | "format": "time_series",
109 | "groupBy": [
110 | {
111 | "params": ["$__interval"],
112 | "type": "time"
113 | },
114 | {
115 | "params": ["null"],
116 | "type": "fill"
117 | }
118 | ],
119 | "interval": "",
120 | "intervalFactor": 1,
121 | "orderByTime": "ASC",
122 | "policy": "default",
123 | "rawSql": "SELECT\n UNIX_TIMESTAMP() as time_sec,\n as value,\n as metric\nFROM \nWHERE $__timeFilter(time_column)\nORDER BY ASC\n",
124 | "refId": "A",
125 | "resultFormat": "time_series",
126 | "select": [
127 | [
128 | {
129 | "params": ["value"],
130 | "type": "field"
131 | },
132 | {
133 | "params": [],
134 | "type": "mean"
135 | }
136 | ]
137 | ],
138 | "step": 1,
139 | "tags": []
140 | }
141 | ],
142 | "thresholds": "70,90",
143 | "timeFrom": "1m",
144 | "title": "Total Process Utilisation",
145 | "type": "singlestat",
146 | "valueFontSize": "80%",
147 | "valueMaps": [
148 | {
149 | "op": "=",
150 | "text": "N/A",
151 | "value": "null"
152 | }
153 | ],
154 | "valueName": "avg"
155 | },
156 | {
157 | "cacheTimeout": null,
158 | "colorBackground": false,
159 | "colorValue": false,
160 | "colors": ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"],
161 | "datasource": "prometheus",
162 | "decimals": null,
163 | "description": "How many times was the maximum amount of children reached?",
164 | "format": "short",
165 | "gauge": {
166 | "maxValue": 100,
167 | "minValue": 0,
168 | "show": false,
169 | "thresholdLabels": false,
170 | "thresholdMarkers": true
171 | },
172 | "id": 7,
173 | "interval": null,
174 | "links": [],
175 | "mappingType": 1,
176 | "mappingTypes": [
177 | {
178 | "name": "value to text",
179 | "value": 1
180 | },
181 | {
182 | "name": "range to text",
183 | "value": 2
184 | }
185 | ],
186 | "maxDataPoints": 100,
187 | "nullPointMode": "connected",
188 | "nullText": null,
189 | "postfix": "",
190 | "postfixFontSize": "50%",
191 | "prefix": "",
192 | "prefixFontSize": "50%",
193 | "rangeMaps": [
194 | {
195 | "from": "null",
196 | "text": "N/A",
197 | "to": "null"
198 | }
199 | ],
200 | "span": 2,
201 | "sparkline": {
202 | "fillColor": "rgba(31, 118, 189, 0.18)",
203 | "full": false,
204 | "lineColor": "rgb(31, 120, 193)",
205 | "show": false
206 | },
207 | "tableColumn": "Value",
208 | "targets": [
209 | {
210 | "dsType": "influxdb",
211 | "expr": "sum(phpfpm_max_children_reached{namespace=\"$namespace\"})",
212 | "format": "table",
213 | "groupBy": [
214 | {
215 | "params": ["$__interval"],
216 | "type": "time"
217 | },
218 | {
219 | "params": ["null"],
220 | "type": "fill"
221 | }
222 | ],
223 | "intervalFactor": 2,
224 | "metric": "php",
225 | "orderByTime": "ASC",
226 | "policy": "default",
227 | "refId": "A",
228 | "resultFormat": "time_series",
229 | "select": [
230 | [
231 | {
232 | "params": ["value"],
233 | "type": "field"
234 | },
235 | {
236 | "params": [],
237 | "type": "mean"
238 | }
239 | ]
240 | ],
241 | "step": 2,
242 | "tags": []
243 | }
244 | ],
245 | "thresholds": "",
246 | "timeFrom": "1m",
247 | "title": "Max Children reached",
248 | "type": "singlestat",
249 | "valueFontSize": "80%",
250 | "valueMaps": [
251 | {
252 | "op": "=",
253 | "text": "N/A",
254 | "value": "null"
255 | }
256 | ],
257 | "valueName": "current"
258 | },
259 | {
260 | "cacheTimeout": null,
261 | "colorBackground": false,
262 | "colorValue": false,
263 | "colors": ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"],
264 | "datasource": "prometheus",
265 | "decimals": null,
266 | "format": "short",
267 | "gauge": {
268 | "maxValue": 100,
269 | "minValue": 0,
270 | "show": false,
271 | "thresholdLabels": false,
272 | "thresholdMarkers": true
273 | },
274 | "id": 1,
275 | "interval": null,
276 | "links": [],
277 | "mappingType": 1,
278 | "mappingTypes": [
279 | {
280 | "name": "value to text",
281 | "value": 1
282 | },
283 | {
284 | "name": "range to text",
285 | "value": 2
286 | }
287 | ],
288 | "maxDataPoints": 100,
289 | "nullPointMode": "connected",
290 | "nullText": null,
291 | "postfix": "",
292 | "postfixFontSize": "50%",
293 | "prefix": "",
294 | "prefixFontSize": "50%",
295 | "rangeMaps": [
296 | {
297 | "from": "null",
298 | "text": "N/A",
299 | "to": "null"
300 | }
301 | ],
302 | "span": 2,
303 | "sparkline": {
304 | "fillColor": "rgba(31, 118, 189, 0.18)",
305 | "full": false,
306 | "lineColor": "rgb(31, 120, 193)",
307 | "show": false
308 | },
309 | "tableColumn": "Value",
310 | "targets": [
311 | {
312 | "dsType": "influxdb",
313 | "expr": "delta(phpfpm_accepted_connections{namespace=\"$namespace\"}[2m])",
314 | "format": "time_series",
315 | "groupBy": [
316 | {
317 | "params": ["$__interval"],
318 | "type": "time"
319 | },
320 | {
321 | "params": ["null"],
322 | "type": "fill"
323 | }
324 | ],
325 | "intervalFactor": 2,
326 | "orderByTime": "ASC",
327 | "policy": "default",
328 | "refId": "A",
329 | "resultFormat": "time_series",
330 | "select": [
331 | [
332 | {
333 | "params": ["value"],
334 | "type": "field"
335 | },
336 | {
337 | "params": [],
338 | "type": "mean"
339 | }
340 | ]
341 | ],
342 | "step": 2,
343 | "tags": []
344 | }
345 | ],
346 | "thresholds": "",
347 | "timeFrom": "1m",
348 | "title": "Accepted connections (rpm)",
349 | "type": "singlestat",
350 | "valueFontSize": "80%",
351 | "valueMaps": [
352 | {
353 | "op": "=",
354 | "text": "N/A",
355 | "value": "null"
356 | }
357 | ],
358 | "valueName": "current"
359 | },
360 | {
361 | "cacheTimeout": null,
362 | "colorBackground": false,
363 | "colorValue": false,
364 | "colors": ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"],
365 | "datasource": "prometheus",
366 | "decimals": null,
367 | "format": "short",
368 | "gauge": {
369 | "maxValue": 100,
370 | "minValue": 0,
371 | "show": false,
372 | "thresholdLabels": false,
373 | "thresholdMarkers": true
374 | },
375 | "id": 3,
376 | "interval": null,
377 | "links": [],
378 | "mappingType": 1,
379 | "mappingTypes": [
380 | {
381 | "name": "value to text",
382 | "value": 1
383 | },
384 | {
385 | "name": "range to text",
386 | "value": 2
387 | }
388 | ],
389 | "maxDataPoints": 100,
390 | "nullPointMode": "connected",
391 | "nullText": null,
392 | "postfix": "",
393 | "postfixFontSize": "50%",
394 | "prefix": "",
395 | "prefixFontSize": "50%",
396 | "rangeMaps": [
397 | {
398 | "from": "null",
399 | "text": "N/A",
400 | "to": "null"
401 | }
402 | ],
403 | "span": 2,
404 | "sparkline": {
405 | "fillColor": "rgba(31, 118, 189, 0.18)",
406 | "full": false,
407 | "lineColor": "rgb(31, 120, 193)",
408 | "show": false
409 | },
410 | "tableColumn": "Value",
411 | "targets": [
412 | {
413 | "dsType": "influxdb",
414 | "expr": "count(phpfpm_up{namespace=\"$namespace\"} > 0)",
415 | "format": "table",
416 | "groupBy": [
417 | {
418 | "params": ["$__interval"],
419 | "type": "time"
420 | },
421 | {
422 | "params": ["null"],
423 | "type": "fill"
424 | }
425 | ],
426 | "hide": false,
427 | "intervalFactor": 2,
428 | "orderByTime": "ASC",
429 | "policy": "default",
430 | "refId": "A",
431 | "resultFormat": "time_series",
432 | "select": [
433 | [
434 | {
435 | "params": ["value"],
436 | "type": "field"
437 | },
438 | {
439 | "params": [],
440 | "type": "mean"
441 | }
442 | ]
443 | ],
444 | "step": 2,
445 | "tags": []
446 | }
447 | ],
448 | "thresholds": "",
449 | "timeFrom": "1m",
450 | "title": "# of pods",
451 | "type": "singlestat",
452 | "valueFontSize": "80%",
453 | "valueMaps": [
454 | {
455 | "op": "=",
456 | "text": "N/A",
457 | "value": "null"
458 | }
459 | ],
460 | "valueName": "current"
461 | },
462 | {
463 | "cacheTimeout": null,
464 | "colorBackground": false,
465 | "colorValue": false,
466 | "colors": ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"],
467 | "datasource": "prometheus",
468 | "decimals": null,
469 | "format": "short",
470 | "gauge": {
471 | "maxValue": 100,
472 | "minValue": 0,
473 | "show": false,
474 | "thresholdLabels": false,
475 | "thresholdMarkers": true
476 | },
477 | "id": 8,
478 | "interval": null,
479 | "links": [],
480 | "mappingType": 1,
481 | "mappingTypes": [
482 | {
483 | "name": "value to text",
484 | "value": 1
485 | },
486 | {
487 | "name": "range to text",
488 | "value": 2
489 | }
490 | ],
491 | "maxDataPoints": 100,
492 | "nullPointMode": "connected",
493 | "nullText": null,
494 | "postfix": "",
495 | "postfixFontSize": "50%",
496 | "prefix": "",
497 | "prefixFontSize": "50%",
498 | "rangeMaps": [
499 | {
500 | "from": "null",
501 | "text": "N/A",
502 | "to": "null"
503 | }
504 | ],
505 | "span": 2,
506 | "sparkline": {
507 | "fillColor": "rgba(31, 118, 189, 0.18)",
508 | "full": false,
509 | "lineColor": "rgb(31, 120, 193)",
510 | "show": false
511 | },
512 | "tableColumn": "Value",
513 | "targets": [
514 | {
515 | "dsType": "influxdb",
516 | "expr": "sum(phpfpm_listen_queue{namespace=\"$namespace\"})",
517 | "format": "table",
518 | "groupBy": [
519 | {
520 | "params": ["$__interval"],
521 | "type": "time"
522 | },
523 | {
524 | "params": ["null"],
525 | "type": "fill"
526 | }
527 | ],
528 | "intervalFactor": 2,
529 | "metric": "phpfpm_listen_queue",
530 | "orderByTime": "ASC",
531 | "policy": "default",
532 | "refId": "A",
533 | "resultFormat": "time_series",
534 | "select": [
535 | [
536 | {
537 | "params": ["value"],
538 | "type": "field"
539 | },
540 | {
541 | "params": [],
542 | "type": "mean"
543 | }
544 | ]
545 | ],
546 | "step": 2,
547 | "tags": []
548 | }
549 | ],
550 | "thresholds": "",
551 | "timeFrom": "1m",
552 | "title": "Queued Requests",
553 | "type": "singlestat",
554 | "valueFontSize": "80%",
555 | "valueMaps": [
556 | {
557 | "op": "=",
558 | "text": "N/A",
559 | "value": "null"
560 | }
561 | ],
562 | "valueName": "current"
563 | },
564 | {
565 | "cacheTimeout": null,
566 | "colorBackground": false,
567 | "colorValue": false,
568 | "colors": ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"],
569 | "datasource": "prometheus",
570 | "decimals": null,
571 | "format": "short",
572 | "gauge": {
573 | "maxValue": 100,
574 | "minValue": 0,
575 | "show": false,
576 | "thresholdLabels": false,
577 | "thresholdMarkers": true
578 | },
579 | "id": 9,
580 | "interval": null,
581 | "links": [],
582 | "mappingType": 1,
583 | "mappingTypes": [
584 | {
585 | "name": "value to text",
586 | "value": 1
587 | },
588 | {
589 | "name": "range to text",
590 | "value": 2
591 | }
592 | ],
593 | "maxDataPoints": 100,
594 | "nullPointMode": "connected",
595 | "nullText": null,
596 | "postfix": "",
597 | "postfixFontSize": "50%",
598 | "prefix": "",
599 | "prefixFontSize": "50%",
600 | "rangeMaps": [
601 | {
602 | "from": "null",
603 | "text": "N/A",
604 | "to": "null"
605 | }
606 | ],
607 | "span": 2,
608 | "sparkline": {
609 | "fillColor": "rgba(31, 118, 189, 0.18)",
610 | "full": false,
611 | "lineColor": "rgb(31, 120, 193)",
612 | "show": false
613 | },
614 | "tableColumn": "Value",
615 | "targets": [
616 | {
617 | "dsType": "influxdb",
618 | "expr": "sum(phpfpm_scrape_failures{namespace=\"$namespace\"})",
619 | "format": "table",
620 | "groupBy": [
621 | {
622 | "params": ["$__interval"],
623 | "type": "time"
624 | },
625 | {
626 | "params": ["null"],
627 | "type": "fill"
628 | }
629 | ],
630 | "intervalFactor": 1,
631 | "metric": "phpfpm_scrape_failures",
632 | "orderByTime": "ASC",
633 | "policy": "default",
634 | "refId": "A",
635 | "resultFormat": "time_series",
636 | "select": [
637 | [
638 | {
639 | "params": ["value"],
640 | "type": "field"
641 | },
642 | {
643 | "params": [],
644 | "type": "mean"
645 | }
646 | ]
647 | ],
648 | "step": 1,
649 | "tags": []
650 | }
651 | ],
652 | "thresholds": "",
653 | "timeFrom": "1m",
654 | "title": "Scrape failures",
655 | "type": "singlestat",
656 | "valueFontSize": "80%",
657 | "valueMaps": [
658 | {
659 | "op": "=",
660 | "text": "N/A",
661 | "value": "null"
662 | }
663 | ],
664 | "valueName": "current"
665 | }
666 | ],
667 | "repeat": null,
668 | "repeatIteration": null,
669 | "repeatRowId": null,
670 | "showTitle": false,
671 | "title": "Dashboard Row",
672 | "titleSize": "h6"
673 | },
674 | {
675 | "collapse": false,
676 | "height": 247,
677 | "panels": [
678 | {
679 | "aliasColors": {},
680 | "bars": false,
681 | "dashLength": 10,
682 | "dashes": false,
683 | "datasource": "prometheus",
684 | "fill": 1,
685 | "id": 24,
686 | "legend": {
687 | "alignAsTable": true,
688 | "avg": false,
689 | "current": true,
690 | "hideEmpty": true,
691 | "hideZero": true,
692 | "max": false,
693 | "min": false,
694 | "rightSide": true,
695 | "show": true,
696 | "total": false,
697 | "values": true
698 | },
699 | "lines": true,
700 | "linewidth": 1,
701 | "links": [],
702 | "nullPointMode": "null as zero",
703 | "percentage": false,
704 | "pointradius": 5,
705 | "points": false,
706 | "renderer": "flot",
707 | "seriesOverrides": [],
708 | "spaceLength": 10,
709 | "span": 6,
710 | "stack": false,
711 | "steppedLine": false,
712 | "targets": [
713 | {
714 | "dsType": "influxdb",
715 | "expr": "sum(phpfpm_process_state{namespace=\"$namespace\"}) by (state)",
716 | "format": "time_series",
717 | "groupBy": [
718 | {
719 | "params": ["$__interval"],
720 | "type": "time"
721 | },
722 | {
723 | "params": ["null"],
724 | "type": "fill"
725 | }
726 | ],
727 | "intervalFactor": 1,
728 | "legendFormat": "{{state}}",
729 | "metric": "",
730 | "orderByTime": "ASC",
731 | "policy": "default",
732 | "refId": "A",
733 | "resultFormat": "time_series",
734 | "select": [
735 | [
736 | {
737 | "params": ["value"],
738 | "type": "field"
739 | },
740 | {
741 | "params": [],
742 | "type": "mean"
743 | }
744 | ]
745 | ],
746 | "step": 1,
747 | "tags": []
748 | },
749 | {
750 | "expr": "sum(phpfpm_process_state{namespace=\"$namespace\"})",
751 | "format": "time_series",
752 | "intervalFactor": 2,
753 | "legendFormat": "Total",
754 | "refId": "B",
755 | "step": 2
756 | }
757 | ],
758 | "thresholds": [],
759 | "timeFrom": null,
760 | "timeShift": null,
761 | "title": "# of processes by state",
762 | "tooltip": {
763 | "shared": true,
764 | "sort": 2,
765 | "value_type": "individual"
766 | },
767 | "type": "graph",
768 | "xaxis": {
769 | "buckets": null,
770 | "mode": "time",
771 | "name": null,
772 | "show": true,
773 | "values": []
774 | },
775 | "yaxes": [
776 | {
777 | "format": "none",
778 | "label": "",
779 | "logBase": 1,
780 | "max": null,
781 | "min": null,
782 | "show": true
783 | },
784 | {
785 | "format": "short",
786 | "label": null,
787 | "logBase": 1,
788 | "max": null,
789 | "min": null,
790 | "show": false
791 | }
792 | ]
793 | },
794 | {
795 | "aliasColors": {},
796 | "bars": false,
797 | "dashLength": 10,
798 | "dashes": false,
799 | "datasource": "prometheus",
800 | "fill": 1,
801 | "id": 25,
802 | "legend": {
803 | "alignAsTable": true,
804 | "avg": true,
805 | "current": true,
806 | "hideEmpty": false,
807 | "hideZero": false,
808 | "max": true,
809 | "min": false,
810 | "rightSide": true,
811 | "show": true,
812 | "sort": "max",
813 | "sortDesc": true,
814 | "total": false,
815 | "values": true
816 | },
817 | "lines": true,
818 | "linewidth": 1,
819 | "links": [],
820 | "nullPointMode": "null",
821 | "percentage": false,
822 | "pointradius": 5,
823 | "points": false,
824 | "renderer": "flot",
825 | "seriesOverrides": [],
826 | "spaceLength": 10,
827 | "span": 6,
828 | "stack": false,
829 | "steppedLine": false,
830 | "targets": [
831 | {
832 | "alias": "",
833 | "expr": "sum(phpfpm_process_request_duration{namespace=\"$namespace\"}) by (pid_hash)",
834 | "format": "time_series",
835 | "intervalFactor": 2,
836 | "legendFormat": "{{pid_hash}}",
837 | "rawSql": "SELECT\n UNIX_TIMESTAMP() as time_sec,\n as value,\n as metric\nFROM \nWHERE $__timeFilter(time_column)\nORDER BY ASC\n",
838 | "refId": "A",
839 | "step": 2
840 | }
841 | ],
842 | "thresholds": [],
843 | "timeFrom": null,
844 | "timeShift": null,
845 | "title": "Request Duration by process",
846 | "tooltip": {
847 | "shared": true,
848 | "sort": 2,
849 | "value_type": "individual"
850 | },
851 | "type": "graph",
852 | "xaxis": {
853 | "buckets": null,
854 | "mode": "time",
855 | "name": null,
856 | "show": true,
857 | "values": []
858 | },
859 | "yaxes": [
860 | {
861 | "format": "µs",
862 | "label": null,
863 | "logBase": 1,
864 | "max": null,
865 | "min": null,
866 | "show": true
867 | },
868 | {
869 | "format": "short",
870 | "label": null,
871 | "logBase": 1,
872 | "max": null,
873 | "min": null,
874 | "show": true
875 | }
876 | ]
877 | }
878 | ],
879 | "repeat": null,
880 | "repeatIteration": null,
881 | "repeatRowId": null,
882 | "showTitle": false,
883 | "title": "Dashboard Row",
884 | "titleSize": "h6"
885 | },
886 | {
887 | "collapse": false,
888 | "height": 258,
889 | "panels": [
890 | {
891 | "aliasColors": {},
892 | "bars": false,
893 | "dashLength": 10,
894 | "dashes": false,
895 | "datasource": "prometheus",
896 | "fill": 1,
897 | "id": 10,
898 | "legend": {
899 | "avg": false,
900 | "current": false,
901 | "max": false,
902 | "min": false,
903 | "show": true,
904 | "total": false,
905 | "values": false
906 | },
907 | "lines": true,
908 | "linewidth": 1,
909 | "links": [],
910 | "nullPointMode": "null",
911 | "percentage": false,
912 | "pointradius": 5,
913 | "points": false,
914 | "renderer": "flot",
915 | "seriesOverrides": [],
916 | "spaceLength": 10,
917 | "span": 6,
918 | "stack": false,
919 | "steppedLine": false,
920 | "targets": [
921 | {
922 | "dsType": "influxdb",
923 | "expr": "sum(phpfpm_listen_queue{namespace=\"$namespace\"})",
924 | "format": "time_series",
925 | "groupBy": [
926 | {
927 | "params": ["$__interval"],
928 | "type": "time"
929 | },
930 | {
931 | "params": ["null"],
932 | "type": "fill"
933 | }
934 | ],
935 | "intervalFactor": 2,
936 | "legendFormat": "# of requests",
937 | "metric": "",
938 | "orderByTime": "ASC",
939 | "policy": "default",
940 | "refId": "A",
941 | "resultFormat": "time_series",
942 | "select": [
943 | [
944 | {
945 | "params": ["value"],
946 | "type": "field"
947 | },
948 | {
949 | "params": [],
950 | "type": "mean"
951 | }
952 | ]
953 | ],
954 | "step": 2,
955 | "tags": []
956 | },
957 | {
958 | "expr": "sum(kube_pod_container_status_terminated{pod=~\"$branch-.*\"})",
959 | "format": "time_series",
960 | "hide": true,
961 | "intervalFactor": 2,
962 | "legendFormat": "# of pod terminations",
963 | "refId": "B",
964 | "step": 60
965 | }
966 | ],
967 | "thresholds": [],
968 | "timeFrom": null,
969 | "timeShift": null,
970 | "title": "Queued requests",
971 | "tooltip": {
972 | "shared": true,
973 | "sort": 0,
974 | "value_type": "individual"
975 | },
976 | "type": "graph",
977 | "xaxis": {
978 | "buckets": null,
979 | "mode": "time",
980 | "name": null,
981 | "show": true,
982 | "values": []
983 | },
984 | "yaxes": [
985 | {
986 | "format": "none",
987 | "label": null,
988 | "logBase": 1,
989 | "max": null,
990 | "min": "0",
991 | "show": true
992 | },
993 | {
994 | "format": "short",
995 | "label": null,
996 | "logBase": 1,
997 | "max": null,
998 | "min": null,
999 | "show": false
1000 | }
1001 | ]
1002 | },
1003 | {
1004 | "aliasColors": {},
1005 | "bars": false,
1006 | "dashLength": 10,
1007 | "dashes": false,
1008 | "datasource": "prometheus",
1009 | "fill": 1,
1010 | "id": 14,
1011 | "legend": {
1012 | "alignAsTable": false,
1013 | "avg": false,
1014 | "current": true,
1015 | "max": false,
1016 | "min": false,
1017 | "rightSide": false,
1018 | "show": false,
1019 | "total": false,
1020 | "values": true
1021 | },
1022 | "lines": true,
1023 | "linewidth": 1,
1024 | "links": [],
1025 | "nullPointMode": "null",
1026 | "percentage": false,
1027 | "pointradius": 5,
1028 | "points": false,
1029 | "renderer": "flot",
1030 | "seriesOverrides": [],
1031 | "spaceLength": 10,
1032 | "span": 6,
1033 | "stack": false,
1034 | "steppedLine": false,
1035 | "targets": [
1036 | {
1037 | "alias": "",
1038 | "expr": "sum(phpfpm_process_requests{namespace=\"$namespace\"}) by (pid_hash)",
1039 | "format": "time_series",
1040 | "intervalFactor": 1,
1041 | "legendFormat": "{{pid_hash}}",
1042 | "rawSql": "SELECT\n UNIX_TIMESTAMP() as time_sec,\n as value,\n as metric\nFROM \nWHERE $__timeFilter(time_column)\nORDER BY ASC\n",
1043 | "refId": "A",
1044 | "step": 1
1045 | }
1046 | ],
1047 | "thresholds": [],
1048 | "timeFrom": null,
1049 | "timeShift": null,
1050 | "title": "Requests per process",
1051 | "tooltip": {
1052 | "shared": true,
1053 | "sort": 0,
1054 | "value_type": "individual"
1055 | },
1056 | "type": "graph",
1057 | "xaxis": {
1058 | "buckets": null,
1059 | "mode": "time",
1060 | "name": null,
1061 | "show": true,
1062 | "values": []
1063 | },
1064 | "yaxes": [
1065 | {
1066 | "format": "short",
1067 | "label": null,
1068 | "logBase": 1,
1069 | "max": null,
1070 | "min": null,
1071 | "show": true
1072 | },
1073 | {
1074 | "format": "short",
1075 | "label": null,
1076 | "logBase": 1,
1077 | "max": null,
1078 | "min": null,
1079 | "show": true
1080 | }
1081 | ]
1082 | }
1083 | ],
1084 | "repeat": null,
1085 | "repeatIteration": null,
1086 | "repeatRowId": null,
1087 | "showTitle": false,
1088 | "title": "Dashboard Row",
1089 | "titleSize": "h6"
1090 | },
1091 | {
1092 | "collapse": false,
1093 | "height": 244,
1094 | "panels": [
1095 | {
1096 | "aliasColors": {},
1097 | "bars": false,
1098 | "dashLength": 10,
1099 | "dashes": false,
1100 | "datasource": "prometheus",
1101 | "fill": 1,
1102 | "id": 11,
1103 | "legend": {
1104 | "avg": false,
1105 | "current": false,
1106 | "max": false,
1107 | "min": false,
1108 | "show": true,
1109 | "total": false,
1110 | "values": false
1111 | },
1112 | "lines": true,
1113 | "linewidth": 1,
1114 | "links": [],
1115 | "nullPointMode": "null",
1116 | "percentage": false,
1117 | "pointradius": 5,
1118 | "points": false,
1119 | "renderer": "flot",
1120 | "seriesOverrides": [],
1121 | "spaceLength": 10,
1122 | "span": 6,
1123 | "stack": false,
1124 | "steppedLine": false,
1125 | "targets": [
1126 | {
1127 | "dsType": "influxdb",
1128 | "expr": "sum(phpfpm_active_processes{namespace=\"$namespace\"})",
1129 | "format": "time_series",
1130 | "groupBy": [
1131 | {
1132 | "params": ["$__interval"],
1133 | "type": "time"
1134 | },
1135 | {
1136 | "params": ["null"],
1137 | "type": "fill"
1138 | }
1139 | ],
1140 | "intervalFactor": 1,
1141 | "legendFormat": "# of active processes",
1142 | "metric": "phpfpm_active_processes",
1143 | "orderByTime": "ASC",
1144 | "policy": "default",
1145 | "refId": "A",
1146 | "resultFormat": "time_series",
1147 | "select": [
1148 | [
1149 | {
1150 | "params": ["value"],
1151 | "type": "field"
1152 | },
1153 | {
1154 | "params": [],
1155 | "type": "mean"
1156 | }
1157 | ]
1158 | ],
1159 | "step": 1,
1160 | "tags": []
1161 | },
1162 | {
1163 | "expr": "sum(phpfpm_idle_processes{namespace=\"$namespace\"})",
1164 | "format": "time_series",
1165 | "intervalFactor": 1,
1166 | "legendFormat": "# of idle processes",
1167 | "metric": "phpfpm_idle_processes",
1168 | "refId": "B",
1169 | "step": 1
1170 | },
1171 | {
1172 | "expr": "sum(phpfpm_total_processes{namespace=\"$namespace\"})",
1173 | "format": "time_series",
1174 | "intervalFactor": 1,
1175 | "legendFormat": "# of total processes",
1176 | "metric": "phpfpm_total_processes",
1177 | "refId": "C",
1178 | "step": 1
1179 | }
1180 | ],
1181 | "thresholds": [],
1182 | "timeFrom": null,
1183 | "timeShift": null,
1184 | "title": "# of Active & Idle processes",
1185 | "tooltip": {
1186 | "shared": true,
1187 | "sort": 0,
1188 | "value_type": "individual"
1189 | },
1190 | "type": "graph",
1191 | "xaxis": {
1192 | "buckets": null,
1193 | "mode": "time",
1194 | "name": null,
1195 | "show": true,
1196 | "values": []
1197 | },
1198 | "yaxes": [
1199 | {
1200 | "format": "short",
1201 | "label": null,
1202 | "logBase": 1,
1203 | "max": null,
1204 | "min": null,
1205 | "show": true
1206 | },
1207 | {
1208 | "format": "short",
1209 | "label": null,
1210 | "logBase": 1,
1211 | "max": null,
1212 | "min": null,
1213 | "show": true
1214 | }
1215 | ]
1216 | },
1217 | {
1218 | "aliasColors": {},
1219 | "bars": false,
1220 | "dashLength": 10,
1221 | "dashes": false,
1222 | "datasource": "prometheus",
1223 | "fill": 1,
1224 | "id": 4,
1225 | "legend": {
1226 | "alignAsTable": false,
1227 | "avg": false,
1228 | "current": false,
1229 | "max": false,
1230 | "min": false,
1231 | "rightSide": true,
1232 | "show": false,
1233 | "total": false,
1234 | "values": false
1235 | },
1236 | "lines": true,
1237 | "linewidth": 1,
1238 | "links": [],
1239 | "nullPointMode": "null",
1240 | "percentage": false,
1241 | "pointradius": 5,
1242 | "points": false,
1243 | "renderer": "flot",
1244 | "seriesOverrides": [
1245 | {
1246 | "alias": "# of pod terminations",
1247 | "yaxis": 2
1248 | }
1249 | ],
1250 | "spaceLength": 10,
1251 | "span": 6,
1252 | "stack": false,
1253 | "steppedLine": false,
1254 | "targets": [
1255 | {
1256 | "dsType": "influxdb",
1257 | "expr": "avg((sum(phpfpm_active_processes{namespace=\"$namespace\"}) by (kubernetes_pod_name) *100) / sum(phpfpm_total_processes{namespace=\"$namespace\"}) by (kubernetes_pod_name))",
1258 | "format": "time_series",
1259 | "groupBy": [
1260 | {
1261 | "params": ["$__interval"],
1262 | "type": "time"
1263 | },
1264 | {
1265 | "params": ["null"],
1266 | "type": "fill"
1267 | }
1268 | ],
1269 | "intervalFactor": 2,
1270 | "legendFormat": "Process utilisation",
1271 | "metric": "",
1272 | "orderByTime": "ASC",
1273 | "policy": "default",
1274 | "refId": "A",
1275 | "resultFormat": "time_series",
1276 | "select": [
1277 | [
1278 | {
1279 | "params": ["value"],
1280 | "type": "field"
1281 | },
1282 | {
1283 | "params": [],
1284 | "type": "mean"
1285 | }
1286 | ]
1287 | ],
1288 | "step": 2,
1289 | "tags": []
1290 | },
1291 | {
1292 | "expr": "sum(kube_pod_container_status_terminated{pod=~\"static-thread-handling-.*\"})",
1293 | "format": "time_series",
1294 | "hide": false,
1295 | "intervalFactor": 2,
1296 | "legendFormat": "# of pod terminations",
1297 | "metric": "kube",
1298 | "refId": "B",
1299 | "step": 2
1300 | }
1301 | ],
1302 | "thresholds": [],
1303 | "timeFrom": null,
1304 | "timeShift": null,
1305 | "title": "Total process utilisation & container termination",
1306 | "tooltip": {
1307 | "shared": true,
1308 | "sort": 0,
1309 | "value_type": "individual"
1310 | },
1311 | "type": "graph",
1312 | "xaxis": {
1313 | "buckets": null,
1314 | "mode": "time",
1315 | "name": null,
1316 | "show": true,
1317 | "values": ["total"]
1318 | },
1319 | "yaxes": [
1320 | {
1321 | "format": "percent",
1322 | "label": "Process utilisation",
1323 | "logBase": 1,
1324 | "max": "100",
1325 | "min": "0",
1326 | "show": true
1327 | },
1328 | {
1329 | "format": "short",
1330 | "label": "Pod termination",
1331 | "logBase": 1,
1332 | "max": null,
1333 | "min": "0",
1334 | "show": true
1335 | }
1336 | ]
1337 | }
1338 | ],
1339 | "repeat": null,
1340 | "repeatIteration": null,
1341 | "repeatRowId": null,
1342 | "showTitle": false,
1343 | "title": "Dashboard Row",
1344 | "titleSize": "h6"
1345 | },
1346 | {
1347 | "collapse": false,
1348 | "height": 235,
1349 | "panels": [
1350 | {
1351 | "aliasColors": {},
1352 | "bars": false,
1353 | "dashLength": 10,
1354 | "dashes": false,
1355 | "datasource": "prometheus",
1356 | "fill": 1,
1357 | "id": 12,
1358 | "legend": {
1359 | "avg": false,
1360 | "current": false,
1361 | "max": false,
1362 | "min": false,
1363 | "show": true,
1364 | "total": false,
1365 | "values": false
1366 | },
1367 | "lines": true,
1368 | "linewidth": 1,
1369 | "links": [],
1370 | "nullPointMode": "null",
1371 | "percentage": false,
1372 | "pointradius": 5,
1373 | "points": false,
1374 | "renderer": "flot",
1375 | "seriesOverrides": [],
1376 | "spaceLength": 10,
1377 | "span": 6,
1378 | "stack": false,
1379 | "steppedLine": false,
1380 | "targets": [
1381 | {
1382 | "dsType": "influxdb",
1383 | "expr": "kube_replicaset_spec_replicas{replicaset=~\"$branch-.*\"}",
1384 | "format": "time_series",
1385 | "groupBy": [
1386 | {
1387 | "params": ["$__interval"],
1388 | "type": "time"
1389 | },
1390 | {
1391 | "params": ["null"],
1392 | "type": "fill"
1393 | }
1394 | ],
1395 | "intervalFactor": 2,
1396 | "legendFormat": "{{replicaset}}",
1397 | "metric": "",
1398 | "orderByTime": "ASC",
1399 | "policy": "default",
1400 | "refId": "A",
1401 | "resultFormat": "time_series",
1402 | "select": [
1403 | [
1404 | {
1405 | "params": ["value"],
1406 | "type": "field"
1407 | },
1408 | {
1409 | "params": [],
1410 | "type": "mean"
1411 | }
1412 | ]
1413 | ],
1414 | "step": 2,
1415 | "tags": []
1416 | }
1417 | ],
1418 | "thresholds": [],
1419 | "timeFrom": null,
1420 | "timeShift": null,
1421 | "title": "# of pods in a ReplicaSet",
1422 | "tooltip": {
1423 | "shared": true,
1424 | "sort": 0,
1425 | "value_type": "individual"
1426 | },
1427 | "type": "graph",
1428 | "xaxis": {
1429 | "buckets": null,
1430 | "mode": "time",
1431 | "name": null,
1432 | "show": true,
1433 | "values": []
1434 | },
1435 | "yaxes": [
1436 | {
1437 | "format": "none",
1438 | "label": null,
1439 | "logBase": 1,
1440 | "max": null,
1441 | "min": null,
1442 | "show": true
1443 | },
1444 | {
1445 | "format": "short",
1446 | "label": null,
1447 | "logBase": 1,
1448 | "max": null,
1449 | "min": null,
1450 | "show": false
1451 | }
1452 | ]
1453 | },
1454 | {
1455 | "aliasColors": {},
1456 | "bars": false,
1457 | "dashLength": 10,
1458 | "dashes": false,
1459 | "datasource": "prometheus",
1460 | "editable": true,
1461 | "error": false,
1462 | "fill": 1,
1463 | "id": 17,
1464 | "legend": {
1465 | "alignAsTable": true,
1466 | "avg": true,
1467 | "current": false,
1468 | "max": true,
1469 | "min": false,
1470 | "rightSide": true,
1471 | "show": true,
1472 | "sort": "avg",
1473 | "sortDesc": true,
1474 | "total": false,
1475 | "values": true
1476 | },
1477 | "lines": true,
1478 | "linewidth": 1,
1479 | "links": [],
1480 | "nullPointMode": "connected",
1481 | "percentage": false,
1482 | "pointradius": 5,
1483 | "points": false,
1484 | "renderer": "flot",
1485 | "seriesOverrides": [],
1486 | "spaceLength": 10,
1487 | "span": 6,
1488 | "stack": false,
1489 | "steppedLine": false,
1490 | "targets": [
1491 | {
1492 | "expr": "count(count(container_memory_usage_bytes{namespace=\"$namespace\"}) by (pod_name))",
1493 | "format": "time_series",
1494 | "interval": "",
1495 | "intervalFactor": 1,
1496 | "legendFormat": "pods",
1497 | "refId": "A",
1498 | "step": 1
1499 | },
1500 | {
1501 | "expr": "count(count(container_memory_usage_bytes{namespace=\"$namespace\"}) by (kubernetes_io_hostname))",
1502 | "format": "time_series",
1503 | "interval": "",
1504 | "intervalFactor": 2,
1505 | "legendFormat": "hosts",
1506 | "refId": "B",
1507 | "step": 2
1508 | }
1509 | ],
1510 | "thresholds": [],
1511 | "timeFrom": null,
1512 | "timeShift": null,
1513 | "title": "Number of pods",
1514 | "tooltip": {
1515 | "msResolution": false,
1516 | "shared": true,
1517 | "sort": 0,
1518 | "value_type": "individual"
1519 | },
1520 | "type": "graph",
1521 | "xaxis": {
1522 | "buckets": null,
1523 | "mode": "time",
1524 | "name": null,
1525 | "show": true,
1526 | "values": []
1527 | },
1528 | "yaxes": [
1529 | {
1530 | "format": "short",
1531 | "label": null,
1532 | "logBase": 1,
1533 | "max": null,
1534 | "min": "0",
1535 | "show": true
1536 | },
1537 | {
1538 | "format": "short",
1539 | "label": null,
1540 | "logBase": 1,
1541 | "max": null,
1542 | "min": null,
1543 | "show": true
1544 | }
1545 | ]
1546 | }
1547 | ],
1548 | "repeat": null,
1549 | "repeatIteration": null,
1550 | "repeatRowId": null,
1551 | "showTitle": false,
1552 | "title": "Dashboard Row",
1553 | "titleSize": "h6"
1554 | },
1555 | {
1556 | "collapse": false,
1557 | "height": 250,
1558 | "panels": [
1559 | {
1560 | "aliasColors": {},
1561 | "bars": false,
1562 | "dashLength": 10,
1563 | "dashes": false,
1564 | "datasource": "prometheus",
1565 | "editable": true,
1566 | "error": false,
1567 | "fill": 1,
1568 | "id": 18,
1569 | "legend": {
1570 | "alignAsTable": true,
1571 | "avg": true,
1572 | "current": false,
1573 | "max": true,
1574 | "min": false,
1575 | "rightSide": true,
1576 | "show": true,
1577 | "sort": "avg",
1578 | "sortDesc": true,
1579 | "total": false,
1580 | "values": true
1581 | },
1582 | "lines": true,
1583 | "linewidth": 1,
1584 | "links": [],
1585 | "nullPointMode": "connected",
1586 | "percentage": false,
1587 | "pointradius": 5,
1588 | "points": false,
1589 | "renderer": "flot",
1590 | "seriesOverrides": [],
1591 | "spaceLength": 10,
1592 | "span": 6,
1593 | "stack": false,
1594 | "steppedLine": false,
1595 | "targets": [
1596 | {
1597 | "expr": "sum(irate(container_cpu_usage_seconds_total{container=\"php\",namespace=\"$namespace\"}[30s])) by (namespace, container) / sum(container_spec_cpu_quota{container=\"php\",namespace=\"$namespace\"} / container_spec_cpu_period{container=\"php\",namespace=\"$namespace\"}) by (namespace, container)",
1598 | "format": "time_series",
1599 | "interval": "",
1600 | "intervalFactor": 1,
1601 | "legendFormat": "actual",
1602 | "metric": "",
1603 | "refId": "A",
1604 | "step": 1
1605 | }
1606 | ],
1607 | "thresholds": [],
1608 | "timeFrom": null,
1609 | "timeShift": null,
1610 | "title": "Cpu usage (relative to limit)",
1611 | "tooltip": {
1612 | "msResolution": false,
1613 | "shared": true,
1614 | "sort": 0,
1615 | "value_type": "individual"
1616 | },
1617 | "type": "graph",
1618 | "xaxis": {
1619 | "buckets": null,
1620 | "mode": "time",
1621 | "name": null,
1622 | "show": true,
1623 | "values": []
1624 | },
1625 | "yaxes": [
1626 | {
1627 | "format": "percentunit",
1628 | "label": "",
1629 | "logBase": 1,
1630 | "max": "1",
1631 | "min": "0",
1632 | "show": true
1633 | },
1634 | {
1635 | "format": "short",
1636 | "label": null,
1637 | "logBase": 1,
1638 | "max": null,
1639 | "min": null,
1640 | "show": true
1641 | }
1642 | ]
1643 | },
1644 | {
1645 | "aliasColors": {},
1646 | "bars": false,
1647 | "dashLength": 10,
1648 | "dashes": false,
1649 | "datasource": "prometheus",
1650 | "editable": true,
1651 | "error": false,
1652 | "fill": 1,
1653 | "id": 19,
1654 | "legend": {
1655 | "alignAsTable": true,
1656 | "avg": true,
1657 | "current": false,
1658 | "max": true,
1659 | "min": false,
1660 | "rightSide": true,
1661 | "show": true,
1662 | "sort": "avg",
1663 | "sortDesc": true,
1664 | "total": false,
1665 | "values": true
1666 | },
1667 | "lines": true,
1668 | "linewidth": 1,
1669 | "links": [],
1670 | "nullPointMode": "connected",
1671 | "percentage": false,
1672 | "pointradius": 5,
1673 | "points": false,
1674 | "renderer": "flot",
1675 | "seriesOverrides": [],
1676 | "spaceLength": 10,
1677 | "span": 6,
1678 | "stack": false,
1679 | "steppedLine": false,
1680 | "targets": [
1681 | {
1682 | "expr": "sum(container_memory_usage_bytes{container=\"php\",namespace=\"$namespace\"}) by (namespace, container) / sum(container_spec_memory_limit_bytes{container=\"php\",namespace=\"$namespace\"}) by (namespace, container)",
1683 | "format": "time_series",
1684 | "interval": "",
1685 | "intervalFactor": 1,
1686 | "legendFormat": "actual",
1687 | "refId": "A",
1688 | "step": 1
1689 | }
1690 | ],
1691 | "thresholds": [],
1692 | "timeFrom": null,
1693 | "timeShift": null,
1694 | "title": "Memory usage (relative to limit)",
1695 | "tooltip": {
1696 | "msResolution": false,
1697 | "shared": true,
1698 | "sort": 0,
1699 | "value_type": "individual"
1700 | },
1701 | "type": "graph",
1702 | "xaxis": {
1703 | "buckets": null,
1704 | "mode": "time",
1705 | "name": null,
1706 | "show": true,
1707 | "values": []
1708 | },
1709 | "yaxes": [
1710 | {
1711 | "format": "percentunit",
1712 | "label": null,
1713 | "logBase": 1,
1714 | "max": "1",
1715 | "min": "0",
1716 | "show": true
1717 | },
1718 | {
1719 | "format": "short",
1720 | "label": null,
1721 | "logBase": 1,
1722 | "max": null,
1723 | "min": null,
1724 | "show": true
1725 | }
1726 | ]
1727 | }
1728 | ],
1729 | "repeat": null,
1730 | "repeatIteration": null,
1731 | "repeatRowId": null,
1732 | "showTitle": false,
1733 | "title": "Usage relative to limit",
1734 | "titleSize": "h6"
1735 | },
1736 | {
1737 | "collapse": false,
1738 | "height": 261,
1739 | "panels": [
1740 | {
1741 | "aliasColors": {},
1742 | "bars": false,
1743 | "dashLength": 10,
1744 | "dashes": false,
1745 | "datasource": "prometheus",
1746 | "description": "The metric may not work if there is no quota assigned.",
1747 | "fill": 1,
1748 | "id": 16,
1749 | "legend": {
1750 | "avg": false,
1751 | "current": false,
1752 | "max": false,
1753 | "min": false,
1754 | "show": true,
1755 | "total": false,
1756 | "values": false
1757 | },
1758 | "lines": true,
1759 | "linewidth": 1,
1760 | "links": [],
1761 | "nullPointMode": "null",
1762 | "percentage": false,
1763 | "pointradius": 5,
1764 | "points": false,
1765 | "renderer": "flot",
1766 | "seriesOverrides": [],
1767 | "spaceLength": 10,
1768 | "span": 6,
1769 | "stack": false,
1770 | "steppedLine": false,
1771 | "targets": [
1772 | {
1773 | "alias": "",
1774 | "expr": "sum(\n irate(\n container_cpu_usage_seconds_total{container=\"php\",namespace=\"$namespace\"}[2m]\n )\n) by (namespace,container,pod) /\nsum(\n container_spec_cpu_quota{container=\"php\",namespace=\"$namespace\"} /\n container_spec_cpu_period{container=\"php\",namespace=\"$namespace\"}\n) by (namespace,container,pod)",
1775 | "format": "time_series",
1776 | "intervalFactor": 1,
1777 | "rawSql": "SELECT\n UNIX_TIMESTAMP() as time_sec,\n as value,\n as metric\nFROM \nWHERE $__timeFilter(time_column)\nORDER BY ASC\n",
1778 | "refId": "A",
1779 | "step": 1
1780 | }
1781 | ],
1782 | "thresholds": [],
1783 | "timeFrom": null,
1784 | "timeShift": null,
1785 | "title": "CPU usage per pod (relative to limit)",
1786 | "tooltip": {
1787 | "shared": true,
1788 | "sort": 0,
1789 | "value_type": "individual"
1790 | },
1791 | "type": "graph",
1792 | "xaxis": {
1793 | "buckets": null,
1794 | "mode": "time",
1795 | "name": null,
1796 | "show": true,
1797 | "values": []
1798 | },
1799 | "yaxes": [
1800 | {
1801 | "format": "short",
1802 | "label": null,
1803 | "logBase": 1,
1804 | "max": null,
1805 | "min": null,
1806 | "show": true
1807 | },
1808 | {
1809 | "format": "short",
1810 | "label": null,
1811 | "logBase": 1,
1812 | "max": null,
1813 | "min": null,
1814 | "show": true
1815 | }
1816 | ]
1817 | },
1818 | {
1819 | "aliasColors": {},
1820 | "bars": false,
1821 | "dashLength": 10,
1822 | "dashes": false,
1823 | "datasource": "prometheus",
1824 | "fill": 1,
1825 | "id": 15,
1826 | "legend": {
1827 | "avg": false,
1828 | "current": false,
1829 | "max": false,
1830 | "min": false,
1831 | "show": true,
1832 | "total": false,
1833 | "values": false
1834 | },
1835 | "lines": true,
1836 | "linewidth": 1,
1837 | "links": [],
1838 | "nullPointMode": "null",
1839 | "percentage": false,
1840 | "pointradius": 5,
1841 | "points": false,
1842 | "renderer": "flot",
1843 | "seriesOverrides": [],
1844 | "spaceLength": 10,
1845 | "span": 6,
1846 | "stack": false,
1847 | "steppedLine": false,
1848 | "targets": [
1849 | {
1850 | "alias": "",
1851 | "expr": "sum(container_memory_usage_bytes{container=\"php\",namespace=\"$namespace\"}) by (namespace,container,pod) / sum(container_spec_memory_limit_bytes{container=\"php\",namespace=\"$namespace\"}) by (namespace,container,pod)",
1852 | "format": "time_series",
1853 | "intervalFactor": 1,
1854 | "legendFormat": "{{pod}}",
1855 | "rawSql": "SELECT\n UNIX_TIMESTAMP() as time_sec,\n as value,\n as metric\nFROM \nWHERE $__timeFilter(time_column)\nORDER BY ASC\n",
1856 | "refId": "A",
1857 | "step": 1
1858 | }
1859 | ],
1860 | "thresholds": [],
1861 | "timeFrom": null,
1862 | "timeShift": null,
1863 | "title": "Memory usage per pod (relative to limit)",
1864 | "tooltip": {
1865 | "shared": true,
1866 | "sort": 0,
1867 | "value_type": "individual"
1868 | },
1869 | "type": "graph",
1870 | "xaxis": {
1871 | "buckets": null,
1872 | "mode": "time",
1873 | "name": null,
1874 | "show": true,
1875 | "values": []
1876 | },
1877 | "yaxes": [
1878 | {
1879 | "format": "percentunit",
1880 | "label": null,
1881 | "logBase": 1,
1882 | "max": "1",
1883 | "min": "0",
1884 | "show": true
1885 | },
1886 | {
1887 | "format": "short",
1888 | "label": null,
1889 | "logBase": 1,
1890 | "max": null,
1891 | "min": null,
1892 | "show": true
1893 | }
1894 | ]
1895 | }
1896 | ],
1897 | "repeat": null,
1898 | "repeatIteration": null,
1899 | "repeatRowId": null,
1900 | "showTitle": false,
1901 | "title": "Usage per pod relative to limit",
1902 | "titleSize": "h6"
1903 | },
1904 | {
1905 | "collapse": false,
1906 | "height": "250",
1907 | "panels": [
1908 | {
1909 | "aliasColors": {},
1910 | "bars": false,
1911 | "dashLength": 10,
1912 | "dashes": false,
1913 | "datasource": "prometheus",
1914 | "fill": 1,
1915 | "id": 20,
1916 | "legend": {
1917 | "alignAsTable": true,
1918 | "avg": true,
1919 | "current": false,
1920 | "max": true,
1921 | "min": false,
1922 | "rightSide": true,
1923 | "show": true,
1924 | "sort": "avg",
1925 | "sortDesc": true,
1926 | "total": false,
1927 | "values": true
1928 | },
1929 | "lines": true,
1930 | "linewidth": 1,
1931 | "links": [],
1932 | "nullPointMode": "null",
1933 | "percentage": false,
1934 | "pointradius": 5,
1935 | "points": false,
1936 | "renderer": "flot",
1937 | "seriesOverrides": [],
1938 | "spaceLength": 10,
1939 | "span": 6,
1940 | "stack": false,
1941 | "steppedLine": false,
1942 | "targets": [
1943 | {
1944 | "expr": "sum(irate(container_cpu_usage_seconds_total{container=\"php\",namespace=\"$namespace\"}[30s])) by (id,pod)",
1945 | "format": "time_series",
1946 | "interval": "",
1947 | "intervalFactor": 2,
1948 | "legendFormat": "{{pod}}",
1949 | "refId": "A",
1950 | "step": 2
1951 | },
1952 | {
1953 | "expr": "sum(container_spec_cpu_quota{container=\"php\",namespace=\"$namespace\"} / container_spec_cpu_period{container=\"php\",namespace=\"$namespace\"}) by (namespace,container) / count(container_memory_usage_bytes{container=\"php\",namespace=\"$namespace\"}) by (namespace,container) ",
1954 | "format": "time_series",
1955 | "intervalFactor": 2,
1956 | "legendFormat": "limit",
1957 | "refId": "B",
1958 | "step": 2
1959 | },
1960 | {
1961 | "expr": "sum(container_spec_cpu_shares{container=\"php\",namespace=\"$namespace\"} / 1024) by (namespace,container) / count(container_spec_cpu_shares{container=\"php\",namespace=\"$namespace\"}) by (namespace,container) ",
1962 | "format": "time_series",
1963 | "intervalFactor": 2,
1964 | "legendFormat": "request",
1965 | "refId": "C",
1966 | "step": 2
1967 | }
1968 | ],
1969 | "thresholds": [],
1970 | "timeFrom": null,
1971 | "timeShift": null,
1972 | "title": "Cpu usage (per pod)",
1973 | "tooltip": {
1974 | "shared": true,
1975 | "sort": 0,
1976 | "value_type": "individual"
1977 | },
1978 | "type": "graph",
1979 | "xaxis": {
1980 | "buckets": null,
1981 | "mode": "time",
1982 | "name": null,
1983 | "show": true,
1984 | "values": []
1985 | },
1986 | "yaxes": [
1987 | {
1988 | "format": "short",
1989 | "label": "cores",
1990 | "logBase": 1,
1991 | "max": null,
1992 | "min": "0",
1993 | "show": true
1994 | },
1995 | {
1996 | "format": "short",
1997 | "label": null,
1998 | "logBase": 1,
1999 | "max": null,
2000 | "min": null,
2001 | "show": true
2002 | }
2003 | ]
2004 | },
2005 | {
2006 | "aliasColors": {},
2007 | "bars": false,
2008 | "dashLength": 10,
2009 | "dashes": false,
2010 | "datasource": "prometheus",
2011 | "editable": true,
2012 | "error": false,
2013 | "fill": 1,
2014 | "id": 21,
2015 | "legend": {
2016 | "alignAsTable": true,
2017 | "avg": true,
2018 | "current": false,
2019 | "max": true,
2020 | "min": false,
2021 | "rightSide": true,
2022 | "show": true,
2023 | "sort": "avg",
2024 | "sortDesc": true,
2025 | "total": false,
2026 | "values": true
2027 | },
2028 | "lines": true,
2029 | "linewidth": 1,
2030 | "links": [],
2031 | "nullPointMode": "connected",
2032 | "percentage": false,
2033 | "pointradius": 5,
2034 | "points": false,
2035 | "renderer": "flot",
2036 | "seriesOverrides": [],
2037 | "spaceLength": 10,
2038 | "span": 6,
2039 | "stack": false,
2040 | "steppedLine": false,
2041 | "targets": [
2042 | {
2043 | "expr": "sum(container_memory_usage_bytes{container=\"php\",namespace=\"$namespace\"}) by (namespace,container) / count(container_memory_usage_bytes{container=\"php\",namespace=\"$namespace\"}) by (namespace,container) ",
2044 | "format": "time_series",
2045 | "intervalFactor": 1,
2046 | "legendFormat": "actual",
2047 | "metric": "",
2048 | "refId": "A",
2049 | "step": 1
2050 | },
2051 | {
2052 | "expr": "sum(container_spec_memory_limit_bytes{container=\"php\",namespace=\"$namespace\"}) by (namespace,container) / count(container_memory_usage_bytes{container=\"php\",namespace=\"$namespace\"}) by (namespace,container) ",
2053 | "format": "time_series",
2054 | "interval": "",
2055 | "intervalFactor": 1,
2056 | "legendFormat": "limit",
2057 | "refId": "B",
2058 | "step": 1
2059 | }
2060 | ],
2061 | "thresholds": [],
2062 | "timeFrom": null,
2063 | "timeShift": null,
2064 | "title": "Memory usage (avg per pod)",
2065 | "tooltip": {
2066 | "msResolution": false,
2067 | "shared": true,
2068 | "sort": 0,
2069 | "value_type": "individual"
2070 | },
2071 | "type": "graph",
2072 | "xaxis": {
2073 | "buckets": null,
2074 | "mode": "time",
2075 | "name": null,
2076 | "show": true,
2077 | "values": []
2078 | },
2079 | "yaxes": [
2080 | {
2081 | "format": "bytes",
2082 | "label": null,
2083 | "logBase": 1,
2084 | "max": null,
2085 | "min": "0",
2086 | "show": true
2087 | },
2088 | {
2089 | "format": "short",
2090 | "label": null,
2091 | "logBase": 1,
2092 | "max": null,
2093 | "min": null,
2094 | "show": true
2095 | }
2096 | ]
2097 | }
2098 | ],
2099 | "repeat": null,
2100 | "repeatIteration": null,
2101 | "repeatRowId": null,
2102 | "showTitle": false,
2103 | "title": "Usage per pod (average)",
2104 | "titleSize": "h6"
2105 | },
2106 | {
2107 | "collapse": false,
2108 | "height": 258,
2109 | "panels": [
2110 | {
2111 | "aliasColors": {},
2112 | "bars": false,
2113 | "dashLength": 10,
2114 | "dashes": false,
2115 | "datasource": "prometheus",
2116 | "editable": true,
2117 | "error": false,
2118 | "fill": 1,
2119 | "grid": {},
2120 | "id": 22,
2121 | "legend": {
2122 | "alignAsTable": true,
2123 | "avg": true,
2124 | "current": false,
2125 | "max": true,
2126 | "min": false,
2127 | "rightSide": true,
2128 | "show": true,
2129 | "sort": "avg",
2130 | "sortDesc": true,
2131 | "total": false,
2132 | "values": true
2133 | },
2134 | "lines": true,
2135 | "linewidth": 2,
2136 | "links": [],
2137 | "nullPointMode": "connected",
2138 | "percentage": false,
2139 | "pointradius": 5,
2140 | "points": false,
2141 | "renderer": "flot",
2142 | "seriesOverrides": [],
2143 | "spaceLength": 10,
2144 | "span": 6,
2145 | "stack": false,
2146 | "steppedLine": false,
2147 | "targets": [
2148 | {
2149 | "expr": "sum(irate(container_cpu_usage_seconds_total{container=\"php\",namespace=\"$namespace\"}[30s])) by (namespace,container)",
2150 | "format": "time_series",
2151 | "hide": false,
2152 | "interval": "",
2153 | "intervalFactor": 1,
2154 | "legendFormat": "actual",
2155 | "metric": "",
2156 | "refId": "A",
2157 | "step": 1
2158 | },
2159 | {
2160 | "expr": "sum(container_spec_cpu_quota{container=\"php\",namespace=\"$namespace\"} / container_spec_cpu_period{container=\"php\",namespace=\"$namespace\"}) by (namespace,container)",
2161 | "format": "time_series",
2162 | "intervalFactor": 1,
2163 | "legendFormat": "limit",
2164 | "refId": "B",
2165 | "step": 1
2166 | },
2167 | {
2168 | "expr": "sum(container_spec_cpu_shares{container=\"php\",namespace=\"$namespace\"} / 1024) by (namespace,container) ",
2169 | "format": "time_series",
2170 | "intervalFactor": 1,
2171 | "legendFormat": "request",
2172 | "refId": "C",
2173 | "step": 1
2174 | }
2175 | ],
2176 | "thresholds": [],
2177 | "timeFrom": null,
2178 | "timeShift": null,
2179 | "title": "Cpu usage (total)",
2180 | "tooltip": {
2181 | "msResolution": true,
2182 | "shared": false,
2183 | "sort": 0,
2184 | "value_type": "cumulative"
2185 | },
2186 | "type": "graph",
2187 | "xaxis": {
2188 | "buckets": null,
2189 | "mode": "time",
2190 | "name": null,
2191 | "show": true,
2192 | "values": []
2193 | },
2194 | "yaxes": [
2195 | {
2196 | "format": "none",
2197 | "label": "cores",
2198 | "logBase": 1,
2199 | "max": null,
2200 | "min": 0,
2201 | "show": true
2202 | },
2203 | {
2204 | "format": "short",
2205 | "label": null,
2206 | "logBase": 1,
2207 | "max": null,
2208 | "min": null,
2209 | "show": true
2210 | }
2211 | ]
2212 | },
2213 | {
2214 | "aliasColors": {},
2215 | "bars": false,
2216 | "dashLength": 10,
2217 | "dashes": false,
2218 | "datasource": "prometheus",
2219 | "editable": true,
2220 | "error": false,
2221 | "fill": 1,
2222 | "grid": {},
2223 | "id": 23,
2224 | "legend": {
2225 | "alignAsTable": true,
2226 | "avg": true,
2227 | "current": false,
2228 | "max": true,
2229 | "min": false,
2230 | "rightSide": true,
2231 | "show": true,
2232 | "sort": "avg",
2233 | "sortDesc": true,
2234 | "total": false,
2235 | "values": true
2236 | },
2237 | "lines": true,
2238 | "linewidth": 2,
2239 | "links": [],
2240 | "nullPointMode": "connected",
2241 | "percentage": false,
2242 | "pointradius": 5,
2243 | "points": false,
2244 | "renderer": "flot",
2245 | "seriesOverrides": [],
2246 | "spaceLength": 10,
2247 | "span": 6,
2248 | "stack": false,
2249 | "steppedLine": false,
2250 | "targets": [
2251 | {
2252 | "expr": "sum(container_memory_usage_bytes{container=\"php\",namespace=\"$namespace\"}) by (namespace,container)",
2253 | "format": "time_series",
2254 | "interval": "",
2255 | "intervalFactor": 1,
2256 | "legendFormat": "actual",
2257 | "refId": "A",
2258 | "step": 1
2259 | },
2260 | {
2261 | "expr": "sum(container_spec_memory_limit_bytes{container=\"php\",namespace=\"$namespace\"}) by (namespace,container)",
2262 | "format": "time_series",
2263 | "intervalFactor": 1,
2264 | "legendFormat": "limit",
2265 | "refId": "B",
2266 | "step": 1
2267 | }
2268 | ],
2269 | "thresholds": [],
2270 | "timeFrom": null,
2271 | "timeShift": null,
2272 | "title": "Memory usage (total)",
2273 | "tooltip": {
2274 | "msResolution": true,
2275 | "shared": false,
2276 | "sort": 0,
2277 | "value_type": "cumulative"
2278 | },
2279 | "type": "graph",
2280 | "xaxis": {
2281 | "buckets": null,
2282 | "mode": "time",
2283 | "name": null,
2284 | "show": true,
2285 | "values": []
2286 | },
2287 | "yaxes": [
2288 | {
2289 | "format": "bytes",
2290 | "label": null,
2291 | "logBase": 1,
2292 | "max": null,
2293 | "min": "0",
2294 | "show": true
2295 | },
2296 | {
2297 | "format": "short",
2298 | "label": null,
2299 | "logBase": 1,
2300 | "max": null,
2301 | "min": null,
2302 | "show": true
2303 | }
2304 | ]
2305 | }
2306 | ],
2307 | "repeat": null,
2308 | "repeatIteration": null,
2309 | "repeatRowId": null,
2310 | "showTitle": false,
2311 | "title": "Usage total",
2312 | "titleSize": "h6"
2313 | }
2314 | ],
2315 | "schemaVersion": 14,
2316 | "style": "dark",
2317 | "tags": [],
2318 | "templating": {
2319 | "list": [
2320 | {
2321 | "allValue": null,
2322 | "current": {},
2323 | "datasource": "prometheus",
2324 | "hide": 0,
2325 | "includeAll": false,
2326 | "label": "Namespace",
2327 | "multi": false,
2328 | "name": "namespace",
2329 | "options": [],
2330 | "query": "label_values(phpfpm_up,namespace)",
2331 | "refresh": 2,
2332 | "regex": "",
2333 | "sort": 0,
2334 | "tagValuesQuery": "",
2335 | "tags": [],
2336 | "tagsQuery": "",
2337 | "type": "query",
2338 | "useTags": false
2339 | }
2340 | ]
2341 | },
2342 | "time": {
2343 | "from": "now-15m",
2344 | "to": "now"
2345 | },
2346 | "timepicker": {
2347 | "refresh_intervals": ["5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"],
2348 | "time_options": ["5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d", "30d"]
2349 | },
2350 | "timezone": "",
2351 | "title": "Kubernetes PHP-FPM",
2352 | "version": 55,
2353 | "description": "A companion dashboard for https://github.com/hipages/php-fpm_exporter\r\n\r\nThe dashboard caters to Kubernetes & PHP-FPM but can be easily adjusted."
2354 | }
2355 |
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2018 Enrico Stahn
2 | // Licensed under the Apache License, Version 2.0 (the "License");
3 | // you may not use this file except in compliance with the License.
4 | // You may obtain a copy of the License at
5 | //
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package main
15 |
16 | import (
17 | "fmt"
18 |
19 | "github.com/hipages/php-fpm_exporter/cmd"
20 | )
21 |
22 | var (
23 | version = "dev"
24 | commit = "none"
25 | date = "unknown"
26 | )
27 |
28 | func main() {
29 | cmd.Version = fmt.Sprintf("%v, commit %v, built at %v", version, commit, date)
30 | cmd.Execute()
31 | }
32 |
--------------------------------------------------------------------------------
/phpfpm/exporter.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2018 Enrico Stahn
2 | // Licensed under the Apache License, Version 2.0 (the "License");
3 | // you may not use this file except in compliance with the License.
4 | // You may obtain a copy of the License at
5 | //
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | // Package phpfpm provides convenient access to PHP-FPM pool data
15 | package phpfpm
16 |
17 | import (
18 | "fmt"
19 | "sync"
20 |
21 | "github.com/prometheus/client_golang/prometheus"
22 | )
23 |
24 | const (
25 | namespace = "phpfpm"
26 | )
27 |
28 | // Exporter configures and exposes PHP-FPM metrics to Prometheus.
29 | type Exporter struct {
30 | mutex sync.Mutex
31 | PoolManager PoolManager
32 |
33 | CountProcessState bool
34 |
35 | up *prometheus.Desc
36 | scrapeFailues *prometheus.Desc
37 | startSince *prometheus.Desc
38 | acceptedConnections *prometheus.Desc
39 | listenQueue *prometheus.Desc
40 | maxListenQueue *prometheus.Desc
41 | listenQueueLength *prometheus.Desc
42 | idleProcesses *prometheus.Desc
43 | activeProcesses *prometheus.Desc
44 | totalProcesses *prometheus.Desc
45 | maxActiveProcesses *prometheus.Desc
46 | maxChildrenReached *prometheus.Desc
47 | slowRequests *prometheus.Desc
48 | processRequests *prometheus.Desc
49 | processLastRequestMemory *prometheus.Desc
50 | processLastRequestCPU *prometheus.Desc
51 | processRequestDuration *prometheus.Desc
52 | processState *prometheus.Desc
53 | }
54 |
55 | // NewExporter creates a new Exporter for a PoolManager and configures the necessary metrics.
56 | func NewExporter(pm PoolManager) *Exporter {
57 | return &Exporter{
58 | PoolManager: pm,
59 |
60 | CountProcessState: false,
61 |
62 | up: prometheus.NewDesc(
63 | prometheus.BuildFQName(namespace, "", "up"),
64 | "Could PHP-FPM be reached?",
65 | []string{"pool", "scrape_uri"},
66 | nil),
67 |
68 | scrapeFailues: prometheus.NewDesc(
69 | prometheus.BuildFQName(namespace, "", "scrape_failures"),
70 | "The number of failures scraping from PHP-FPM.",
71 | []string{"pool", "scrape_uri"},
72 | nil),
73 |
74 | startSince: prometheus.NewDesc(
75 | prometheus.BuildFQName(namespace, "", "start_since"),
76 | "The number of seconds since FPM has started.",
77 | []string{"pool", "scrape_uri"},
78 | nil),
79 |
80 | acceptedConnections: prometheus.NewDesc(
81 | prometheus.BuildFQName(namespace, "", "accepted_connections"),
82 | "The number of requests accepted by the pool.",
83 | []string{"pool", "scrape_uri"},
84 | nil),
85 |
86 | listenQueue: prometheus.NewDesc(
87 | prometheus.BuildFQName(namespace, "", "listen_queue"),
88 | "The number of requests in the queue of pending connections.",
89 | []string{"pool", "scrape_uri"},
90 | nil),
91 |
92 | maxListenQueue: prometheus.NewDesc(
93 | prometheus.BuildFQName(namespace, "", "max_listen_queue"),
94 | "The maximum number of requests in the queue of pending connections since FPM has started.",
95 | []string{"pool", "scrape_uri"},
96 | nil),
97 |
98 | listenQueueLength: prometheus.NewDesc(
99 | prometheus.BuildFQName(namespace, "", "listen_queue_length"),
100 | "The size of the socket queue of pending connections.",
101 | []string{"pool", "scrape_uri"},
102 | nil),
103 |
104 | idleProcesses: prometheus.NewDesc(
105 | prometheus.BuildFQName(namespace, "", "idle_processes"),
106 | "The number of idle processes.",
107 | []string{"pool", "scrape_uri"},
108 | nil),
109 |
110 | activeProcesses: prometheus.NewDesc(
111 | prometheus.BuildFQName(namespace, "", "active_processes"),
112 | "The number of active processes.",
113 | []string{"pool", "scrape_uri"},
114 | nil),
115 |
116 | totalProcesses: prometheus.NewDesc(
117 | prometheus.BuildFQName(namespace, "", "total_processes"),
118 | "The number of idle + active processes.",
119 | []string{"pool", "scrape_uri"},
120 | nil),
121 |
122 | maxActiveProcesses: prometheus.NewDesc(
123 | prometheus.BuildFQName(namespace, "", "max_active_processes"),
124 | "The maximum number of active processes since FPM has started.",
125 | []string{"pool", "scrape_uri"},
126 | nil),
127 |
128 | maxChildrenReached: prometheus.NewDesc(
129 | prometheus.BuildFQName(namespace, "", "max_children_reached"),
130 | "The number of times, the process limit has been reached, when pm tries to start more children (works only for pm 'dynamic' and 'ondemand').",
131 | []string{"pool", "scrape_uri"},
132 | nil),
133 |
134 | slowRequests: prometheus.NewDesc(
135 | prometheus.BuildFQName(namespace, "", "slow_requests"),
136 | "The number of requests that exceeded your 'request_slowlog_timeout' value.",
137 | []string{"pool", "scrape_uri"},
138 | nil),
139 |
140 | processRequests: prometheus.NewDesc(
141 | prometheus.BuildFQName(namespace, "", "process_requests"),
142 | "The number of requests the process has served.",
143 | []string{"pool", "child", "scrape_uri"},
144 | nil),
145 |
146 | processLastRequestMemory: prometheus.NewDesc(
147 | prometheus.BuildFQName(namespace, "", "process_last_request_memory"),
148 | "The max amount of memory the last request consumed.",
149 | []string{"pool", "child", "scrape_uri"},
150 | nil),
151 |
152 | processLastRequestCPU: prometheus.NewDesc(
153 | prometheus.BuildFQName(namespace, "", "process_last_request_cpu"),
154 | "The %cpu the last request consumed.",
155 | []string{"pool", "child", "scrape_uri"},
156 | nil),
157 |
158 | processRequestDuration: prometheus.NewDesc(
159 | prometheus.BuildFQName(namespace, "", "process_request_duration"),
160 | "The duration in microseconds of the requests.",
161 | []string{"pool", "child", "scrape_uri"},
162 | nil),
163 |
164 | processState: prometheus.NewDesc(
165 | prometheus.BuildFQName(namespace, "", "process_state"),
166 | "The state of the process (Idle, Running, ...).",
167 | []string{"pool", "child", "state", "scrape_uri"},
168 | nil),
169 | }
170 | }
171 |
172 | // Collect updates the Pools and sends the collected metrics to Prometheus
173 | func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
174 | e.mutex.Lock()
175 | defer e.mutex.Unlock()
176 |
177 | if err := e.PoolManager.Update(); err != nil {
178 | log.Error(err)
179 | }
180 |
181 | for _, pool := range e.PoolManager.Pools {
182 | ch <- prometheus.MustNewConstMetric(e.scrapeFailues, prometheus.CounterValue, float64(pool.ScrapeFailures), pool.Name, pool.Address)
183 |
184 | if pool.ScrapeError != nil {
185 | ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 0, pool.Name, pool.Address)
186 | log.Errorf("Error scraping PHP-FPM: %v", pool.ScrapeError)
187 | continue
188 | }
189 |
190 | active, idle, total := CountProcessState(pool.Processes)
191 | if !e.CountProcessState && (active != pool.ActiveProcesses || idle != pool.IdleProcesses) {
192 | log.Error("Inconsistent active and idle processes reported. Set `--phpfpm.fix-process-count` to have this calculated by php-fpm_exporter instead.")
193 | }
194 |
195 | if !e.CountProcessState {
196 | active = pool.ActiveProcesses
197 | idle = pool.IdleProcesses
198 | total = pool.TotalProcesses
199 | }
200 |
201 | ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 1, pool.Name, pool.Address)
202 | ch <- prometheus.MustNewConstMetric(e.startSince, prometheus.CounterValue, float64(pool.StartSince), pool.Name, pool.Address)
203 | ch <- prometheus.MustNewConstMetric(e.acceptedConnections, prometheus.CounterValue, float64(pool.AcceptedConnections), pool.Name, pool.Address)
204 | ch <- prometheus.MustNewConstMetric(e.listenQueue, prometheus.GaugeValue, float64(pool.ListenQueue), pool.Name, pool.Address)
205 | ch <- prometheus.MustNewConstMetric(e.maxListenQueue, prometheus.CounterValue, float64(pool.MaxListenQueue), pool.Name, pool.Address)
206 | ch <- prometheus.MustNewConstMetric(e.listenQueueLength, prometheus.GaugeValue, float64(pool.ListenQueueLength), pool.Name, pool.Address)
207 | ch <- prometheus.MustNewConstMetric(e.idleProcesses, prometheus.GaugeValue, float64(idle), pool.Name, pool.Address)
208 | ch <- prometheus.MustNewConstMetric(e.activeProcesses, prometheus.GaugeValue, float64(active), pool.Name, pool.Address)
209 | ch <- prometheus.MustNewConstMetric(e.totalProcesses, prometheus.GaugeValue, float64(total), pool.Name, pool.Address)
210 | ch <- prometheus.MustNewConstMetric(e.maxActiveProcesses, prometheus.CounterValue, float64(pool.MaxActiveProcesses), pool.Name, pool.Address)
211 | ch <- prometheus.MustNewConstMetric(e.maxChildrenReached, prometheus.CounterValue, float64(pool.MaxChildrenReached), pool.Name, pool.Address)
212 | ch <- prometheus.MustNewConstMetric(e.slowRequests, prometheus.CounterValue, float64(pool.SlowRequests), pool.Name, pool.Address)
213 |
214 | for childNumber, process := range pool.Processes {
215 | childName := fmt.Sprintf("%d", childNumber)
216 |
217 | states := map[string]int{
218 | PoolProcessRequestIdle: 0,
219 | PoolProcessRequestRunning: 0,
220 | PoolProcessRequestFinishing: 0,
221 | PoolProcessRequestReadingHeaders: 0,
222 | PoolProcessRequestInfo: 0,
223 | PoolProcessRequestEnding: 0,
224 | }
225 | states[process.State]++
226 |
227 | for stateName, inState := range states {
228 | ch <- prometheus.MustNewConstMetric(e.processState, prometheus.GaugeValue, float64(inState), pool.Name, childName, stateName, pool.Address)
229 | }
230 | ch <- prometheus.MustNewConstMetric(e.processRequests, prometheus.CounterValue, float64(process.Requests), pool.Name, childName, pool.Address)
231 | ch <- prometheus.MustNewConstMetric(e.processLastRequestMemory, prometheus.GaugeValue, float64(process.LastRequestMemory), pool.Name, childName, pool.Address)
232 | ch <- prometheus.MustNewConstMetric(e.processLastRequestCPU, prometheus.GaugeValue, process.LastRequestCPU, pool.Name, childName, pool.Address)
233 | ch <- prometheus.MustNewConstMetric(e.processRequestDuration, prometheus.GaugeValue, float64(process.RequestDuration), pool.Name, childName, pool.Address)
234 | }
235 | }
236 | }
237 |
238 | // Describe exposes the metric description to Prometheus
239 | func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
240 | ch <- e.up
241 | ch <- e.startSince
242 | ch <- e.acceptedConnections
243 | ch <- e.listenQueue
244 | ch <- e.maxListenQueue
245 | ch <- e.listenQueueLength
246 | ch <- e.idleProcesses
247 | ch <- e.activeProcesses
248 | ch <- e.totalProcesses
249 | ch <- e.maxActiveProcesses
250 | ch <- e.maxChildrenReached
251 | ch <- e.slowRequests
252 | ch <- e.processState
253 | ch <- e.processRequests
254 | ch <- e.processLastRequestMemory
255 | ch <- e.processLastRequestCPU
256 | ch <- e.processRequestDuration
257 | }
258 |
--------------------------------------------------------------------------------
/phpfpm/phpfpm.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2018 Enrico Stahn
2 | // Licensed under the Apache License, Version 2.0 (the "License");
3 | // you may not use this file except in compliance with the License.
4 | // You may obtain a copy of the License at
5 | //
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | // Package phpfpm provides convenient access to PHP-FPM pool data
15 | package phpfpm
16 |
17 | import (
18 | "encoding/json"
19 | "fmt"
20 | "io/ioutil"
21 | "net/url"
22 | "regexp"
23 | "strconv"
24 | "strings"
25 | "sync"
26 | "time"
27 |
28 | fcgiclient "github.com/tomasen/fcgi_client"
29 | )
30 |
31 | // PoolProcessRequestIdle defines a process that is idle.
32 | const PoolProcessRequestIdle string = "Idle"
33 |
34 | // PoolProcessRequestRunning defines a process that is running.
35 | const PoolProcessRequestRunning string = "Running"
36 |
37 | // PoolProcessRequestFinishing defines a process that is about to finish.
38 | const PoolProcessRequestFinishing string = "Finishing"
39 |
40 | // PoolProcessRequestReadingHeaders defines a process that is reading headers.
41 | const PoolProcessRequestReadingHeaders string = "Reading headers"
42 |
43 | // PoolProcessRequestInfo defines a process that is getting request information. Was changed in PHP 7.4 to PoolProcessRequestInfo74
44 | const PoolProcessRequestInfo string = "Getting request informations"
45 | const PoolProcessRequestInfo74 string = "Getting request information"
46 |
47 | // PoolProcessRequestEnding defines a process that is about to end.
48 | const PoolProcessRequestEnding string = "Ending"
49 |
50 | var log logger
51 |
52 | type logger interface {
53 | Info(ar ...interface{})
54 | Infof(string, ...interface{})
55 | Debug(ar ...interface{})
56 | Debugf(string, ...interface{})
57 | Error(ar ...interface{})
58 | Errorf(string, ...interface{})
59 | }
60 |
61 | // PoolManager manages all configured Pools
62 | type PoolManager struct {
63 | Pools []Pool `json:"pools"`
64 | }
65 |
66 | // Pool describes a single PHP-FPM pool that can be reached via a Socket or TCP address
67 | type Pool struct {
68 | // The address of the pool, e.g. tcp://127.0.0.1:9000 or unix:///tmp/php-fpm.sock
69 | Address string `json:"-"`
70 | ScrapeError error `json:"-"`
71 | ScrapeFailures int64 `json:"-"`
72 | Name string `json:"pool"`
73 | ProcessManager string `json:"process manager"`
74 | StartTime timestamp `json:"start time"`
75 | StartSince int64 `json:"start since"`
76 | AcceptedConnections int64 `json:"accepted conn"`
77 | ListenQueue int64 `json:"listen queue"`
78 | MaxListenQueue int64 `json:"max listen queue"`
79 | ListenQueueLength int64 `json:"listen queue len"`
80 | IdleProcesses int64 `json:"idle processes"`
81 | ActiveProcesses int64 `json:"active processes"`
82 | TotalProcesses int64 `json:"total processes"`
83 | MaxActiveProcesses int64 `json:"max active processes"`
84 | MaxChildrenReached int64 `json:"max children reached"`
85 | SlowRequests int64 `json:"slow requests"`
86 | Processes []PoolProcess `json:"processes"`
87 | }
88 |
89 | type requestDuration int64
90 |
91 | // PoolProcess describes a single PHP-FPM process. A pool can have multiple processes.
92 | type PoolProcess struct {
93 | PID int64 `json:"pid"`
94 | State string `json:"state"`
95 | StartTime int64 `json:"start time"`
96 | StartSince int64 `json:"start since"`
97 | Requests int64 `json:"requests"`
98 | RequestDuration requestDuration `json:"request duration"`
99 | RequestMethod string `json:"request method"`
100 | RequestURI string `json:"request uri"`
101 | ContentLength int64 `json:"content length"`
102 | User string `json:"user"`
103 | Script string `json:"script"`
104 | LastRequestCPU float64 `json:"last request cpu"`
105 | LastRequestMemory int64 `json:"last request memory"`
106 | }
107 |
108 | // PoolProcessStateCounter holds the calculated metrics for pool processes.
109 | type PoolProcessStateCounter struct {
110 | Running int64
111 | Idle int64
112 | Finishing int64
113 | ReadingHeaders int64
114 | Info int64
115 | Ending int64
116 | }
117 |
118 | // Add will add a pool to the pool manager based on the given URI.
119 | func (pm *PoolManager) Add(uri string) Pool {
120 | p := Pool{Address: uri}
121 | pm.Pools = append(pm.Pools, p)
122 | return p
123 | }
124 |
125 | // Update will run the pool.Update() method concurrently on all Pools.
126 | func (pm *PoolManager) Update() (err error) {
127 | wg := &sync.WaitGroup{}
128 |
129 | started := time.Now()
130 |
131 | for idx := range pm.Pools {
132 | wg.Add(1)
133 | go func(p *Pool) {
134 | defer wg.Done()
135 | if err := p.Update(); err != nil {
136 | log.Error(err)
137 | }
138 | }(&pm.Pools[idx])
139 | }
140 |
141 | wg.Wait()
142 |
143 | ended := time.Now()
144 |
145 | log.Debugf("Updated %v pool(s) in %v", len(pm.Pools), ended.Sub(started))
146 |
147 | return nil
148 | }
149 |
150 | // Update will connect to PHP-FPM and retrieve the latest data for the pool.
151 | func (p *Pool) Update() (err error) {
152 | p.ScrapeError = nil
153 |
154 | scheme, address, path, err := parseURL(p.Address)
155 | if err != nil {
156 | return p.error(err)
157 | }
158 |
159 | fcgi, err := fcgiclient.DialTimeout(scheme, address, time.Duration(3)*time.Second)
160 | if err != nil {
161 | return p.error(err)
162 | }
163 |
164 | defer fcgi.Close()
165 |
166 | env := map[string]string{
167 | "SCRIPT_FILENAME": path,
168 | "SCRIPT_NAME": path,
169 | "SERVER_SOFTWARE": "go / php-fpm_exporter",
170 | "REMOTE_ADDR": "127.0.0.1",
171 | "QUERY_STRING": "json&full",
172 | }
173 |
174 | resp, err := fcgi.Get(env)
175 | if err != nil {
176 | return p.error(err)
177 | }
178 |
179 | defer resp.Body.Close()
180 |
181 | content, err := ioutil.ReadAll(resp.Body)
182 | if err != nil {
183 | return p.error(err)
184 | }
185 |
186 | content = JSONResponseFixer(content)
187 |
188 | log.Debugf("Pool[%v]: %v", p.Address, string(content))
189 |
190 | if err = json.Unmarshal(content, &p); err != nil {
191 | log.Errorf("Pool[%v]: %v", p.Address, string(content))
192 | return p.error(err)
193 | }
194 |
195 | return nil
196 | }
197 |
198 | func (p *Pool) error(err error) error {
199 | p.ScrapeError = err
200 | p.ScrapeFailures++
201 | log.Error(err)
202 | return err
203 | }
204 |
205 | // JSONResponseFixer resolves encoding issues with PHP-FPMs JSON response
206 | func JSONResponseFixer(content []byte) []byte {
207 | c := string(content)
208 | re := regexp.MustCompile(`(,"request uri":)"(.*?)"(,"content length":)`)
209 | matches := re.FindAllStringSubmatch(c, -1)
210 |
211 | for _, match := range matches {
212 | requestURI, _ := json.Marshal(match[2])
213 |
214 | sold := match[0]
215 | snew := match[1] + string(requestURI) + match[3]
216 |
217 | c = strings.ReplaceAll(c, sold, snew)
218 | }
219 |
220 | return []byte(c)
221 | }
222 |
223 | // CountProcessState return the calculated metrics based on the reported processes.
224 | func CountProcessState(processes []PoolProcess) (active int64, idle int64, total int64) {
225 | for idx := range processes {
226 | switch processes[idx].State {
227 | case PoolProcessRequestRunning:
228 | active++
229 | case PoolProcessRequestIdle:
230 | idle++
231 | case PoolProcessRequestEnding:
232 | case PoolProcessRequestFinishing:
233 | case PoolProcessRequestInfo:
234 | case PoolProcessRequestInfo74:
235 | case PoolProcessRequestReadingHeaders:
236 | active++
237 | default:
238 | log.Errorf("Unknown process state '%v'", processes[idx].State)
239 | }
240 | }
241 |
242 | return active, idle, active + idle
243 | }
244 |
245 | // parseURL creates elements to be passed into fcgiclient.DialTimeout
246 | func parseURL(rawurl string) (scheme string, address string, path string, err error) {
247 | uri, err := url.Parse(rawurl)
248 | if err != nil {
249 | return uri.Scheme, uri.Host, uri.Path, err
250 | }
251 |
252 | scheme = uri.Scheme
253 |
254 | switch uri.Scheme {
255 | case "unix":
256 | result := strings.Split(uri.Path, ";")
257 | address = result[0]
258 | if len(result) > 1 {
259 | path = result[1]
260 | }
261 | default:
262 | address = uri.Host
263 | path = uri.Path
264 | }
265 |
266 | return
267 | }
268 |
269 | type timestamp time.Time
270 |
271 | // MarshalJSON customise JSON for timestamp
272 | func (t *timestamp) MarshalJSON() ([]byte, error) {
273 | ts := time.Time(*t).Unix()
274 | stamp := fmt.Sprint(ts)
275 | return []byte(stamp), nil
276 | }
277 |
278 | // UnmarshalJSON customise JSON for timestamp
279 | func (t *timestamp) UnmarshalJSON(b []byte) error {
280 | ts, err := strconv.Atoi(string(b))
281 | if err != nil {
282 | return err
283 | }
284 | *t = timestamp(time.Unix(int64(ts), 0))
285 | return nil
286 | }
287 |
288 | // This is because of bug in php-fpm that can return 'request duration' which can't
289 | // fit to int64. For details check links:
290 | // https://bugs.php.net/bug.php?id=62382
291 | // https://serverfault.com/questions/624977/huge-request-duration-value-for-a-particular-php-script
292 | func (rd *requestDuration) MarshalJSON() ([]byte, error) {
293 | stamp := fmt.Sprint(rd)
294 | return []byte(stamp), nil
295 | }
296 |
297 | func (rd *requestDuration) UnmarshalJSON(b []byte) error {
298 | rdc, err := strconv.Atoi(string(b))
299 | if err != nil {
300 | *rd = 0
301 | } else {
302 | *rd = requestDuration(rdc)
303 | }
304 | return nil
305 | }
306 |
307 | // SetLogger configures the used logger
308 | func SetLogger(logger logger) {
309 | log = logger
310 | }
311 |
--------------------------------------------------------------------------------
/phpfpm/phpfpm_test.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2018 Enrico Stahn
2 | // Licensed under the Apache License, Version 2.0 (the "License");
3 | // you may not use this file except in compliance with the License.
4 | // You may obtain a copy of the License at
5 | //
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package phpfpm
15 |
16 | import (
17 | "encoding/json"
18 | "testing"
19 |
20 | "github.com/stretchr/testify/assert"
21 | )
22 |
23 | func TestCountProcessState(t *testing.T) {
24 | processes := []PoolProcess{
25 | {State: PoolProcessRequestIdle},
26 | {State: PoolProcessRequestRunning},
27 | {State: PoolProcessRequestReadingHeaders},
28 | {State: PoolProcessRequestInfo},
29 | {State: PoolProcessRequestFinishing},
30 | {State: PoolProcessRequestEnding},
31 | }
32 |
33 | active, idle, total := CountProcessState(processes)
34 |
35 | assert.Equal(t, int64(2), active, "active processes")
36 | assert.Equal(t, int64(1), idle, "idle processes")
37 | assert.Equal(t, int64(3), total, "total processes")
38 | }
39 |
40 | // https://github.com/hipages/php-fpm_exporter/issues/10
41 | func TestCannotUnmarshalNumberIssue10(t *testing.T) {
42 | pool := Pool{}
43 | content := []byte(`{
44 | "pool":"www",
45 | "process manager":"dynamic",
46 | "start time":1519474655,
47 | "start since":302035,
48 | "accepted conn":44144,
49 | "listen queue":0,
50 | "max listen queue":1,
51 | "listen queue len":128,
52 | "idle processes":1,
53 | "active processes":1,
54 | "total processes":2,
55 | "max active processes":2,
56 | "max children reached":0,
57 | "slow requests":0,
58 | "processes":[
59 | {
60 | "pid":23,
61 | "state":"Idle",
62 | "start time":1519474655,
63 | "start since":302035,
64 | "requests":22071,
65 | "request duration":295,
66 | "request method":"GET",
67 | "request uri":"/status?json&full",
68 | "content length":0,
69 | "user":"-",
70 | "script":"-",
71 | "last request cpu":0.00,
72 | "last request memory":2097152
73 | },
74 | {
75 | "pid":24,
76 | "state":"Running",
77 | "start time":1519474655,
78 | "start since":302035,
79 | "requests":22073,
80 | "request duration":18446744073709550774,
81 | "request method":"GET",
82 | "request uri":"/status?json&full",
83 | "content length":0,
84 | "user":"-",
85 | "script":"-",
86 | "last request cpu":0.00,
87 | "last request memory":0
88 | }
89 | ]
90 | }`)
91 |
92 | err := json.Unmarshal(content, &pool)
93 |
94 | assert.Nil(t, err, "successfully unmarshal on invalid 'request duration'")
95 | assert.Equal(t, int(pool.Processes[0].RequestDuration), 295, "request duration set to 0 because it couldn't be deserialized")
96 | assert.Equal(t, int(pool.Processes[1].RequestDuration), 0, "request duration set to 0 because it couldn't be deserialized")
97 | }
98 |
99 | // https://github.com/hipages/php-fpm_exporter/issues/24
100 | func TestInvalidCharacterIssue24(t *testing.T) {
101 | // todo: Implement fcgi client dependency injection to allow testing of Pool.Update
102 | }
103 |
104 | func TestJsonResponseFixer(t *testing.T) {
105 | pool := Pool{}
106 | content := []byte(`{"pool":"www","process manager":"dynamic","start time":1528367006,"start since":15073840,"accepted conn":1577112,"listen queue":0,"max listen queue":0,"listen queue len":0,"idle processes":16,"active processes":1,"total processes":17,"max active processes":15,"max children reached":0,"slow requests":0, "processes":[{"pid":15873,"state":"Idle","start time":1543354120,"start since":86726,"requests":853,"request duration":5721,"request method":"GET","request uri":"/vbseo.php?ALTERNATE_TEMPLATES=|%20echo%20"Content-Type:%20text%2Fhtml"%3Becho%20""%20%3B%20id%00","content length":0,"user":"-","script":"/www/forum.example.com/vbseo.php","last request cpu":349.59,"last request memory":786432},{"pid":123,"state":"Idle","start time":1543354120,"start since":86726,"requests":853,"request duration":5721,"request method":"GET","request uri":"123/vbseo.php?ALTERNATE_TEMPLATES=|%20echo%20"Content-Type:%20text%2Fhtml"%3Becho%20""%20%3B%20id%00","content length":0,"user":"-","script":"/www/forum.example.com/vbseo.php","last request cpu":349.59,"last request memory":786432}]}`)
107 |
108 | content = JSONResponseFixer(content)
109 |
110 | err := json.Unmarshal(content, &pool)
111 |
112 | assert.Nil(t, err, "successfully unmarshal on invalid 'request uri'")
113 | assert.Equal(t, pool.Processes[0].RequestURI, `/vbseo.php?ALTERNATE_TEMPLATES=|%20echo%20"Content-Type:%20text%2Fhtml"%3Becho%20""%20%3B%20id%00`, "request uri couldn't be deserialized")
114 | assert.Equal(t, pool.Processes[1].RequestURI, `123/vbseo.php?ALTERNATE_TEMPLATES=|%20echo%20"Content-Type:%20text%2Fhtml"%3Becho%20""%20%3B%20id%00`, "request uri couldn't be deserialized")
115 | }
116 |
117 | func TestParseURL(t *testing.T) {
118 | var uris = []struct {
119 | in string
120 | out []string
121 | err error
122 | }{
123 | {"tcp://127.0.0.1:9000/status", []string{"tcp", "127.0.0.1:9000", "/status"}, nil},
124 | {"tcp://127.0.0.1", []string{"tcp", "127.0.0.1", ""}, nil},
125 | {"unix:///tmp/php.sock;/status", []string{"unix", "/tmp/php.sock", "/status"}, nil},
126 | {"unix:///tmp/php.sock", []string{"unix", "/tmp/php.sock", ""}, nil},
127 | }
128 |
129 | for _, u := range uris {
130 | scheme, address, path, err := parseURL(u.in)
131 | assert.Equal(t, u.err, err)
132 | assert.Equal(t, u.out, []string{scheme, address, path})
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "config:base",
4 | "group:recommended"
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/sonar-project.properties:
--------------------------------------------------------------------------------
1 | sonar.organization=hipages
2 | sonar.projectKey=hipages_php-fpm_exporter
3 |
4 | sonar.sources=.
5 | sonar.exclusions=**/*_test.go,**/vendor/**,**/testdata/*
6 |
7 | sonar.tests=.
8 | sonar.test.inclusions=**/*_test.go
9 | sonar.test.exclusions=**/vendor/**
10 | sonar.go.coverage.reportPaths=cover.out
11 |
--------------------------------------------------------------------------------
/test/docker-compose-e2e.yml:
--------------------------------------------------------------------------------
1 | version: "3"
2 |
3 | services:
4 |
5 | phpfpm1:
6 | image: hipages/php
7 | ports:
8 | - "9031:9000"
9 | environment:
10 | PHP_FPM_PM_STATUS_PATH: "/status"
11 |
12 | phpfpm2:
13 | image: hipages/php
14 | ports:
15 | - "9032:9000"
16 | environment:
17 | PHP_FPM_PM_STATUS_PATH: "/status"
18 |
19 | phpfpm3:
20 | image: hipages/php
21 | ports:
22 | - "9033:9000"
23 | environment:
24 | PHP_FPM_PM_STATUS_PATH: "/status"
25 |
26 | exporter:
27 | image: hipages/php-fpm_exporter:latest
28 | ports:
29 | - "9253:9253"
30 | environment:
31 | PHP_FPM_SCRAPE_URI: "tcp://phpfpm1:9000/status,tcp://phpfpm2:9000/status,tcp://phpfpm3:9000/status"
32 | PHP_FPM_LOG_LEVEL: "debug"
33 |
--------------------------------------------------------------------------------
/test/docker-compose-local.yml:
--------------------------------------------------------------------------------
1 | version: "3"
2 |
3 | services:
4 |
5 | prometheus:
6 | image: quay.io/prometheus/prometheus:latest
7 | ports:
8 | - 9090:9090
9 | volumes:
10 | - "./prometheus.yml:/etc/prometheus/prometheus.yml"
11 |
12 | phpfpm:
13 | image: hipages/php
14 | ports:
15 | - "9000:9000"
16 | environment:
17 | PHP_FPM_PM_STATUS_PATH: "/status"
18 |
19 | phpfpm1:
20 | image: hipages/php
21 | ports:
22 | - "9001:9001"
23 | environment:
24 | PHP_FPM_PM_STATUS_PATH: "/status"
25 |
26 | phpfpm2:
27 | image: hipages/php
28 | ports:
29 | - "9002:9002"
30 | environment:
31 | PHP_FPM_PM_STATUS_PATH: "/status"
32 |
--------------------------------------------------------------------------------
/test/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3"
2 |
3 | services:
4 |
5 | prometheus:
6 | image: quay.io/prometheus/prometheus:latest
7 | ports:
8 | - 9090:9090
9 | volumes:
10 | - "./prometheus.yml:/etc/prometheus/prometheus.yml"
11 |
12 | phpfpm:
13 | image: hipages/php
14 | environment:
15 | PHP_FPM_PM_STATUS_PATH: "/status"
16 |
17 | exporter:
18 | image: hipages/php-fpm_exporter:latest
19 | ports:
20 | - "9253:9253"
21 | environment:
22 | PHP_FPM_SCRAPE_URI: "tcp://phpfpm:9000/status"
23 | PHP_FPM_LOG_LEVEL: "debug"
24 |
--------------------------------------------------------------------------------
/test/e2e.bats:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bats
2 |
3 | load '/usr/local/lib/bats-support/load.bash'
4 | load '/usr/local/lib/bats-assert/load.bash'
5 |
6 | setup () {
7 | docker-compose -f ./test/docker-compose-e2e.yml up -d
8 | # Workaround to wait for docker to start containers
9 | sleep 5
10 | #go run main.go server --phpfpm.scrape-uri tcp://127.0.0.1:9031/status,tcp://127.0.0.1:9032/status 3>&- &
11 | }
12 |
13 | teardown() {
14 | docker-compose -f ./test/docker-compose-e2e.yml stop
15 | docker-compose -f ./test/docker-compose-e2e.yml rm -f
16 | docker-compose -f ./test/docker-compose-e2e.yml down --volumes
17 | }
18 |
19 | @test "Should have metrics endpoint" {
20 | run curl -sSL http://localhost:9253/metrics
21 | [ "$status" -eq 0 ]
22 | }
23 |
24 | @test "Should have metric phpfpm_up" {
25 | run curl -sSL http://localhost:9253/metrics
26 | assert_output --partial '# TYPE phpfpm_up gauge'
27 | }
28 |
29 | @test "Should have scraped multiple PHP-FPM pools" {
30 | run curl -sSL http://localhost:9253/metrics
31 | assert_output --partial 'phpfpm_up{pool="www",scrape_uri="tcp://phpfpm1:9000/status"} 1'
32 | assert_output --partial 'phpfpm_up{pool="www",scrape_uri="tcp://phpfpm2:9000/status"} 1'
33 | assert_output --partial 'phpfpm_up{pool="www",scrape_uri="tcp://phpfpm3:9000/status"} 1'
34 | }
35 |
36 | @test "Should exit cleanly" {
37 | run docker-compose -f ./test/docker-compose-e2e.yml stop exporter
38 | docker-compose -f ./test/docker-compose-e2e.yml ps exporter | grep -q "Exit 0"
39 | }
40 |
--------------------------------------------------------------------------------
/test/prometheus.yml:
--------------------------------------------------------------------------------
1 | # my global config
2 | global:
3 | scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
4 | evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
5 | # scrape_timeout is set to the global default (10s).
6 |
7 | # Alertmanager configuration
8 | alerting:
9 | alertmanagers:
10 | - static_configs:
11 | - targets:
12 | # - alertmanager:9093
13 |
14 | # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
15 | rule_files:
16 | # - "first_rules.yml"
17 | # - "second_rules.yml"
18 |
19 | # A scrape configuration containing exactly one endpoint to scrape:
20 | # Here it's Prometheus itself.
21 | scrape_configs:
22 | # The job name is added as a label `job=` to any timeseries scraped from this config.
23 | - job_name: 'prometheus'
24 |
25 | # metrics_path defaults to '/metrics'
26 | # scheme defaults to 'http'.
27 |
28 | static_configs:
29 | - targets: ['localhost:9090']
30 |
31 | - job_name: 'phpfpm'
32 |
33 | scrape_interval: 2s
34 | scrape_timeout: 1s
35 |
36 | static_configs:
37 | - targets: ['exporter:9253']
38 |
--------------------------------------------------------------------------------