mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-10-22 05:45:07 +02:00
Compare commits
275 Commits
v0.3
...
check_file
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d210f02603 | ||
|
|
b9e6f50d5f | ||
|
|
d15eba8fe8 | ||
|
|
f83a342e28 | ||
|
|
03d5486413 | ||
|
|
ee4e1baf5b | ||
|
|
94c80307e8 | ||
|
|
f859fe178d | ||
|
|
0ff8c8616e | ||
|
|
32e93b362e | ||
|
|
1b61b5dae4 | ||
|
|
160c3cde47 | ||
|
|
e7d76dd0d8 | ||
|
|
482ae046cb | ||
|
|
d00b14f3e8 | ||
|
|
4fd8c87157 | ||
|
|
1e2e43742f | ||
|
|
5ca669951f | ||
|
|
02344f30a4 | ||
|
|
c2c8f3c73e | ||
|
|
b3f1b63617 | ||
|
|
100d306473 | ||
|
|
ea04b7ed28 | ||
|
|
31994f44fa | ||
|
|
708e145020 | ||
|
|
d0af494149 | ||
|
|
95c0803a3c | ||
|
|
87309fcd2b | ||
|
|
8915c2fd5d | ||
|
|
27faafef78 | ||
|
|
7840de7b82 | ||
|
|
21646e1edf | ||
|
|
8837ff4474 | ||
|
|
8e8be09ed9 | ||
|
|
51dda886f1 | ||
|
|
c96021c7cc | ||
|
|
8f336c1bb7 | ||
|
|
7d3f67f15b | ||
|
|
f6c94e32b3 | ||
|
|
2e7990f87d | ||
|
|
f496db4905 | ||
|
|
6ab45dd3ec | ||
|
|
9df1054e32 | ||
|
|
e76eaa86ad | ||
|
|
262f0c6a86 | ||
|
|
b488ff76b1 | ||
|
|
e42b41f264 | ||
|
|
195d0794b0 | ||
|
|
3d7bb4cdd7 | ||
|
|
94b086acf0 | ||
|
|
ec570f884c | ||
|
|
abd49a377c | ||
|
|
1ba08cd148 | ||
|
|
94c4153a95 | ||
|
|
de2e522f52 | ||
|
|
10df95e3f2 | ||
|
|
84e019c693 | ||
|
|
ff0833c413 | ||
|
|
b0423b842d | ||
|
|
6c10c9741a | ||
|
|
200e6d6f42 | ||
|
|
89cfa861cb | ||
|
|
7a0e4726e1 | ||
|
|
6dbddb4450 | ||
|
|
2bd386dae7 | ||
|
|
162cce0fda | ||
|
|
155d1b9acf | ||
|
|
c9b9752b6a | ||
|
|
3c8a5e434f | ||
|
|
efd4f5feb4 | ||
|
|
a1f4dd6a6c | ||
|
|
d55e579195 | ||
|
|
b78e83b055 | ||
|
|
56b41a9e57 | ||
|
|
ae98807ace | ||
|
|
31a8e63d72 | ||
|
|
6f1f33f3a5 | ||
|
|
a29f0c7e3b | ||
|
|
4fb6ac0140 | ||
|
|
5918f96fd8 | ||
|
|
8cb87a2165 | ||
|
|
3e91a37dee | ||
|
|
ed68baeada | ||
|
|
888db31dbf | ||
|
|
c938d32629 | ||
|
|
d5daf54d4f | ||
|
|
18bffd7c14 | ||
|
|
bd0105b370 | ||
|
|
b1a8674c4c | ||
|
|
234ad3c54e | ||
|
|
7bb80780e0 | ||
|
|
e66d52bb32 | ||
|
|
9840d0193d | ||
|
|
ce7eef8d30 | ||
|
|
92e45ca62c | ||
|
|
fd10a279fc | ||
|
|
9e63d0ea59 | ||
|
|
f0da07310b | ||
|
|
76bb033a88 | ||
|
|
0f35469168 | ||
|
|
e79601e2e8 | ||
|
|
317d36c9dd | ||
|
|
821d104656 | ||
|
|
deb1bcfa2f | ||
|
|
7a67d5e25f | ||
|
|
be20f956c2 | ||
|
|
9ae0806aa9 | ||
|
|
4bd71224df | ||
|
|
6bf3bfd10a | ||
|
|
0fbff00996 | ||
|
|
8849824ba9 | ||
|
|
ed511b7c09 | ||
|
|
a0acf01dc3 | ||
|
|
5b6a2b9018 | ||
|
|
58461f1f72 | ||
|
|
c09d8fb118 | ||
|
|
3438972237 | ||
|
|
8a3446a596 | ||
|
|
88fabc2e83 | ||
|
|
503705d442 | ||
|
|
7ccbf1ebe2 | ||
|
|
60ef0ed116 | ||
|
|
a8beec29cc | ||
|
|
0dd430e7e9 | ||
|
|
f7b39d027b | ||
|
|
eaf8b1941d | ||
|
|
62f6e4151a | ||
|
|
acd092a977 | ||
|
|
6eb8e3a1f5 | ||
|
|
8ba33568a6 | ||
|
|
2ca0359744 | ||
|
|
a2f0bc37d4 | ||
|
|
cfcde9b23b | ||
|
|
c7d692e27f | ||
|
|
c312093d2b | ||
|
|
7438b9d245 | ||
|
|
32bb9c5fc0 | ||
|
|
f5ad45e49f | ||
|
|
ea33d45d8e | ||
|
|
251ae8e879 | ||
|
|
edd33d5810 | ||
|
|
88b3fe1e41 | ||
|
|
96b4a2aec1 | ||
|
|
4b5c2f4e37 | ||
|
|
f818bf4c11 | ||
|
|
aedc1be277 | ||
|
|
c75d394e11 | ||
|
|
bae36473f7 | ||
|
|
b3c27e0af5 | ||
|
|
09b740b82e | ||
|
|
2adf9484a3 | ||
|
|
27f17b88af | ||
|
|
b2bc7b95d3 | ||
|
|
f79b7b5e2b | ||
|
|
b16343e5e2 | ||
|
|
4fa37a58f2 | ||
|
|
addbfd40a1 | ||
|
|
04819d9db2 | ||
|
|
9ccc5a6ca7 | ||
|
|
b7dcbaebcf | ||
|
|
a3ac8f2ead | ||
|
|
8e7143a20a | ||
|
|
3a10f7cfdb | ||
|
|
0ca6d1a794 | ||
|
|
580d21d8bb | ||
|
|
31a38bc17d | ||
|
|
dbdec1eab8 | ||
|
|
0d31ec481b | ||
|
|
e22c3287e9 | ||
|
|
8d85bd53f1 | ||
|
|
b732b2d739 | ||
|
|
bef807dd44 | ||
|
|
659d0115c0 | ||
|
|
e13695307f | ||
|
|
4ed07cad77 | ||
|
|
ad5dbd85ea | ||
|
|
132ebabd45 | ||
|
|
f8d91d9cf1 | ||
|
|
cc84a94647 | ||
|
|
838b8d824d | ||
|
|
7ddc889f06 | ||
|
|
500685672b | ||
|
|
d4c89a4206 | ||
|
|
826f364772 | ||
|
|
5df550b208 | ||
|
|
5c34805918 | ||
|
|
1db5f3b29a | ||
|
|
0623691bab | ||
|
|
9886f14d14 | ||
|
|
857903be2b | ||
|
|
80d92d6d28 | ||
|
|
8068e59818 | ||
|
|
8abedac0fe | ||
|
|
ee4bd558f1 | ||
|
|
186a62a86b | ||
|
|
e098c33179 | ||
|
|
38d4e0a730 | ||
|
|
54d14519ca | ||
|
|
c35ac9dba8 | ||
|
|
c019f8e7ad | ||
|
|
fb6f6a4daa | ||
|
|
9d6d0dbd93 | ||
|
|
c2d4272fdf | ||
|
|
8c73095548 | ||
|
|
31c5c89a5a | ||
|
|
bf9c7e1830 | ||
|
|
48d34bf564 | ||
|
|
a1d85fa886 | ||
|
|
96ee16398e | ||
|
|
e7b8088c41 | ||
|
|
017cd58247 | ||
|
|
36dd440864 | ||
|
|
7b098e0b1b | ||
|
|
229a57b16a | ||
|
|
70a9530aba | ||
|
|
2f0b6057ca | ||
|
|
69f7c19659 | ||
|
|
ecdb4c1bcf | ||
|
|
4d5b1adbc8 | ||
|
|
28348bd108 | ||
|
|
a3b9d8a90b | ||
|
|
7e43e9171e | ||
|
|
5d25a7bf12 | ||
|
|
83b4343310 | ||
|
|
f1d3cabdc6 | ||
|
|
4763733d8d | ||
|
|
2a014b6fba | ||
|
|
16e898ecca | ||
|
|
50479f9325 | ||
|
|
e0e91844bc | ||
|
|
296225f3a8 | ||
|
|
43bcce6fb5 | ||
|
|
622e94ae0e | ||
|
|
c506114480 | ||
|
|
657543dded | ||
|
|
4851382ad7 | ||
|
|
b66fdd1436 | ||
|
|
3f76947f54 | ||
|
|
c182d295f4 | ||
|
|
beebcd7145 | ||
|
|
57629a2e0a | ||
|
|
082eea525a | ||
|
|
aa1afd745e | ||
|
|
2b8266d1d2 | ||
|
|
992b19d354 | ||
|
|
0b08ca9ae0 | ||
|
|
f6dae7c013 | ||
|
|
1de3dda7be | ||
|
|
73f22c1041 | ||
|
|
c9b8fcdaa7 | ||
|
|
17f37583fc | ||
|
|
fb9ea992ea | ||
|
|
21edca5f88 | ||
|
|
d835724d93 | ||
|
|
3cf2f69a07 | ||
|
|
e7f7e68095 | ||
|
|
c5082bbffe | ||
|
|
c0e600269a | ||
|
|
f2486abeab | ||
|
|
21864e0ac4 | ||
|
|
3157386b3e | ||
|
|
8c668fcc6f | ||
|
|
1961edc659 | ||
|
|
547bc0461f | ||
|
|
7f62975a68 | ||
|
|
5e64c01c9d | ||
|
|
f1d2828e1d | ||
|
|
07af660e50 | ||
|
|
af4c468ab5 | ||
|
|
b3030a8d44 | ||
|
|
db04c8fbae | ||
|
|
4c1263312b | ||
|
|
940623585c | ||
|
|
87ecb12c6f | ||
|
|
ae64eddcc8 |
4
.github/ci-config.json
vendored
4
.github/ci-config.json
vendored
@@ -3,6 +3,6 @@
|
|||||||
"collectors" : ".github/ci-collectors.json",
|
"collectors" : ".github/ci-collectors.json",
|
||||||
"receivers" : ".github/ci-receivers.json",
|
"receivers" : ".github/ci-receivers.json",
|
||||||
"router" : ".github/ci-router.json",
|
"router" : ".github/ci-router.json",
|
||||||
"interval": 5,
|
"interval": "5s",
|
||||||
"duration": 1
|
"duration": "1s"
|
||||||
}
|
}
|
||||||
|
|||||||
4
.github/ci-sinks.json
vendored
4
.github/ci-sinks.json
vendored
@@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
"testoutput" : {
|
"testoutput" : {
|
||||||
"type" : "stdout",
|
"type" : "stdout",
|
||||||
"meta_as_tags" : true
|
"meta_as_tags" : [
|
||||||
|
"unit"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
64
.github/workflows/AlmaLinux.yml
vendored
64
.github/workflows/AlmaLinux.yml
vendored
@@ -1,64 +0,0 @@
|
|||||||
# See: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
|
|
||||||
|
|
||||||
# Workflow name
|
|
||||||
name: AlmaLinux 8.5 RPM build
|
|
||||||
|
|
||||||
# Run on tag push
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '**'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
#
|
|
||||||
# Build on AlmaLinux 8.5 using go-toolset
|
|
||||||
#
|
|
||||||
AlmaLinux-RPM-build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
# See: https://hub.docker.com/_/almalinux
|
|
||||||
container: almalinux:8.5
|
|
||||||
steps:
|
|
||||||
|
|
||||||
# Use dnf to install development packages
|
|
||||||
- name: Install development packages
|
|
||||||
run: dnf --assumeyes group install "Development Tools" "RPM Development Tools"
|
|
||||||
|
|
||||||
# Checkout git repository and submodules
|
|
||||||
# fetch-depth must be 0 to use git describe
|
|
||||||
# See: https://github.com/marketplace/actions/checkout
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: recursive
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
# Use dnf to install build dependencies
|
|
||||||
- name: Install build dependencies
|
|
||||||
run: dnf --assumeyes builddep scripts/cc-metric-collector.spec
|
|
||||||
|
|
||||||
- name: RPM build MetricCollector
|
|
||||||
id: rpmbuild
|
|
||||||
run: make RPM
|
|
||||||
|
|
||||||
# See: https://github.com/actions/upload-artifact
|
|
||||||
- name: Save RPM as artifact
|
|
||||||
uses: actions/upload-artifact@v2
|
|
||||||
with:
|
|
||||||
name: cc-metric-collector RPM for AlmaLinux 8.5
|
|
||||||
path: ${{ steps.rpmbuild.outputs.RPM }}
|
|
||||||
- name: Save SRPM as artifact
|
|
||||||
uses: actions/upload-artifact@v2
|
|
||||||
with:
|
|
||||||
name: cc-metric-collector SRPM for AlmaLinux 8.5
|
|
||||||
path: ${{ steps.rpmbuild.outputs.SRPM }}
|
|
||||||
|
|
||||||
# See: https://github.com/softprops/action-gh-release
|
|
||||||
- name: Release
|
|
||||||
uses: softprops/action-gh-release@v1
|
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
|
||||||
with:
|
|
||||||
name: cc-metric-collector-${{github.ref_name}}
|
|
||||||
files: |
|
|
||||||
${{ steps.rpmbuild.outputs.RPM }}
|
|
||||||
${{ steps.rpmbuild.outputs.SRPM }}
|
|
||||||
64
.github/workflows/RedHatUniversalBaseImage.yml
vendored
64
.github/workflows/RedHatUniversalBaseImage.yml
vendored
@@ -1,64 +0,0 @@
|
|||||||
# See: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
|
|
||||||
|
|
||||||
# Workflow name
|
|
||||||
name: Red Hat Universal Base Image 8 RPM build
|
|
||||||
|
|
||||||
# Run on tag push
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '**'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
#
|
|
||||||
# Build on UBI 8 using go-toolset
|
|
||||||
#
|
|
||||||
UBI-8-RPM-build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
# See: https://catalog.redhat.com/software/containers/ubi8/ubi/5c359854d70cc534b3a3784e?container-tabs=gti
|
|
||||||
container: registry.access.redhat.com/ubi8/ubi:8.5-226.1645809065
|
|
||||||
steps:
|
|
||||||
|
|
||||||
# Use dnf to install development packages
|
|
||||||
- name: Install development packages
|
|
||||||
run: dnf --assumeyes --disableplugin=subscription-manager install rpm-build go-srpm-macros rpm-build-libs rpm-libs gcc make python38 git
|
|
||||||
|
|
||||||
# Checkout git repository and submodules
|
|
||||||
# fetch-depth must be 0 to use git describe
|
|
||||||
# See: https://github.com/marketplace/actions/checkout
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: recursive
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
# Use dnf to install build dependencies
|
|
||||||
- name: Install build dependencies
|
|
||||||
run: dnf --assumeyes --disableplugin=subscription-manager builddep scripts/cc-metric-collector.spec
|
|
||||||
|
|
||||||
- name: RPM build MetricCollector
|
|
||||||
id: rpmbuild
|
|
||||||
run: make RPM
|
|
||||||
|
|
||||||
# See: https://github.com/actions/upload-artifact
|
|
||||||
- name: Save RPM as artifact
|
|
||||||
uses: actions/upload-artifact@v2
|
|
||||||
with:
|
|
||||||
name: cc-metric-collector RPM for UBI 8
|
|
||||||
path: ${{ steps.rpmbuild.outputs.RPM }}
|
|
||||||
- name: Save SRPM as artifact
|
|
||||||
uses: actions/upload-artifact@v2
|
|
||||||
with:
|
|
||||||
name: cc-metric-collector SRPM for UBI 8
|
|
||||||
path: ${{ steps.rpmbuild.outputs.SRPM }}
|
|
||||||
|
|
||||||
# See: https://github.com/softprops/action-gh-release
|
|
||||||
- name: Release
|
|
||||||
uses: softprops/action-gh-release@v1
|
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
|
||||||
with:
|
|
||||||
name: cc-metric-collector-${{github.ref_name}}
|
|
||||||
files: |
|
|
||||||
${{ steps.rpmbuild.outputs.RPM }}
|
|
||||||
${{ steps.rpmbuild.outputs.SRPM }}
|
|
||||||
504
.github/workflows/Release.yml
vendored
Normal file
504
.github/workflows/Release.yml
vendored
Normal file
@@ -0,0 +1,504 @@
|
|||||||
|
# See: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
|
||||||
|
|
||||||
|
# Workflow name
|
||||||
|
name: Release
|
||||||
|
|
||||||
|
# Run on tag push
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '**'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build on AlmaLinux 8 using go-toolset
|
||||||
|
#
|
||||||
|
AlmaLinux8-RPM-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# See: https://hub.docker.com/_/almalinux
|
||||||
|
container: almalinux:8
|
||||||
|
# The job outputs link to the outputs of the 'rpmrename' step
|
||||||
|
# Only job outputs can be used in child jobs
|
||||||
|
outputs:
|
||||||
|
rpm : ${{steps.rpmrename.outputs.RPM}}
|
||||||
|
srpm : ${{steps.rpmrename.outputs.SRPM}}
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Use dnf to install development packages
|
||||||
|
- name: Install development packages
|
||||||
|
run: |
|
||||||
|
dnf --assumeyes group install "Development Tools" "RPM Development Tools"
|
||||||
|
dnf --assumeyes install wget openssl-devel diffutils delve which
|
||||||
|
|
||||||
|
# Checkout git repository and submodules
|
||||||
|
# fetch-depth must be 0 to use git describe
|
||||||
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
# - name: Setup Golang
|
||||||
|
# uses: actions/setup-go@v5
|
||||||
|
# with:
|
||||||
|
# go-version: 'stable'
|
||||||
|
- name: Setup Golang
|
||||||
|
run: |
|
||||||
|
dnf --assumeyes --disableplugin=subscription-manager install \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/go-toolset-1.22.9-1.module_el8.10.0+3938+8c723e16.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/golang-1.22.9-1.module_el8.10.0+3938+8c723e16.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/golang-bin-1.22.9-1.module_el8.10.0+3938+8c723e16.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/golang-src-1.22.9-1.module_el8.10.0+3938+8c723e16.noarch.rpm
|
||||||
|
|
||||||
|
- name: RPM build MetricCollector
|
||||||
|
id: rpmbuild
|
||||||
|
run: |
|
||||||
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
make RPM
|
||||||
|
|
||||||
|
# AlmaLinux 8 is a derivate of RedHat Enterprise Linux 8 (UBI8),
|
||||||
|
# so the created RPM both contain the substring 'el8' in the RPM file names
|
||||||
|
# This step replaces the substring 'el8' to 'alma8'. It uses the move operation
|
||||||
|
# because it is unclear whether the default AlmaLinux 8 container contains the
|
||||||
|
# 'rename' command. This way we also get the new names for output.
|
||||||
|
- name: Rename RPMs (s/el8/alma8/)
|
||||||
|
id: rpmrename
|
||||||
|
run: |
|
||||||
|
OLD_RPM="${{steps.rpmbuild.outputs.RPM}}"
|
||||||
|
OLD_SRPM="${{steps.rpmbuild.outputs.SRPM}}"
|
||||||
|
NEW_RPM="${OLD_RPM/el8/alma8}"
|
||||||
|
NEW_SRPM=${OLD_SRPM/el8/alma8}
|
||||||
|
mv "${OLD_RPM}" "${NEW_RPM}"
|
||||||
|
mv "${OLD_SRPM}" "${NEW_SRPM}"
|
||||||
|
echo "SRPM=${NEW_SRPM}" >> $GITHUB_OUTPUT
|
||||||
|
echo "RPM=${NEW_RPM}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
# See: https://github.com/actions/upload-artifact
|
||||||
|
- name: Save RPM as artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector RPM for AlmaLinux 8
|
||||||
|
path: ${{ steps.rpmrename.outputs.RPM }}
|
||||||
|
overwrite: true
|
||||||
|
- name: Save SRPM as artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector SRPM for AlmaLinux 8
|
||||||
|
path: ${{ steps.rpmrename.outputs.SRPM }}
|
||||||
|
overwrite: true
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build on AlmaLinux 9 using go-toolset
|
||||||
|
#
|
||||||
|
AlmaLinux9-RPM-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# See: https://hub.docker.com/_/almalinux
|
||||||
|
container: almalinux:9
|
||||||
|
# The job outputs link to the outputs of the 'rpmrename' step
|
||||||
|
# Only job outputs can be used in child jobs
|
||||||
|
outputs:
|
||||||
|
rpm : ${{steps.rpmrename.outputs.RPM}}
|
||||||
|
srpm : ${{steps.rpmrename.outputs.SRPM}}
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Use dnf to install development packages
|
||||||
|
- name: Install development packages
|
||||||
|
run: |
|
||||||
|
dnf --assumeyes group install "Development Tools" "RPM Development Tools"
|
||||||
|
dnf --assumeyes install wget openssl-devel diffutils delve which
|
||||||
|
|
||||||
|
# Checkout git repository and submodules
|
||||||
|
# fetch-depth must be 0 to use git describe
|
||||||
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
# - name: Setup Golang
|
||||||
|
# uses: actions/setup-go@v5
|
||||||
|
# with:
|
||||||
|
# go-version: 'stable'
|
||||||
|
- name: Setup Golang
|
||||||
|
run: |
|
||||||
|
dnf --assumeyes --disableplugin=subscription-manager install \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/go-toolset-1.22.7-2.el9_5.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-1.22.7-2.el9_5.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-bin-1.22.7-2.el9_5.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-src-1.22.7-2.el9_5.noarch.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-race-1.22.7-2.el9_5.x86_64.rpm
|
||||||
|
|
||||||
|
- name: RPM build MetricCollector
|
||||||
|
id: rpmbuild
|
||||||
|
run: |
|
||||||
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
make RPM
|
||||||
|
|
||||||
|
# AlmaLinux 9 is a derivate of RedHat Enterprise Linux 8 (UBI8),
|
||||||
|
# so the created RPM both contain the substring 'el9' in the RPM file names
|
||||||
|
# This step replaces the substring 'el8' to 'alma8'. It uses the move operation
|
||||||
|
# because it is unclear whether the default AlmaLinux 8 container contains the
|
||||||
|
# 'rename' command. This way we also get the new names for output.
|
||||||
|
- name: Rename RPMs (s/el9/alma9/)
|
||||||
|
id: rpmrename
|
||||||
|
run: |
|
||||||
|
OLD_RPM="${{steps.rpmbuild.outputs.RPM}}"
|
||||||
|
OLD_SRPM="${{steps.rpmbuild.outputs.SRPM}}"
|
||||||
|
NEW_RPM="${OLD_RPM/el9/alma9}"
|
||||||
|
NEW_SRPM=${OLD_SRPM/el9/alma9}
|
||||||
|
mv "${OLD_RPM}" "${NEW_RPM}"
|
||||||
|
mv "${OLD_SRPM}" "${NEW_SRPM}"
|
||||||
|
echo "SRPM=${NEW_SRPM}" >> $GITHUB_OUTPUT
|
||||||
|
echo "RPM=${NEW_RPM}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
# See: https://github.com/actions/upload-artifact
|
||||||
|
- name: Save RPM as artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector RPM for AlmaLinux 9
|
||||||
|
path: ${{ steps.rpmrename.outputs.RPM }}
|
||||||
|
overwrite: true
|
||||||
|
- name: Save SRPM as artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector SRPM for AlmaLinux 9
|
||||||
|
path: ${{ steps.rpmrename.outputs.SRPM }}
|
||||||
|
overwrite: true
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build on UBI 8 using go-toolset
|
||||||
|
#
|
||||||
|
UBI-8-RPM-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# See: https://catalog.redhat.com/software/containers/ubi8/ubi/5c35984d70cc534b3a3784e?container-tabs=gti
|
||||||
|
container: registry.access.redhat.com/ubi8/ubi:8.8-1032.1692772289
|
||||||
|
# The job outputs link to the outputs of the 'rpmbuild' step
|
||||||
|
outputs:
|
||||||
|
rpm : ${{steps.rpmbuild.outputs.RPM}}
|
||||||
|
srpm : ${{steps.rpmbuild.outputs.SRPM}}
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Use dnf to install development packages
|
||||||
|
- name: Install development packages
|
||||||
|
run: dnf --assumeyes --disableplugin=subscription-manager install rpm-build go-srpm-macros rpm-build-libs rpm-libs gcc make python38 git wget openssl-devel diffutils delve which
|
||||||
|
|
||||||
|
# Checkout git repository and submodules
|
||||||
|
# fetch-depth must be 0 to use git describe
|
||||||
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
# - name: Setup Golang
|
||||||
|
# uses: actions/setup-go@v5
|
||||||
|
# with:
|
||||||
|
# go-version: 'stable'
|
||||||
|
- name: Setup Golang
|
||||||
|
run: |
|
||||||
|
dnf --assumeyes --disableplugin=subscription-manager install \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/go-toolset-1.22.9-1.module_el8.10.0+3938+8c723e16.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/golang-1.22.9-1.module_el8.10.0+3938+8c723e16.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/golang-bin-1.22.9-1.module_el8.10.0+3938+8c723e16.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/golang-src-1.22.9-1.module_el8.10.0+3938+8c723e16.noarch.rpm
|
||||||
|
|
||||||
|
- name: RPM build MetricCollector
|
||||||
|
id: rpmbuild
|
||||||
|
run: |
|
||||||
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
make RPM
|
||||||
|
|
||||||
|
# See: https://github.com/actions/upload-artifact
|
||||||
|
- name: Save RPM as artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector RPM for UBI 8
|
||||||
|
path: ${{ steps.rpmbuild.outputs.RPM }}
|
||||||
|
overwrite: true
|
||||||
|
- name: Save SRPM as artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector SRPM for UBI 8
|
||||||
|
path: ${{ steps.rpmbuild.outputs.SRPM }}
|
||||||
|
overwrite: true
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build on UBI 9 using go-toolset
|
||||||
|
#
|
||||||
|
UBI-9-RPM-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# See: https://catalog.redhat.com/software/containers/ubi8/ubi/5c359854d70cc534b3a3784e?container-tabs=gti
|
||||||
|
container: redhat/ubi9
|
||||||
|
# The job outputs link to the outputs of the 'rpmbuild' step
|
||||||
|
# The job outputs link to the outputs of the 'rpmbuild' step
|
||||||
|
outputs:
|
||||||
|
rpm : ${{steps.rpmbuild.outputs.RPM}}
|
||||||
|
srpm : ${{steps.rpmbuild.outputs.SRPM}}
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Use dnf to install development packages
|
||||||
|
- name: Install development packages
|
||||||
|
run: dnf --assumeyes --disableplugin=subscription-manager install rpm-build go-srpm-macros gcc make python39 git wget openssl-devel diffutils delve
|
||||||
|
|
||||||
|
# Checkout git repository and submodules
|
||||||
|
# fetch-depth must be 0 to use git describe
|
||||||
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
# See: https://github.com/marketplace/actions/setup-go-environment
|
||||||
|
# - name: Setup Golang
|
||||||
|
# uses: actions/setup-go@v5
|
||||||
|
# with:
|
||||||
|
# go-version: 'stable'
|
||||||
|
- name: Setup Golang
|
||||||
|
run: |
|
||||||
|
dnf --assumeyes --disableplugin=subscription-manager install \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/go-toolset-1.22.7-2.el9_5.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-1.22.7-2.el9_5.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-bin-1.22.7-2.el9_5.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-src-1.22.7-2.el9_5.noarch.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-race-1.22.7-2.el9_5.x86_64.rpm
|
||||||
|
|
||||||
|
- name: RPM build MetricCollector
|
||||||
|
id: rpmbuild
|
||||||
|
run: |
|
||||||
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
make RPM
|
||||||
|
|
||||||
|
# See: https://github.com/actions/upload-artifact
|
||||||
|
- name: Save RPM as artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector RPM for UBI 9
|
||||||
|
path: ${{ steps.rpmbuild.outputs.RPM }}
|
||||||
|
overwrite: true
|
||||||
|
- name: Save SRPM as artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector SRPM for UBI 9
|
||||||
|
path: ${{ steps.rpmbuild.outputs.SRPM }}
|
||||||
|
overwrite: true
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build on Ubuntu 22.04 using official go package
|
||||||
|
#
|
||||||
|
Ubuntu-jammy-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: ubuntu:22.04
|
||||||
|
# The job outputs link to the outputs of the 'debrename' step
|
||||||
|
# Only job outputs can be used in child jobs
|
||||||
|
outputs:
|
||||||
|
deb : ${{steps.debrename.outputs.DEB}}
|
||||||
|
steps:
|
||||||
|
# Use apt to install development packages
|
||||||
|
- name: Install development packages
|
||||||
|
run: |
|
||||||
|
apt update && apt --assume-yes upgrade
|
||||||
|
apt --assume-yes install build-essential sed git wget bash
|
||||||
|
# Checkout git repository and submodules
|
||||||
|
# fetch-depth must be 0 to use git describe
|
||||||
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Golang
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: 'stable'
|
||||||
|
|
||||||
|
- name: DEB build MetricCollector
|
||||||
|
id: dpkg-build
|
||||||
|
run: |
|
||||||
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
make DEB
|
||||||
|
- name: Rename DEB (add '_ubuntu22.04')
|
||||||
|
id: debrename
|
||||||
|
run: |
|
||||||
|
OLD_DEB_NAME=$(echo "${{steps.dpkg-build.outputs.DEB}}" | rev | cut -d '.' -f 2- | rev)
|
||||||
|
NEW_DEB_FILE="${OLD_DEB_NAME}_ubuntu22.04.deb"
|
||||||
|
mv "${{steps.dpkg-build.outputs.DEB}}" "${NEW_DEB_FILE}"
|
||||||
|
echo "DEB=${NEW_DEB_FILE}" >> $GITHUB_OUTPUT
|
||||||
|
# See: https://github.com/actions/upload-artifact
|
||||||
|
- name: Save DEB as artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector DEB for Ubuntu 22.04
|
||||||
|
path: ${{ steps.debrename.outputs.DEB }}
|
||||||
|
overwrite: true
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build on Ubuntu 24.04 using official go package
|
||||||
|
#
|
||||||
|
Ubuntu-noblenumbat-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: ubuntu:24.04
|
||||||
|
# The job outputs link to the outputs of the 'debrename' step
|
||||||
|
# Only job outputs can be used in child jobs
|
||||||
|
outputs:
|
||||||
|
deb : ${{steps.debrename.outputs.DEB}}
|
||||||
|
steps:
|
||||||
|
# Use apt to install development packages
|
||||||
|
- name: Install development packages
|
||||||
|
run: |
|
||||||
|
apt update && apt --assume-yes upgrade
|
||||||
|
apt --assume-yes install build-essential sed git wget bash
|
||||||
|
# Checkout git repository and submodules
|
||||||
|
# fetch-depth must be 0 to use git describe
|
||||||
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Golang
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: 'stable'
|
||||||
|
|
||||||
|
- name: DEB build MetricCollector
|
||||||
|
id: dpkg-build
|
||||||
|
run: |
|
||||||
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
make DEB
|
||||||
|
- name: Rename DEB (add '_ubuntu24.04')
|
||||||
|
id: debrename
|
||||||
|
run: |
|
||||||
|
OLD_DEB_NAME=$(echo "${{steps.dpkg-build.outputs.DEB}}" | rev | cut -d '.' -f 2- | rev)
|
||||||
|
NEW_DEB_FILE="${OLD_DEB_NAME}_ubuntu24.04.deb"
|
||||||
|
mv "${{steps.dpkg-build.outputs.DEB}}" "${NEW_DEB_FILE}"
|
||||||
|
echo "DEB=${NEW_DEB_FILE}" >> $GITHUB_OUTPUT
|
||||||
|
# See: https://github.com/actions/upload-artifact
|
||||||
|
- name: Save DEB as artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector DEB for Ubuntu 24.04
|
||||||
|
path: ${{ steps.debrename.outputs.DEB }}
|
||||||
|
overwrite: true
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create release with fresh RPMs
|
||||||
|
#
|
||||||
|
Release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# We need the RPMs, so add dependency
|
||||||
|
needs: [AlmaLinux8-RPM-build, AlmaLinux9-RPM-build, UBI-8-RPM-build, UBI-9-RPM-build, Ubuntu-jammy-build, Ubuntu-noblenumbat-build]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# See: https://github.com/actions/download-artifact
|
||||||
|
- name: Download AlmaLinux 8 RPM
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector RPM for AlmaLinux 8
|
||||||
|
- name: Download AlmaLinux 8 SRPM
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector SRPM for AlmaLinux 8
|
||||||
|
|
||||||
|
- name: Download AlmaLinux 9 RPM
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector RPM for AlmaLinux 9
|
||||||
|
- name: Download AlmaLinux 9 SRPM
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector SRPM for AlmaLinux 9
|
||||||
|
|
||||||
|
- name: Download UBI 8 RPM
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector RPM for UBI 8
|
||||||
|
- name: Download UBI 8 SRPM
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector SRPM for UBI 8
|
||||||
|
|
||||||
|
- name: Download UBI 9 RPM
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector RPM for UBI 9
|
||||||
|
- name: Download UBI 9 SRPM
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector SRPM for UBI 9
|
||||||
|
|
||||||
|
- name: Download Ubuntu 22.04 DEB
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector DEB for Ubuntu 22.04
|
||||||
|
|
||||||
|
- name: Download Ubuntu 24.04 DEB
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector DEB for Ubuntu 24.04
|
||||||
|
|
||||||
|
# The download actions do not publish the name of the downloaded file,
|
||||||
|
# so we re-use the job outputs of the parent jobs. The files are all
|
||||||
|
# downloaded to the current folder.
|
||||||
|
# The gh-release action afterwards does not accept file lists but all
|
||||||
|
# files have to be listed at 'files'. The step creates one output per
|
||||||
|
# RPM package (2 per distro)
|
||||||
|
- name: Set RPM variables
|
||||||
|
id: files
|
||||||
|
run: |
|
||||||
|
ALMA_8_RPM=$(basename "${{ needs.AlmaLinux8-RPM-build.outputs.rpm}}")
|
||||||
|
ALMA_8_SRPM=$(basename "${{ needs.AlmaLinux8-RPM-build.outputs.srpm}}")
|
||||||
|
ALMA_9_RPM=$(basename "${{ needs.AlmaLinux9-RPM-build.outputs.rpm}}")
|
||||||
|
ALMA_9_SRPM=$(basename "${{ needs.AlmaLinux9-RPM-build.outputs.srpm}}")
|
||||||
|
UBI_8_RPM=$(basename "${{ needs.UBI-8-RPM-build.outputs.rpm}}")
|
||||||
|
UBI_8_SRPM=$(basename "${{ needs.UBI-8-RPM-build.outputs.srpm}}")
|
||||||
|
UBI_9_RPM=$(basename "${{ needs.UBI-9-RPM-build.outputs.rpm}}")
|
||||||
|
UBI_9_SRPM=$(basename "${{ needs.UBI-9-RPM-build.outputs.srpm}}")
|
||||||
|
U_2204_DEB=$(basename "${{ needs.Ubuntu-jammy-build.outputs.deb}}")
|
||||||
|
U_2404_DEB=$(basename "${{ needs.Ubuntu-noblenumbat-build.outputs.deb}}")
|
||||||
|
echo "ALMA_8_RPM::${ALMA_8_RPM}"
|
||||||
|
echo "ALMA_8_SRPM::${ALMA_8_SRPM}"
|
||||||
|
echo "ALMA_9_RPM::${ALMA_9_RPM}"
|
||||||
|
echo "ALMA_9_SRPM::${ALMA_9_SRPM}"
|
||||||
|
echo "UBI_8_RPM::${UBI_8_RPM}"
|
||||||
|
echo "UBI_8_SRPM::${UBI_8_SRPM}"
|
||||||
|
echo "UBI_9_RPM::${UBI_9_RPM}"
|
||||||
|
echo "UBI_9_SRPM::${UBI_9_SRPM}"
|
||||||
|
echo "U_2204_DEB::${U_2204_DEB}"
|
||||||
|
echo "U_2404_DEB::${U_2404_DEB}"
|
||||||
|
echo "ALMA_8_RPM=${ALMA_8_RPM}" >> $GITHUB_OUTPUT
|
||||||
|
echo "ALMA_8_SRPM=${ALMA_8_SRPM}" >> $GITHUB_OUTPUT
|
||||||
|
echo "ALMA_9_RPM=${ALMA_9_RPM}" >> $GITHUB_OUTPUT
|
||||||
|
echo "ALMA_9_SRPM=${ALMA_9_SRPM}" >> $GITHUB_OUTPUT
|
||||||
|
echo "UBI_8_RPM=${UBI_8_RPM}" >> $GITHUB_OUTPUT
|
||||||
|
echo "UBI_8_SRPM=${UBI_8_SRPM}" >> $GITHUB_OUTPUT
|
||||||
|
echo "UBI_9_RPM=${UBI_9_RPM}" >> $GITHUB_OUTPUT
|
||||||
|
echo "UBI_9_SRPM=${UBI_9_SRPM}" >> $GITHUB_OUTPUT
|
||||||
|
echo "U_2204_DEB=${U_2204_DEB}" >> $GITHUB_OUTPUT
|
||||||
|
echo "U_2404_DEB=${U_2404_DEB}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
# See: https://github.com/softprops/action-gh-release
|
||||||
|
- name: Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
with:
|
||||||
|
name: cc-metric-collector-${{github.ref_name}}
|
||||||
|
files: |
|
||||||
|
${{ steps.files.outputs.ALMA_8_RPM }}
|
||||||
|
${{ steps.files.outputs.ALMA_8_SRPM }}
|
||||||
|
${{ steps.files.outputs.ALMA_9_RPM }}
|
||||||
|
${{ steps.files.outputs.ALMA_9_SRPM }}
|
||||||
|
${{ steps.files.outputs.UBI_8_RPM }}
|
||||||
|
${{ steps.files.outputs.UBI_8_SRPM }}
|
||||||
|
${{ steps.files.outputs.UBI_9_RPM }}
|
||||||
|
${{ steps.files.outputs.UBI_9_SRPM }}
|
||||||
|
${{ steps.files.outputs.U_2204_DEB }}
|
||||||
|
${{ steps.files.outputs.U_2404_DEB }}
|
||||||
323
.github/workflows/runonce.yml
vendored
323
.github/workflows/runonce.yml
vendored
@@ -4,65 +4,346 @@
|
|||||||
name: Run Test
|
name: Run Test
|
||||||
|
|
||||||
# Run on event push
|
# Run on event push
|
||||||
on: push
|
on:
|
||||||
|
push:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
#
|
#
|
||||||
# Job build-1-17
|
# Job build-1-21
|
||||||
# Build on latest Ubuntu using golang version 1.17
|
# Build on latest Ubuntu using golang version 1.21
|
||||||
#
|
#
|
||||||
build-1-17:
|
build-1-21:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# See: https://github.com/marketplace/actions/checkout
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
# Checkout git repository and submodules
|
# Checkout git repository and submodules
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
# See: https://github.com/marketplace/actions/setup-go-environment
|
# See: https://github.com/marketplace/actions/setup-go-environment
|
||||||
- name: Setup Golang
|
- name: Setup Golang
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '^1.17.7'
|
go-version: '1.21'
|
||||||
|
|
||||||
# Install libganglia
|
|
||||||
- name: Setup Ganglia
|
|
||||||
run: sudo apt install ganglia-monitor libganglia1
|
|
||||||
|
|
||||||
- name: Build MetricCollector
|
- name: Build MetricCollector
|
||||||
run: make
|
run: make
|
||||||
|
|
||||||
|
- name: Set config file permissions
|
||||||
|
run: |
|
||||||
|
chown $USER .github/ci*.json
|
||||||
|
chmod 0600 .github/ci*.json
|
||||||
|
|
||||||
- name: Run MetricCollector once
|
- name: Run MetricCollector once
|
||||||
run: ./cc-metric-collector --once --config .github/ci-config.json
|
run: ./cc-metric-collector --once --config .github/ci-config.json
|
||||||
|
|
||||||
#
|
#
|
||||||
# Job build-1-16
|
# Job build-1-22
|
||||||
# Build on latest Ubuntu using golang version 1.16
|
# Build on latest Ubuntu using golang version 1.22
|
||||||
#
|
#
|
||||||
build-1-16:
|
build-1-22:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# See: https://github.com/marketplace/actions/checkout
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
# Checkout git repository and submodules
|
# Checkout git repository and submodules
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
# See: https://github.com/marketplace/actions/setup-go-environment
|
# See: https://github.com/marketplace/actions/setup-go-environment
|
||||||
- name: Setup Golang
|
- name: Setup Golang
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '^1.16.7' # The version AlmaLinux 8.5 uses
|
go-version: '1.22'
|
||||||
|
|
||||||
# Install libganglia
|
|
||||||
- name: Setup Ganglia
|
|
||||||
run: sudo apt install ganglia-monitor libganglia1
|
|
||||||
|
|
||||||
- name: Build MetricCollector
|
- name: Build MetricCollector
|
||||||
run: make
|
run: make
|
||||||
|
|
||||||
|
- name: Set config file permissions
|
||||||
|
run: |
|
||||||
|
chown $USER .github/ci*.json
|
||||||
|
chmod 0600 .github/ci*.json
|
||||||
|
|
||||||
- name: Run MetricCollector once
|
- name: Run MetricCollector once
|
||||||
run: ./cc-metric-collector --once --config .github/ci-config.json
|
run: ./cc-metric-collector --once --config .github/ci-config.json
|
||||||
|
|
||||||
|
#
|
||||||
|
# Job build-1-23
|
||||||
|
# Build on latest Ubuntu using golang version 1.23
|
||||||
|
#
|
||||||
|
build-1-23:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
|
# Checkout git repository and submodules
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
# See: https://github.com/marketplace/actions/setup-go-environment
|
||||||
|
- name: Setup Golang
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: '1.23'
|
||||||
|
|
||||||
|
- name: Build MetricCollector
|
||||||
|
run: make
|
||||||
|
|
||||||
|
- name: Set config file permissions
|
||||||
|
run: |
|
||||||
|
chown $USER .github/ci*.json
|
||||||
|
chmod 0600 .github/ci*.json
|
||||||
|
|
||||||
|
- name: Run MetricCollector once
|
||||||
|
run: ./cc-metric-collector --once --config .github/ci-config.json
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build on AlmaLinux 8
|
||||||
|
#
|
||||||
|
AlmaLinux8-RPM-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# See: https://hub.docker.com/_/almalinux
|
||||||
|
container: almalinux:8
|
||||||
|
# The job outputs link to the outputs of the 'rpmrename' step
|
||||||
|
# Only job outputs can be used in child jobs
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Use dnf to install development packages
|
||||||
|
- name: Install development packages
|
||||||
|
run: |
|
||||||
|
dnf --assumeyes group install "Development Tools" "RPM Development Tools"
|
||||||
|
dnf --assumeyes install wget openssl-devel diffutils delve which
|
||||||
|
|
||||||
|
# Checkout git repository and submodules
|
||||||
|
# fetch-depth must be 0 to use git describe
|
||||||
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
# See: https://github.com/marketplace/actions/setup-go-environment
|
||||||
|
# - name: Setup Golang
|
||||||
|
# uses: actions/setup-go@v5
|
||||||
|
# with:
|
||||||
|
# go-version: 'stable'
|
||||||
|
- name: Setup Golang
|
||||||
|
run: |
|
||||||
|
dnf --assumeyes --disableplugin=subscription-manager install \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/go-toolset-1.22.9-1.module_el8.10.0+3938+8c723e16.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/golang-1.22.9-1.module_el8.10.0+3938+8c723e16.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/golang-bin-1.22.9-1.module_el8.10.0+3938+8c723e16.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/golang-src-1.22.9-1.module_el8.10.0+3938+8c723e16.noarch.rpm
|
||||||
|
|
||||||
|
- name: RPM build MetricCollector
|
||||||
|
id: rpmbuild
|
||||||
|
run: |
|
||||||
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
make RPM
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build on AlmaLinux 9
|
||||||
|
#
|
||||||
|
AlmaLinux9-RPM-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# See: https://hub.docker.com/_/almalinux
|
||||||
|
container: almalinux:9
|
||||||
|
# The job outputs link to the outputs of the 'rpmrename' step
|
||||||
|
# Only job outputs can be used in child jobs
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Use dnf to install development packages
|
||||||
|
- name: Install development packages
|
||||||
|
run: |
|
||||||
|
dnf --assumeyes group install "Development Tools" "RPM Development Tools"
|
||||||
|
dnf --assumeyes install wget openssl-devel diffutils delve which
|
||||||
|
|
||||||
|
# Checkout git repository and submodules
|
||||||
|
# fetch-depth must be 0 to use git describe
|
||||||
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
# See: https://github.com/marketplace/actions/setup-go-environment
|
||||||
|
# - name: Setup Golang
|
||||||
|
# uses: actions/setup-go@v5
|
||||||
|
# with:
|
||||||
|
# go-version: 'stable'
|
||||||
|
- name: Setup Golang
|
||||||
|
run: |
|
||||||
|
dnf --assumeyes --disableplugin=subscription-manager install \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/go-toolset-1.22.7-2.el9_5.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-1.22.7-2.el9_5.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-bin-1.22.7-2.el9_5.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-src-1.22.7-2.el9_5.noarch.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-race-1.22.7-2.el9_5.x86_64.rpm
|
||||||
|
|
||||||
|
- name: RPM build MetricCollector
|
||||||
|
id: rpmbuild
|
||||||
|
run: |
|
||||||
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
make RPM
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build on UBI 8 using go-toolset
|
||||||
|
#
|
||||||
|
UBI-8-RPM-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# See: https://catalog.redhat.com/software/containers/ubi8/ubi/5c359854d70cc534b3a3784e?container-tabs=gti
|
||||||
|
container: redhat/ubi8
|
||||||
|
# The job outputs link to the outputs of the 'rpmbuild' step
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Use dnf to install development packages
|
||||||
|
- name: Install development packages
|
||||||
|
run: dnf --assumeyes --disableplugin=subscription-manager install rpm-build go-srpm-macros rpm-build-libs rpm-libs gcc make python38 git wget openssl-devel diffutils delve which
|
||||||
|
|
||||||
|
# Checkout git repository and submodules
|
||||||
|
# fetch-depth must be 0 to use git describe
|
||||||
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
# See: https://github.com/marketplace/actions/setup-go-environment
|
||||||
|
# - name: Setup Golang
|
||||||
|
# uses: actions/setup-go@v5
|
||||||
|
# with:
|
||||||
|
# go-version: 'stable'
|
||||||
|
- name: Setup Golang
|
||||||
|
run: |
|
||||||
|
dnf --assumeyes --disableplugin=subscription-manager install \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/go-toolset-1.22.9-1.module_el8.10.0+3938+8c723e16.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/golang-1.22.9-1.module_el8.10.0+3938+8c723e16.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/golang-bin-1.22.9-1.module_el8.10.0+3938+8c723e16.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/golang-src-1.22.9-1.module_el8.10.0+3938+8c723e16.noarch.rpm
|
||||||
|
|
||||||
|
- name: RPM build MetricCollector
|
||||||
|
id: rpmbuild
|
||||||
|
run: |
|
||||||
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
make RPM
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build on UBI 9 using go-toolset
|
||||||
|
#
|
||||||
|
UBI-9-RPM-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# See: https://catalog.redhat.com/software/containers/ubi8/ubi/5c359854d70cc534b3a3784e?container-tabs=gti
|
||||||
|
container: redhat/ubi9
|
||||||
|
# The job outputs link to the outputs of the 'rpmbuild' step
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Use dnf to install development packages
|
||||||
|
- name: Install development packages
|
||||||
|
run: dnf --assumeyes --disableplugin=subscription-manager install rpm-build go-srpm-macros gcc make python39 git wget openssl-devel diffutils delve
|
||||||
|
|
||||||
|
# Checkout git repository and submodules
|
||||||
|
# fetch-depth must be 0 to use git describe
|
||||||
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
# See: https://github.com/marketplace/actions/setup-go-environment
|
||||||
|
# - name: Setup Golang
|
||||||
|
# uses: actions/setup-go@v5
|
||||||
|
# with:
|
||||||
|
# go-version: 'stable'
|
||||||
|
- name: Setup Golang
|
||||||
|
run: |
|
||||||
|
dnf --assumeyes --disableplugin=subscription-manager install \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/go-toolset-1.22.7-2.el9_5.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-1.22.7-2.el9_5.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-bin-1.22.7-2.el9_5.x86_64.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-src-1.22.7-2.el9_5.noarch.rpm \
|
||||||
|
https://repo.almalinux.org/almalinux/9/AppStream/x86_64/os/Packages/golang-race-1.22.7-2.el9_5.x86_64.rpm
|
||||||
|
|
||||||
|
- name: RPM build MetricCollector
|
||||||
|
id: rpmbuild
|
||||||
|
run: |
|
||||||
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
make RPM
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build on Ubuntu 22.04 using official go package
|
||||||
|
#
|
||||||
|
Ubuntu-jammy-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: ubuntu:22.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# Use apt to install development packages
|
||||||
|
- name: Install development packages
|
||||||
|
run: |
|
||||||
|
apt update && apt --assume-yes upgrade
|
||||||
|
apt --assume-yes install build-essential sed git wget bash
|
||||||
|
# Checkout git repository and submodules
|
||||||
|
# fetch-depth must be 0 to use git describe
|
||||||
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
# Use official golang package
|
||||||
|
# See: https://github.com/marketplace/actions/setup-go-environment
|
||||||
|
- name: Setup Golang
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: 'stable'
|
||||||
|
|
||||||
|
- name: DEB build MetricCollector
|
||||||
|
id: dpkg-build
|
||||||
|
run: |
|
||||||
|
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
||||||
|
make DEB
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build on Ubuntu 24.04 using official go package
|
||||||
|
#
|
||||||
|
Ubuntu-noblenumbat-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: ubuntu:24.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# Use apt to install development packages
|
||||||
|
- name: Install development packages
|
||||||
|
run: |
|
||||||
|
apt update && apt --assume-yes upgrade
|
||||||
|
apt --assume-yes install build-essential sed git wget bash
|
||||||
|
# Checkout git repository and submodules
|
||||||
|
# fetch-depth must be 0 to use git describe
|
||||||
|
# See: https://github.com/marketplace/actions/checkout
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
# Use official golang package
|
||||||
|
# See: https://github.com/marketplace/actions/setup-go-environment
|
||||||
|
- name: Setup Golang
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: 'stable'
|
||||||
|
|
||||||
|
- name: DEB build MetricCollector
|
||||||
|
id: dpkg-build
|
||||||
|
run: |
|
||||||
|
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
||||||
|
make DEB
|
||||||
|
|||||||
29
.zenodo.json
Normal file
29
.zenodo.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"title": "cc-metric-collector",
|
||||||
|
"description": "Monitoring agent for ClusterCockpit.",
|
||||||
|
"creators": [
|
||||||
|
{
|
||||||
|
"affiliation": "Regionales Rechenzentrum Erlangen, Friedrich-Alexander-Universität Erlangen-Nürnberg",
|
||||||
|
"name": "Thomas Gruber",
|
||||||
|
"orcid": "0000-0001-5560-6964"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"affiliation": "Steinbuch Centre for Computing, Karlsruher Institut für Technologie",
|
||||||
|
"name": "Holger Obermaier",
|
||||||
|
"orcid": "0000-0002-6830-6626"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"upload_type": "software",
|
||||||
|
"license": "MIT",
|
||||||
|
"access_right": "open",
|
||||||
|
"keywords": [
|
||||||
|
"performance-monitoring",
|
||||||
|
"cluster-monitoring",
|
||||||
|
"open-source"
|
||||||
|
],
|
||||||
|
"communities": [
|
||||||
|
{
|
||||||
|
"identifier": "clustercockpit"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
85
Makefile
85
Makefile
@@ -15,47 +15,62 @@ COMPONENT_DIRS := collectors \
|
|||||||
internal/ccTopology \
|
internal/ccTopology \
|
||||||
internal/multiChanTicker
|
internal/multiChanTicker
|
||||||
|
|
||||||
|
BINDIR = bin
|
||||||
|
GOBIN = $(shell which go)
|
||||||
|
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: $(APP)
|
all: $(APP)
|
||||||
|
|
||||||
$(APP): $(GOSRC)
|
$(APP): $(GOSRC) go.mod
|
||||||
make -C collectors
|
make -C collectors
|
||||||
go get
|
$(GOBIN) get
|
||||||
go build -o $(APP) $(GOSRC_APP)
|
$(GOBIN) build -o $(APP) $(GOSRC_APP)
|
||||||
|
|
||||||
|
install: $(APP)
|
||||||
|
@WORKSPACE=$(PREFIX)
|
||||||
|
@if [ -z "$${WORKSPACE}" ]; then exit 1; fi
|
||||||
|
@mkdir --parents --verbose $${WORKSPACE}/usr/$(BINDIR)
|
||||||
|
@install -Dpm 755 $(APP) $${WORKSPACE}/usr/$(BINDIR)/$(APP)
|
||||||
|
@mkdir --parents --verbose $${WORKSPACE}/etc/cc-metric-collector $${WORKSPACE}/etc/default $${WORKSPACE}/etc/systemd/system $${WORKSPACE}/etc/init.d
|
||||||
|
@install -Dpm 600 config.json $${WORKSPACE}/etc/cc-metric-collector/cc-metric-collector.json
|
||||||
|
@sed -i -e s+"\"./"+"\"/etc/cc-metric-collector/"+g $${WORKSPACE}/etc/cc-metric-collector/cc-metric-collector.json
|
||||||
|
@install -Dpm 600 sinks.json $${WORKSPACE}/etc/cc-metric-collector/sinks.json
|
||||||
|
@install -Dpm 600 collectors.json $${WORKSPACE}/etc/cc-metric-collector/collectors.json
|
||||||
|
@install -Dpm 600 router.json $${WORKSPACE}/etc/cc-metric-collector/router.json
|
||||||
|
@install -Dpm 600 receivers.json $${WORKSPACE}/etc/cc-metric-collector/receivers.json
|
||||||
|
@install -Dpm 600 scripts/cc-metric-collector.config $${WORKSPACE}/etc/default/cc-metric-collector
|
||||||
|
@install -Dpm 644 scripts/cc-metric-collector.service $${WORKSPACE}/etc/systemd/system/cc-metric-collector.service
|
||||||
|
@install -Dpm 644 scripts/cc-metric-collector.init $${WORKSPACE}/etc/init.d/cc-metric-collector
|
||||||
|
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
.ONESHELL:
|
.ONESHELL:
|
||||||
clean:
|
clean:
|
||||||
@for COMP in $(COMPONENT_DIRS)
|
@for COMP in $(COMPONENT_DIRS); do if [ -e $$COMP/Makefile ]; then make -C $$COMP clean; fi; done
|
||||||
do
|
|
||||||
if [[ -e $$COMP/Makefile ]]; then
|
|
||||||
make -C $$COMP clean
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
rm -f $(APP)
|
rm -f $(APP)
|
||||||
|
|
||||||
.PHONY: fmt
|
.PHONY: fmt
|
||||||
fmt:
|
fmt:
|
||||||
go fmt $(GOSRC_COLLECTORS)
|
$(GOBIN) fmt $(GOSRC_COLLECTORS)
|
||||||
go fmt $(GOSRC_SINKS)
|
$(GOBIN) fmt $(GOSRC_SINKS)
|
||||||
go fmt $(GOSRC_RECEIVERS)
|
$(GOBIN) fmt $(GOSRC_RECEIVERS)
|
||||||
go fmt $(GOSRC_APP)
|
$(GOBIN) fmt $(GOSRC_APP)
|
||||||
@for F in $(GOSRC_INTERNAL); do go fmt $$F; done
|
@for F in $(GOSRC_INTERNAL); do $(GOBIN) fmt $$F; done
|
||||||
|
|
||||||
|
|
||||||
# Examine Go source code and reports suspicious constructs
|
# Examine Go source code and reports suspicious constructs
|
||||||
.PHONY: vet
|
.PHONY: vet
|
||||||
vet:
|
vet:
|
||||||
go vet ./...
|
$(GOBIN) vet ./...
|
||||||
|
|
||||||
|
|
||||||
# Run linter for the Go programming language.
|
# Run linter for the Go programming language.
|
||||||
# Using static analysis, it finds bugs and performance issues, offers simplifications, and enforces style rules
|
# Using static analysis, it finds bugs and performance issues, offers simplifications, and enforces style rules
|
||||||
.PHONY: staticcheck
|
.PHONY: staticcheck
|
||||||
staticcheck:
|
staticcheck:
|
||||||
go install honnef.co/go/tools/cmd/staticcheck@latest
|
$(GOBIN) install honnef.co/go/tools/cmd/staticcheck@latest
|
||||||
$$(go env GOPATH)/bin/staticcheck ./...
|
$$($(GOBIN) env GOPATH)/bin/staticcheck ./...
|
||||||
|
|
||||||
.ONESHELL:
|
.ONESHELL:
|
||||||
.PHONY: RPM
|
.PHONY: RPM
|
||||||
@@ -69,7 +84,7 @@ RPM: scripts/cc-metric-collector.spec
|
|||||||
@COMMITISH="HEAD"
|
@COMMITISH="HEAD"
|
||||||
@VERS=$$(git describe --tags $${COMMITISH})
|
@VERS=$$(git describe --tags $${COMMITISH})
|
||||||
@VERS=$${VERS#v}
|
@VERS=$${VERS#v}
|
||||||
@VERS=$${VERS//-/_}
|
@VERS=$$(echo $${VERS} | sed -e s+'-'+'_'+g)
|
||||||
@eval $$(rpmspec --query --queryformat "NAME='%{name}' VERSION='%{version}' RELEASE='%{release}' NVR='%{NVR}' NVRA='%{NVRA}'" --define="VERS $${VERS}" "$${SPECFILE}")
|
@eval $$(rpmspec --query --queryformat "NAME='%{name}' VERSION='%{version}' RELEASE='%{release}' NVR='%{NVR}' NVRA='%{NVRA}'" --define="VERS $${VERS}" "$${SPECFILE}")
|
||||||
@PREFIX="$${NAME}-$${VERSION}"
|
@PREFIX="$${NAME}-$${VERSION}"
|
||||||
@FORMAT="tar.gz"
|
@FORMAT="tar.gz"
|
||||||
@@ -81,8 +96,34 @@ RPM: scripts/cc-metric-collector.spec
|
|||||||
@if [[ "$${GITHUB_ACTIONS}" == true ]]; then
|
@if [[ "$${GITHUB_ACTIONS}" == true ]]; then
|
||||||
@ RPMFILE="$${RPMDIR}/$${ARCH}/$${NVRA}.rpm"
|
@ RPMFILE="$${RPMDIR}/$${ARCH}/$${NVRA}.rpm"
|
||||||
@ SRPMFILE="$${SRPMDIR}/$${NVR}.src.rpm"
|
@ SRPMFILE="$${SRPMDIR}/$${NVR}.src.rpm"
|
||||||
@ echo "RPM: $${RPMFILE}"
|
@ echo "SRPM=$${SRPMFILE}" >> $${GITHUB_OUTPUT}
|
||||||
@ echo "SRPM: $${SRPMFILE}"
|
@ echo "RPM=$${RPMFILE}" >> $${GITHUB_OUTPUT}
|
||||||
@ echo "::set-output name=SRPM::$${SRPMFILE}"
|
|
||||||
@ echo "::set-output name=RPM::$${RPMFILE}"
|
|
||||||
@fi
|
@fi
|
||||||
|
|
||||||
|
.PHONY: DEB
|
||||||
|
DEB: scripts/cc-metric-collector.deb.control $(APP)
|
||||||
|
@BASEDIR=$${PWD}
|
||||||
|
@WORKSPACE=$${PWD}/.dpkgbuild
|
||||||
|
@DEBIANDIR=$${WORKSPACE}/debian
|
||||||
|
@DEBIANBINDIR=$${WORKSPACE}/DEBIAN
|
||||||
|
@mkdir --parents --verbose $${WORKSPACE} $${DEBIANBINDIR}
|
||||||
|
#@mkdir --parents --verbose $$DEBIANDIR
|
||||||
|
@CONTROLFILE="$${BASEDIR}/scripts/cc-metric-collector.deb.control"
|
||||||
|
@COMMITISH="HEAD"
|
||||||
|
@VERS=$$(git describe --tags --abbrev=0 $${COMMITISH})
|
||||||
|
@if [ -z "$${VERS}" ]; then VERS=${GITHUB_REF_NAME}; fi
|
||||||
|
@VERS=$${VERS#v}
|
||||||
|
@ARCH=$$(uname -m)
|
||||||
|
@ARCH=$$(echo $${ARCH} | sed -e s+'_'+'-'+g)
|
||||||
|
@if [ "$${ARCH}" = "x86-64" ]; then ARCH=amd64; fi
|
||||||
|
@PREFIX="$${NAME}-$${VERSION}_$${ARCH}"
|
||||||
|
@SIZE_BYTES=$$(du -bcs --exclude=.dpkgbuild "$${WORKSPACE}"/ | awk '{print $$1}' | head -1 | sed -e 's/^0\+//')
|
||||||
|
@SIZE="$$(awk -v size="$${SIZE_BYTES}" 'BEGIN {print (size/1024)+1}' | awk '{print int($$0)}')"
|
||||||
|
@sed -e s+"{VERSION}"+"$${VERS}"+g -e s+"{INSTALLED_SIZE}"+"$${SIZE}"+g -e s+"{ARCH}"+"$${ARCH}"+g $${CONTROLFILE} > $${DEBIANBINDIR}/control
|
||||||
|
@make PREFIX=$${WORKSPACE} install
|
||||||
|
@DEB_FILE="cc-metric-collector_$${VERS}_$${ARCH}.deb"
|
||||||
|
@dpkg-deb -b $${WORKSPACE} "$${DEB_FILE}"
|
||||||
|
@if [ "$${GITHUB_ACTIONS}" = "true" ]; then
|
||||||
|
@ echo "DEB=$${DEB_FILE}" >> $${GITHUB_OUTPUT}
|
||||||
|
@fi
|
||||||
|
@rm -r "$${WORKSPACE}"
|
||||||
|
|||||||
20
README.md
20
README.md
@@ -1,5 +1,6 @@
|
|||||||
# cc-metric-collector
|
# cc-metric-collector
|
||||||
A node agent for measuring, processing and forwarding node level metrics. It is part of the ClusterCockpit ecosystem.
|
|
||||||
|
A node agent for measuring, processing and forwarding node level metrics. It is part of the [ClusterCockpit ecosystem](./docs/introduction.md).
|
||||||
|
|
||||||
The metric collector sends (and receives) metric in the [InfluxDB line protocol](https://docs.influxdata.com/influxdb/cloud/reference/syntax/line-protocol/) as it provides flexibility while providing a separation between tags (like index columns in relational databases) and fields (like data columns).
|
The metric collector sends (and receives) metric in the [InfluxDB line protocol](https://docs.influxdata.com/influxdb/cloud/reference/syntax/line-protocol/) as it provides flexibility while providing a separation between tags (like index columns in relational databases) and fields (like data columns).
|
||||||
|
|
||||||
@@ -7,10 +8,14 @@ There is a single timer loop that triggers all collectors serially, collects the
|
|||||||
|
|
||||||
The receiver runs as a go routine side-by-side with the timer loop and asynchronously forwards received metrics to the sink.
|
The receiver runs as a go routine side-by-side with the timer loop and asynchronously forwards received metrics to the sink.
|
||||||
|
|
||||||
|
|
||||||
|
[](https://doi.org/10.5281/zenodo.7438287)
|
||||||
|
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
|
|
||||||
Configuration is implemented using a single json document that is distributed over network and may be persisted as file.
|
Configuration is implemented using a single json document that is distributed over network and may be persisted as file.
|
||||||
Supported metrics are documented [here](https://github.com/ClusterCockpit/cc-specifications/blob/master/metrics/lineprotocol_alternative.md).
|
Supported metrics are documented [here](https://github.com/ClusterCockpit/cc-specifications/blob/master/interfaces/lineprotocol/README.md).
|
||||||
|
|
||||||
There is a main configuration file with basic settings that point to the other configuration files for the different components.
|
There is a main configuration file with basic settings that point to the other configuration files for the different components.
|
||||||
|
|
||||||
@@ -20,20 +25,20 @@ There is a main configuration file with basic settings that point to the other c
|
|||||||
"collectors" : "collectors.json",
|
"collectors" : "collectors.json",
|
||||||
"receivers" : "receivers.json",
|
"receivers" : "receivers.json",
|
||||||
"router" : "router.json",
|
"router" : "router.json",
|
||||||
"interval": 10,
|
"interval": "10s",
|
||||||
"duration": 1
|
"duration": "1s"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `interval` defines how often the metrics should be read and send to the sink. The `duration` tells collectors how long one measurement has to take. This is important for some collectors, like the `likwid` collector.
|
The `interval` defines how often the metrics should be read and send to the sink. The `duration` tells collectors how long one measurement has to take. This is important for some collectors, like the `likwid` collector. For more information, see [here](./docs/configuration.md).
|
||||||
|
|
||||||
See the component READMEs for their configuration:
|
See the component READMEs for their configuration:
|
||||||
|
|
||||||
* [`collectors`](./collectors/README.md)
|
* [`collectors`](./collectors/README.md)
|
||||||
* [`sinks`](./sinks/README.md)
|
* [`sinks`](./sinks/README.md)
|
||||||
* [`receivers`](./receivers/README.md)
|
* [`receivers`](./receivers/README.md)
|
||||||
* [`router`](./internal/metricRouter/README.md)
|
* [`router`](./internal/metricRouter/README.md)
|
||||||
|
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -43,6 +48,7 @@ $ go get (requires at least golang 1.16)
|
|||||||
$ make
|
$ make
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For more information, see [here](./docs/building.md).
|
||||||
|
|
||||||
# Running
|
# Running
|
||||||
|
|
||||||
@@ -56,6 +62,7 @@ Usage of metric-collector:
|
|||||||
-once
|
-once
|
||||||
Run all collectors only once
|
Run all collectors only once
|
||||||
```
|
```
|
||||||
|
|
||||||
# Scenarios
|
# Scenarios
|
||||||
|
|
||||||
The metric collector was designed with flexibility in mind, so it can be used in many scenarios. Here are a few:
|
The metric collector was designed with flexibility in mind, so it can be used in many scenarios. Here are a few:
|
||||||
@@ -93,6 +100,7 @@ flowchart TD
|
|||||||
```
|
```
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
|
|
||||||
The ClusterCockpit ecosystem is designed to be used by different HPC computing centers. Since configurations and setups differ between the centers, the centers likely have to put some work into the cc-metric-collector to gather all desired metrics.
|
The ClusterCockpit ecosystem is designed to be used by different HPC computing centers. Since configurations and setups differ between the centers, the centers likely have to put some work into the cc-metric-collector to gather all desired metrics.
|
||||||
|
|
||||||
You are free to open an issue to request a collector but we would also be happy about PRs.
|
You are free to open an issue to request a collector but we would also be happy about PRs.
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
@@ -15,15 +16,15 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
|
||||||
mr "github.com/ClusterCockpit/cc-metric-collector/internal/metricRouter"
|
mr "github.com/ClusterCockpit/cc-metric-collector/internal/metricRouter"
|
||||||
mct "github.com/ClusterCockpit/cc-metric-collector/internal/multiChanTicker"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
mct "github.com/ClusterCockpit/cc-metric-collector/pkg/multiChanTicker"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CentralConfigFile struct {
|
type CentralConfigFile struct {
|
||||||
Interval int `json:"interval"`
|
Interval string `json:"interval"`
|
||||||
Duration int `json:"duration"`
|
Duration string `json:"duration"`
|
||||||
CollectorConfigFile string `json:"collectors"`
|
CollectorConfigFile string `json:"collectors"`
|
||||||
RouterConfigFile string `json:"router"`
|
RouterConfigFile string `json:"router"`
|
||||||
SinkConfigFile string `json:"sinks"`
|
SinkConfigFile string `json:"sinks"`
|
||||||
@@ -42,6 +43,27 @@ func LoadCentralConfiguration(file string, config *CentralConfigFile) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ConfigFileCheck(file string) error {
|
||||||
|
|
||||||
|
info, err := os.Stat(file)
|
||||||
|
if err != nil {
|
||||||
|
cclog.Error("Cannot access file", file)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
uid := info.Sys().(*syscall.Stat_t).Uid
|
||||||
|
perm := info.Mode().Perm()
|
||||||
|
if uid != uint32(os.Getuid()) {
|
||||||
|
err = fmt.Errorf("file %s has a different owner", file)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if perm != 0600 {
|
||||||
|
err = fmt.Errorf("file %s has a invalid permissions", file)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type RuntimeConfig struct {
|
type RuntimeConfig struct {
|
||||||
Interval time.Duration
|
Interval time.Duration
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
@@ -54,7 +76,7 @@ type RuntimeConfig struct {
|
|||||||
ReceiveManager receivers.ReceiveManager
|
ReceiveManager receivers.ReceiveManager
|
||||||
MultiChanTicker mct.MultiChanTicker
|
MultiChanTicker mct.MultiChanTicker
|
||||||
|
|
||||||
Channels []chan lp.CCMetric
|
Channels []chan lp.CCMessage
|
||||||
Sync sync.WaitGroup
|
Sync sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,37 +189,78 @@ func mainFunc() int {
|
|||||||
CliArgs: ReadCli(),
|
CliArgs: ReadCli(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = ConfigFileCheck(rcfg.CliArgs["configfile"])
|
||||||
|
if err != nil {
|
||||||
|
cclog.Error(err.Error())
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
// Load and check configuration
|
// Load and check configuration
|
||||||
err = LoadCentralConfiguration(rcfg.CliArgs["configfile"], &rcfg.ConfigFile)
|
err = LoadCentralConfiguration(rcfg.CliArgs["configfile"], &rcfg.ConfigFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.Error("Error reading configuration file ", rcfg.CliArgs["configfile"], ": ", err.Error())
|
cclog.Error("Error reading configuration file ", rcfg.CliArgs["configfile"], ": ", err.Error())
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
if rcfg.ConfigFile.Interval <= 0 || time.Duration(rcfg.ConfigFile.Interval)*time.Second <= 0 {
|
|
||||||
|
// Properly use duration parser with inputs like '60s', '5m' or similar
|
||||||
|
if len(rcfg.ConfigFile.Interval) > 0 {
|
||||||
|
t, err := time.ParseDuration(rcfg.ConfigFile.Interval)
|
||||||
|
if err != nil {
|
||||||
|
cclog.Error("Configuration value 'interval' no valid duration")
|
||||||
|
}
|
||||||
|
rcfg.Interval = t
|
||||||
|
if rcfg.Interval == 0 {
|
||||||
cclog.Error("Configuration value 'interval' must be greater than zero")
|
cclog.Error("Configuration value 'interval' must be greater than zero")
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
rcfg.Interval = time.Duration(rcfg.ConfigFile.Interval) * time.Second
|
}
|
||||||
if rcfg.ConfigFile.Duration <= 0 || time.Duration(rcfg.ConfigFile.Duration)*time.Second <= 0 {
|
|
||||||
|
// Properly use duration parser with inputs like '60s', '5m' or similar
|
||||||
|
if len(rcfg.ConfigFile.Duration) > 0 {
|
||||||
|
t, err := time.ParseDuration(rcfg.ConfigFile.Duration)
|
||||||
|
if err != nil {
|
||||||
|
cclog.Error("Configuration value 'duration' no valid duration")
|
||||||
|
}
|
||||||
|
rcfg.Duration = t
|
||||||
|
if rcfg.Duration == 0 {
|
||||||
cclog.Error("Configuration value 'duration' must be greater than zero")
|
cclog.Error("Configuration value 'duration' must be greater than zero")
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
rcfg.Duration = time.Duration(rcfg.ConfigFile.Duration) * time.Second
|
}
|
||||||
|
if rcfg.Duration > rcfg.Interval {
|
||||||
|
cclog.Error("The interval should be greater than duration")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
if len(rcfg.ConfigFile.RouterConfigFile) == 0 {
|
if len(rcfg.ConfigFile.RouterConfigFile) == 0 {
|
||||||
cclog.Error("Metric router configuration file must be set")
|
cclog.Error("Metric router configuration file must be set")
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
err = ConfigFileCheck(rcfg.ConfigFile.RouterConfigFile)
|
||||||
|
if err != nil {
|
||||||
|
cclog.Error(err.Error())
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
if len(rcfg.ConfigFile.SinkConfigFile) == 0 {
|
if len(rcfg.ConfigFile.SinkConfigFile) == 0 {
|
||||||
cclog.Error("Sink configuration file must be set")
|
cclog.Error("Sink configuration file must be set")
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
err = ConfigFileCheck(rcfg.ConfigFile.SinkConfigFile)
|
||||||
|
if err != nil {
|
||||||
|
cclog.Error(err.Error())
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
if len(rcfg.ConfigFile.CollectorConfigFile) == 0 {
|
if len(rcfg.ConfigFile.CollectorConfigFile) == 0 {
|
||||||
cclog.Error("Metric collector configuration file must be set")
|
cclog.Error("Metric collector configuration file must be set")
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
err = ConfigFileCheck(rcfg.ConfigFile.CollectorConfigFile)
|
||||||
|
if err != nil {
|
||||||
|
cclog.Error(err.Error())
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
// Set log file
|
// Set log file
|
||||||
if logfile := rcfg.CliArgs["logfile"]; logfile != "stderr" {
|
if logfile := rcfg.CliArgs["logfile"]; logfile != "stderr" {
|
||||||
@@ -222,7 +285,7 @@ func mainFunc() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connect metric router to sink manager
|
// Connect metric router to sink manager
|
||||||
RouterToSinksChannel := make(chan lp.CCMetric, 200)
|
RouterToSinksChannel := make(chan lp.CCMessage, 200)
|
||||||
rcfg.SinkManager.AddInput(RouterToSinksChannel)
|
rcfg.SinkManager.AddInput(RouterToSinksChannel)
|
||||||
rcfg.MetricRouter.AddOutput(RouterToSinksChannel)
|
rcfg.MetricRouter.AddOutput(RouterToSinksChannel)
|
||||||
|
|
||||||
@@ -234,12 +297,17 @@ func mainFunc() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connect collector manager to metric router
|
// Connect collector manager to metric router
|
||||||
CollectToRouterChannel := make(chan lp.CCMetric, 200)
|
CollectToRouterChannel := make(chan lp.CCMessage, 200)
|
||||||
rcfg.CollectManager.AddOutput(CollectToRouterChannel)
|
rcfg.CollectManager.AddOutput(CollectToRouterChannel)
|
||||||
rcfg.MetricRouter.AddCollectorInput(CollectToRouterChannel)
|
rcfg.MetricRouter.AddCollectorInput(CollectToRouterChannel)
|
||||||
|
|
||||||
// Create new receive manager
|
// Create new receive manager
|
||||||
if len(rcfg.ConfigFile.ReceiverConfigFile) > 0 {
|
if len(rcfg.ConfigFile.ReceiverConfigFile) > 0 {
|
||||||
|
err = ConfigFileCheck(rcfg.ConfigFile.ReceiverConfigFile)
|
||||||
|
if err != nil {
|
||||||
|
cclog.Error(err.Error())
|
||||||
|
return 1
|
||||||
|
}
|
||||||
rcfg.ReceiveManager, err = receivers.New(&rcfg.Sync, rcfg.ConfigFile.ReceiverConfigFile)
|
rcfg.ReceiveManager, err = receivers.New(&rcfg.Sync, rcfg.ConfigFile.ReceiverConfigFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.Error(err.Error())
|
cclog.Error(err.Error())
|
||||||
@@ -247,7 +315,7 @@ func mainFunc() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connect receive manager to metric router
|
// Connect receive manager to metric router
|
||||||
ReceiveToRouterChannel := make(chan lp.CCMetric, 200)
|
ReceiveToRouterChannel := make(chan lp.CCMessage, 200)
|
||||||
rcfg.ReceiveManager.AddOutput(ReceiveToRouterChannel)
|
rcfg.ReceiveManager.AddOutput(ReceiveToRouterChannel)
|
||||||
rcfg.MetricRouter.AddReceiverInput(ReceiveToRouterChannel)
|
rcfg.MetricRouter.AddReceiverInput(ReceiveToRouterChannel)
|
||||||
use_recv = true
|
use_recv = true
|
||||||
@@ -271,7 +339,7 @@ func mainFunc() int {
|
|||||||
|
|
||||||
// Wait until one tick has passed. This is a workaround
|
// Wait until one tick has passed. This is a workaround
|
||||||
if rcfg.CliArgs["once"] == "true" {
|
if rcfg.CliArgs["once"] == "true" {
|
||||||
x := 1.2 * float64(rcfg.ConfigFile.Interval)
|
x := 1.2 * float64(rcfg.Interval.Seconds())
|
||||||
time.Sleep(time.Duration(int(x)) * time.Second)
|
time.Sleep(time.Duration(int(x)) * time.Second)
|
||||||
shutdownSignal <- os.Interrupt
|
shutdownSignal <- os.Interrupt
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,13 @@
|
|||||||
"proc_total"
|
"proc_total"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"memstat": {},
|
||||||
|
"netstat": {
|
||||||
|
"include_devices": [
|
||||||
|
"enp5s0"
|
||||||
|
],
|
||||||
|
"send_derived_values": true
|
||||||
|
},
|
||||||
"numastats": {},
|
"numastats": {},
|
||||||
"nvidia": {},
|
"nvidia": {},
|
||||||
"tempstat": {
|
"tempstat": {
|
||||||
@@ -27,5 +34,8 @@
|
|||||||
"type-id": "1"
|
"type-id": "1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"topprocs": {
|
||||||
|
"num_procs": 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,79 +1,33 @@
|
|||||||
# Use central installation
|
# LIKWID version
|
||||||
CENTRAL_INSTALL = false
|
LIKWID_VERSION := 5.4.1
|
||||||
# How to access hardware performance counters through LIKWID.
|
LIKWID_INSTALLED_FOLDER := $(shell dirname $$(which likwid-topology 2>/dev/null) 2>/dev/null)
|
||||||
# Recommended is 'direct' mode
|
|
||||||
ACCESSMODE = direct
|
|
||||||
|
|
||||||
#######################################################################
|
LIKWID_FOLDER := $(CURDIR)/likwid
|
||||||
# if CENTRAL_INSTALL == true
|
|
||||||
#######################################################################
|
|
||||||
# Path to central installation (if CENTRAL_INSTALL=true)
|
|
||||||
LIKWID_BASE=/apps/likwid/5.2.1
|
|
||||||
# LIKWID version (should be same major version as central installation, 5.2.x)
|
|
||||||
LIKWID_VERSION = 5.2.1
|
|
||||||
|
|
||||||
#######################################################################
|
all: likwid
|
||||||
# if CENTRAL_INSTALL == false and ACCESSMODE == accessdaemon
|
|
||||||
#######################################################################
|
|
||||||
# Where to install the accessdaemon
|
|
||||||
DAEMON_INSTALLDIR = /usr/local
|
|
||||||
# Which user to use for the accessdaemon
|
|
||||||
DAEMON_USER = root
|
|
||||||
# Which group to use for the accessdaemon
|
|
||||||
DAEMON_GROUP = root
|
|
||||||
|
|
||||||
|
.ONESHELL:
|
||||||
|
.PHONY: likwid
|
||||||
|
likwid:
|
||||||
|
if [ -n "$(LIKWID_INSTALLED_FOLDER)" ]; then
|
||||||
|
# Using likwid include files from system installation
|
||||||
|
INCLUDE_DIR="$(LIKWID_INSTALLED_FOLDER)/../include"
|
||||||
|
mkdir --parents --verbose "$(LIKWID_FOLDER)"
|
||||||
|
cp "$${INCLUDE_DIR}"/*.h "$(LIKWID_FOLDER)"
|
||||||
|
else
|
||||||
|
# Using likwid include files from downloaded tar archive
|
||||||
|
if [ -d "$(LIKWID_FOLDER)" ]; then
|
||||||
|
rm --recursive "$(LIKWID_FOLDER)"
|
||||||
|
fi
|
||||||
|
BUILD_FOLDER="$${PWD}/likwidbuild"
|
||||||
|
mkdir --parents --verbose "$${BUILD_FOLDER}"
|
||||||
|
wget --output-document=- http://ftp.rrze.uni-erlangen.de/mirrors/likwid/likwid-$(LIKWID_VERSION).tar.gz |
|
||||||
|
tar --directory="$${BUILD_FOLDER}" --extract --gz
|
||||||
|
install -D --verbose --preserve-timestamps --mode=0644 --target-directory="$(LIKWID_FOLDER)" "$${BUILD_FOLDER}/likwid-$(LIKWID_VERSION)/src/includes"/likwid*.h
|
||||||
|
rm --recursive "$${BUILD_FOLDER}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
#################################################
|
|
||||||
# No need to change anything below this line
|
|
||||||
#################################################
|
|
||||||
INSTALL_FOLDER = ./likwid
|
|
||||||
BUILD_FOLDER = ./likwid/build
|
|
||||||
|
|
||||||
ifneq ($(strip $(CENTRAL_INSTALL)),true)
|
|
||||||
LIKWID_BASE := $(shell pwd)/$(INSTALL_FOLDER)
|
|
||||||
DAEMON_BASE := $(LIKWID_BASE)
|
|
||||||
GROUPS_BASE := $(LIKWID_BASE)/groups
|
|
||||||
all: $(INSTALL_FOLDER)/liblikwid.a cleanup
|
|
||||||
else
|
|
||||||
DAEMON_BASE= $(LIKWID_BASE)/sbin
|
|
||||||
all: $(INSTALL_FOLDER)/liblikwid.a cleanup
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$(BUILD_FOLDER)/likwid-$(LIKWID_VERSION).tar.gz: $(BUILD_FOLDER)
|
|
||||||
wget -P $(BUILD_FOLDER) ftp://ftp.rrze.uni-erlangen.de/mirrors/likwid/likwid-$(LIKWID_VERSION).tar.gz
|
|
||||||
|
|
||||||
$(BUILD_FOLDER):
|
|
||||||
mkdir -p $(BUILD_FOLDER)
|
|
||||||
|
|
||||||
$(INSTALL_FOLDER):
|
|
||||||
mkdir -p $(INSTALL_FOLDER)
|
|
||||||
|
|
||||||
$(BUILD_FOLDER)/likwid-$(LIKWID_VERSION): $(BUILD_FOLDER)/likwid-$(LIKWID_VERSION).tar.gz
|
|
||||||
tar -C $(BUILD_FOLDER) -xf $(BUILD_FOLDER)/likwid-$(LIKWID_VERSION).tar.gz
|
|
||||||
|
|
||||||
$(INSTALL_FOLDER)/liblikwid.a: $(BUILD_FOLDER)/likwid-$(LIKWID_VERSION) $(INSTALL_FOLDER)
|
|
||||||
cd "$(BUILD_FOLDER)/likwid-$(LIKWID_VERSION)" && make "PREFIX=$(LIKWID_BASE)" "SHARED_LIBRARY=false" "ACCESSMODE=$(ACCESSMODE)" "INSTALLED_ACCESSDAEMON=$(DAEMON_INSTALLDIR)/likwid-accessD"
|
|
||||||
cp \
|
|
||||||
$(BUILD_FOLDER)/likwid-$(LIKWID_VERSION)/liblikwid.a \
|
|
||||||
$(BUILD_FOLDER)/likwid-$(LIKWID_VERSION)/ext/hwloc/liblikwid-hwloc.a \
|
|
||||||
$(BUILD_FOLDER)/likwid-$(LIKWID_VERSION)/src/includes/likwid*.h \
|
|
||||||
$(BUILD_FOLDER)/likwid-$(LIKWID_VERSION)/src/includes/bstrlib.h \
|
|
||||||
$(INSTALL_FOLDER)
|
|
||||||
|
|
||||||
$(DAEMON_INSTALLDIR)/likwid-accessD: $(BUILD_FOLDER)/likwid-$(LIKWID_VERSION)/likwid-accessD
|
|
||||||
sudo -u $(DAEMON_USER) -g $(DAEMON_GROUP) install -m 4775 $(BUILD_FOLDER)/likwid-$(LIKWID_VERSION)/likwid-accessD $(DAEMON_INSTALLDIR)/likwid-accessD
|
|
||||||
|
|
||||||
prepare_collector: likwidMetric.go
|
|
||||||
cp likwidMetric.go likwidMetric.go.orig
|
|
||||||
sed -i -e s+"const GROUPPATH =.*"+"const GROUPPATH = \`$(GROUPS_BASE)\`"+g likwidMetric.go
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
rm -rf $(BUILD_FOLDER)
|
|
||||||
|
|
||||||
clean: cleanup
|
|
||||||
rm -rf likwid
|
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm -rf likwid
|
||||||
|
|||||||
@@ -35,8 +35,11 @@ In contrast to the configuration files for sinks and receivers, the collectors c
|
|||||||
* [`nfs4stat`](./nfs4Metric.md)
|
* [`nfs4stat`](./nfs4Metric.md)
|
||||||
* [`cpufreq`](./cpufreqMetric.md)
|
* [`cpufreq`](./cpufreqMetric.md)
|
||||||
* [`cpufreq_cpuinfo`](./cpufreqCpuinfoMetric.md)
|
* [`cpufreq_cpuinfo`](./cpufreqCpuinfoMetric.md)
|
||||||
* [`numastat`](./numastatMetric.md)
|
* [`numastats`](./numastatsMetric.md)
|
||||||
* [`gpfs`](./gpfsMetric.md)
|
* [`gpfs`](./gpfsMetric.md)
|
||||||
|
* [`beegfs_meta`](./beegfsmetaMetric.md)
|
||||||
|
* [`beegfs_storage`](./beegfsstorageMetric.md)
|
||||||
|
* [`rocm_smi`](./rocmsmiMetric.md)
|
||||||
|
|
||||||
## Todos
|
## Todos
|
||||||
|
|
||||||
|
|||||||
230
collectors/beegfsmetaMetric.go
Normal file
230
collectors/beegfsmetaMetric.go
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
package collectors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"os/user"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
)
|
||||||
|
|
||||||
|
const DEFAULT_BEEGFS_CMD = "beegfs-ctl"
|
||||||
|
|
||||||
|
// Struct for the collector-specific JSON config
|
||||||
|
type BeegfsMetaCollectorConfig struct {
|
||||||
|
Beegfs string `json:"beegfs_path"`
|
||||||
|
ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
|
||||||
|
ExcludeFilesystem []string `json:"exclude_filesystem"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BeegfsMetaCollector struct {
|
||||||
|
metricCollector
|
||||||
|
tags map[string]string
|
||||||
|
matches map[string]string
|
||||||
|
config BeegfsMetaCollectorConfig
|
||||||
|
skipFS map[string]struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *BeegfsMetaCollector) Init(config json.RawMessage) error {
|
||||||
|
// Check if already initialized
|
||||||
|
if m.init {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// Metrics
|
||||||
|
var nodeMdstat_array = [39]string{
|
||||||
|
"sum", "ack", "close", "entInf",
|
||||||
|
"fndOwn", "mkdir", "create", "rddir",
|
||||||
|
"refrEn", "mdsInf", "rmdir", "rmLnk",
|
||||||
|
"mvDirIns", "mvFiIns", "open", "ren",
|
||||||
|
"sChDrct", "sAttr", "sDirPat", "stat",
|
||||||
|
"statfs", "trunc", "symlnk", "unlnk",
|
||||||
|
"lookLI", "statLI", "revalLI", "openLI",
|
||||||
|
"createLI", "hardlnk", "flckAp", "flckEn",
|
||||||
|
"flckRg", "dirparent", "listXA", "getXA",
|
||||||
|
"rmXA", "setXA", "mirror"}
|
||||||
|
|
||||||
|
m.name = "BeegfsMetaCollector"
|
||||||
|
m.setup()
|
||||||
|
m.parallel = true
|
||||||
|
// Set default beegfs-ctl binary
|
||||||
|
|
||||||
|
m.config.Beegfs = DEFAULT_BEEGFS_CMD
|
||||||
|
|
||||||
|
// Read JSON configuration
|
||||||
|
if len(config) > 0 {
|
||||||
|
err := json.Unmarshal(config, &m.config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//create map with possible variables
|
||||||
|
m.matches = make(map[string]string)
|
||||||
|
for _, value := range nodeMdstat_array {
|
||||||
|
_, skip := stringArrayContains(m.config.ExcludeMetrics, value)
|
||||||
|
if skip {
|
||||||
|
m.matches["other"] = "0"
|
||||||
|
} else {
|
||||||
|
m.matches["beegfs_cmeta_"+value] = "0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.meta = map[string]string{
|
||||||
|
"source": m.name,
|
||||||
|
"group": "BeegfsMeta",
|
||||||
|
}
|
||||||
|
m.tags = map[string]string{
|
||||||
|
"type": "node",
|
||||||
|
"filesystem": "",
|
||||||
|
}
|
||||||
|
m.skipFS = make(map[string]struct{})
|
||||||
|
for _, fs := range m.config.ExcludeFilesystem {
|
||||||
|
m.skipFS[fs] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Beegfs file system statistics can only be queried by user root
|
||||||
|
user, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("BeegfsMetaCollector.Init(): Failed to get current user: %v", err)
|
||||||
|
}
|
||||||
|
if user.Uid != "0" {
|
||||||
|
return fmt.Errorf("BeegfsMetaCollector.Init(): BeeGFS file system statistics can only be queried by user root")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if beegfs-ctl is in executable search path
|
||||||
|
_, err = exec.LookPath(m.config.Beegfs)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("BeegfsMetaCollector.Init(): Failed to find beegfs-ctl binary '%s': %v", m.config.Beegfs, err)
|
||||||
|
}
|
||||||
|
m.init = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *BeegfsMetaCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
|
if !m.init {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//get mounpoint
|
||||||
|
buffer, _ := os.ReadFile(string("/proc/mounts"))
|
||||||
|
mounts := strings.Split(string(buffer), "\n")
|
||||||
|
var mountpoints []string
|
||||||
|
for _, line := range mounts {
|
||||||
|
if len(line) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
f := strings.Fields(line)
|
||||||
|
if strings.Contains(f[0], "beegfs_ondemand") {
|
||||||
|
// Skip excluded filesystems
|
||||||
|
if _, skip := m.skipFS[f[1]]; skip {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
mountpoints = append(mountpoints, f[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(mountpoints) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, mountpoint := range mountpoints {
|
||||||
|
m.tags["filesystem"] = mountpoint
|
||||||
|
|
||||||
|
// bwwgfs-ctl:
|
||||||
|
// --clientstats: Show client IO statistics.
|
||||||
|
// --nodetype=meta: The node type to query (meta, storage).
|
||||||
|
// --interval:
|
||||||
|
// --mount=/mnt/beeond/: Which mount point
|
||||||
|
//cmd := exec.Command(m.config.Beegfs, "/root/mc/test.txt")
|
||||||
|
mountoption := "--mount=" + mountpoint
|
||||||
|
cmd := exec.Command(m.config.Beegfs, "--clientstats",
|
||||||
|
"--nodetype=meta", mountoption, "--allstats")
|
||||||
|
cmd.Stdin = strings.NewReader("\n")
|
||||||
|
cmdStdout := new(bytes.Buffer)
|
||||||
|
cmdStderr := new(bytes.Buffer)
|
||||||
|
cmd.Stdout = cmdStdout
|
||||||
|
cmd.Stderr = cmdStderr
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "BeegfsMetaCollector.Read(): Failed to execute command \"%s\": %s\n", cmd.String(), err.Error())
|
||||||
|
fmt.Fprintf(os.Stderr, "BeegfsMetaCollector.Read(): command exit code: \"%d\"\n", cmd.ProcessState.ExitCode())
|
||||||
|
data, _ := io.ReadAll(cmdStderr)
|
||||||
|
fmt.Fprintf(os.Stderr, "BeegfsMetaCollector.Read(): command stderr: \"%s\"\n", string(data))
|
||||||
|
data, _ = io.ReadAll(cmdStdout)
|
||||||
|
fmt.Fprintf(os.Stderr, "BeegfsMetaCollector.Read(): command stdout: \"%s\"\n", string(data))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Read I/O statistics
|
||||||
|
scanner := bufio.NewScanner(cmdStdout)
|
||||||
|
|
||||||
|
sumLine := regexp.MustCompile(`^Sum:\s+\d+\s+\[[a-zA-Z]+\]+`)
|
||||||
|
//Line := regexp.MustCompile(`^(.*)\s+(\d)+\s+\[([a-zA-Z]+)\]+`)
|
||||||
|
statsLine := regexp.MustCompile(`^(.*?)\s+?(\d.*?)$`)
|
||||||
|
singleSpacePattern := regexp.MustCompile(`\s+`)
|
||||||
|
removePattern := regexp.MustCompile(`[\[|\]]`)
|
||||||
|
|
||||||
|
for scanner.Scan() {
|
||||||
|
readLine := scanner.Text()
|
||||||
|
//fmt.Println(readLine)
|
||||||
|
// Jump few lines, we only want the I/O stats from nodes
|
||||||
|
if !sumLine.MatchString(readLine) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
match := statsLine.FindStringSubmatch(readLine)
|
||||||
|
// nodeName = "Sum:" or would be nodes
|
||||||
|
// nodeName := match[1]
|
||||||
|
//Remove multiple whitespaces
|
||||||
|
dummy := removePattern.ReplaceAllString(match[2], " ")
|
||||||
|
metaStats := strings.TrimSpace(singleSpacePattern.ReplaceAllString(dummy, " "))
|
||||||
|
split := strings.Split(metaStats, " ")
|
||||||
|
|
||||||
|
// fill map with values
|
||||||
|
// split[i+1] = mdname
|
||||||
|
// split[i] = amount of md operations
|
||||||
|
for i := 0; i <= len(split)-1; i += 2 {
|
||||||
|
if _, ok := m.matches[split[i+1]]; ok {
|
||||||
|
m.matches["beegfs_cmeta_"+split[i+1]] = split[i]
|
||||||
|
} else {
|
||||||
|
f1, err := strconv.ParseFloat(m.matches["other"], 32)
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(
|
||||||
|
m.name,
|
||||||
|
fmt.Sprintf("Metric (other): Failed to convert str written '%s' to float: %v", m.matches["other"], err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
f2, err := strconv.ParseFloat(split[i], 32)
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(
|
||||||
|
m.name,
|
||||||
|
fmt.Sprintf("Metric (other): Failed to convert str written '%s' to float: %v", m.matches["other"], err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
//mdStat["other"] = fmt.Sprintf("%f", f1+f2)
|
||||||
|
m.matches["beegfs_cstorage_other"] = fmt.Sprintf("%f", f1+f2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, data := range m.matches {
|
||||||
|
value, _ := strconv.ParseFloat(data, 32)
|
||||||
|
y, err := lp.NewMessage(key, m.tags, m.meta, map[string]interface{}{"value": value}, time.Now())
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *BeegfsMetaCollector) Close() {
|
||||||
|
m.init = false
|
||||||
|
}
|
||||||
75
collectors/beegfsmetaMetric.md
Normal file
75
collectors/beegfsmetaMetric.md
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
## `BeeGFS on Demand` collector
|
||||||
|
This Collector is to collect BeeGFS on Demand (BeeOND) metadata clientstats.
|
||||||
|
|
||||||
|
```json
|
||||||
|
"beegfs_meta": {
|
||||||
|
"beegfs_path": "/usr/bin/beegfs-ctl",
|
||||||
|
"exclude_filesystem": [
|
||||||
|
"/mnt/ignore_me"
|
||||||
|
],
|
||||||
|
"exclude_metrics": [
|
||||||
|
"ack",
|
||||||
|
"entInf",
|
||||||
|
"fndOwn"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `BeeGFS On Demand (BeeOND)` collector uses the `beegfs-ctl` command to read performance metrics for
|
||||||
|
BeeGFS filesystems.
|
||||||
|
|
||||||
|
The reported filesystems can be filtered with the `exclude_filesystem` option
|
||||||
|
in the configuration.
|
||||||
|
|
||||||
|
The path to the `beegfs-ctl` command can be configured with the `beegfs_path` option
|
||||||
|
in the configuration.
|
||||||
|
|
||||||
|
When using the `exclude_metrics` option, the excluded metrics are summed as `other`.
|
||||||
|
|
||||||
|
Important: The metrics listed below, are similar to the naming of BeeGFS. The Collector prefixes these with `beegfs_cstorage`(beegfs client storage).
|
||||||
|
|
||||||
|
For example beegfs metric `open`-> `beegfs_cstorage_open`
|
||||||
|
|
||||||
|
Available Metrics:
|
||||||
|
|
||||||
|
* sum
|
||||||
|
* ack
|
||||||
|
* close
|
||||||
|
* entInf
|
||||||
|
* fndOwn
|
||||||
|
* mkdir
|
||||||
|
* create
|
||||||
|
* rddir
|
||||||
|
* refrEnt
|
||||||
|
* mdsInf
|
||||||
|
* rmdir
|
||||||
|
* rmLnk
|
||||||
|
* mvDirIns
|
||||||
|
* mvFiIns
|
||||||
|
* open
|
||||||
|
* ren
|
||||||
|
* sChDrct
|
||||||
|
* sAttr
|
||||||
|
* sDirPat
|
||||||
|
* stat
|
||||||
|
* statfs
|
||||||
|
* trunc
|
||||||
|
* symlnk
|
||||||
|
* unlnk
|
||||||
|
* lookLI
|
||||||
|
* statLI
|
||||||
|
* revalLI
|
||||||
|
* openLI
|
||||||
|
* createLI
|
||||||
|
* hardlnk
|
||||||
|
* flckAp
|
||||||
|
* flckEn
|
||||||
|
* flckRg
|
||||||
|
* dirparent
|
||||||
|
* listXA
|
||||||
|
* getXA
|
||||||
|
* rmXA
|
||||||
|
* setXA
|
||||||
|
* mirror
|
||||||
|
|
||||||
|
The collector adds a `filesystem` tag to all metrics
|
||||||
222
collectors/beegfsstorageMetric.go
Normal file
222
collectors/beegfsstorageMetric.go
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
package collectors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"os/user"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Struct for the collector-specific JSON config
|
||||||
|
type BeegfsStorageCollectorConfig struct {
|
||||||
|
Beegfs string `json:"beegfs_path"`
|
||||||
|
ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
|
||||||
|
ExcludeFilesystem []string `json:"exclude_filesystem"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BeegfsStorageCollector struct {
|
||||||
|
metricCollector
|
||||||
|
tags map[string]string
|
||||||
|
matches map[string]string
|
||||||
|
config BeegfsStorageCollectorConfig
|
||||||
|
skipFS map[string]struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *BeegfsStorageCollector) Init(config json.RawMessage) error {
|
||||||
|
// Check if already initialized
|
||||||
|
if m.init {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// Metrics
|
||||||
|
var storageStat_array = [18]string{
|
||||||
|
"sum", "ack", "sChDrct", "getFSize",
|
||||||
|
"sAttr", "statfs", "trunc", "close",
|
||||||
|
"fsync", "ops-rd", "MiB-rd/s", "ops-wr",
|
||||||
|
"MiB-wr/s", "gendbg", "hrtbeat", "remNode",
|
||||||
|
"storInf", "unlnk"}
|
||||||
|
|
||||||
|
m.name = "BeegfsStorageCollector"
|
||||||
|
m.setup()
|
||||||
|
m.parallel = true
|
||||||
|
// Set default beegfs-ctl binary
|
||||||
|
|
||||||
|
m.config.Beegfs = DEFAULT_BEEGFS_CMD
|
||||||
|
|
||||||
|
// Read JSON configuration
|
||||||
|
if len(config) > 0 {
|
||||||
|
err := json.Unmarshal(config, &m.config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println(m.config.Beegfs)
|
||||||
|
//create map with possible variables
|
||||||
|
m.matches = make(map[string]string)
|
||||||
|
for _, value := range storageStat_array {
|
||||||
|
_, skip := stringArrayContains(m.config.ExcludeMetrics, value)
|
||||||
|
if skip {
|
||||||
|
m.matches["other"] = "0"
|
||||||
|
} else {
|
||||||
|
m.matches["beegfs_cstorage_"+value] = "0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.meta = map[string]string{
|
||||||
|
"source": m.name,
|
||||||
|
"group": "BeegfsStorage",
|
||||||
|
}
|
||||||
|
m.tags = map[string]string{
|
||||||
|
"type": "node",
|
||||||
|
"filesystem": "",
|
||||||
|
}
|
||||||
|
m.skipFS = make(map[string]struct{})
|
||||||
|
for _, fs := range m.config.ExcludeFilesystem {
|
||||||
|
m.skipFS[fs] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Beegfs file system statistics can only be queried by user root
|
||||||
|
user, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("BeegfsStorageCollector.Init(): Failed to get current user: %v", err)
|
||||||
|
}
|
||||||
|
if user.Uid != "0" {
|
||||||
|
return fmt.Errorf("BeegfsStorageCollector.Init(): BeeGFS file system statistics can only be queried by user root")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if beegfs-ctl is in executable search path
|
||||||
|
_, err = exec.LookPath(m.config.Beegfs)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("BeegfsStorageCollector.Init(): Failed to find beegfs-ctl binary '%s': %v", m.config.Beegfs, err)
|
||||||
|
}
|
||||||
|
m.init = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *BeegfsStorageCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
|
if !m.init {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//get mounpoint
|
||||||
|
buffer, _ := os.ReadFile(string("/proc/mounts"))
|
||||||
|
mounts := strings.Split(string(buffer), "\n")
|
||||||
|
var mountpoints []string
|
||||||
|
for _, line := range mounts {
|
||||||
|
if len(line) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
f := strings.Fields(line)
|
||||||
|
if strings.Contains(f[0], "beegfs_ondemand") {
|
||||||
|
// Skip excluded filesystems
|
||||||
|
if _, skip := m.skipFS[f[1]]; skip {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
mountpoints = append(mountpoints, f[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(mountpoints) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// collects stats for each BeeGFS on Demand FS
|
||||||
|
for _, mountpoint := range mountpoints {
|
||||||
|
m.tags["filesystem"] = mountpoint
|
||||||
|
|
||||||
|
// bwwgfs-ctl:
|
||||||
|
// --clientstats: Show client IO statistics.
|
||||||
|
// --nodetype=meta: The node type to query (meta, storage).
|
||||||
|
// --interval:
|
||||||
|
// --mount=/mnt/beeond/: Which mount point
|
||||||
|
//cmd := exec.Command(m.config.Beegfs, "/root/mc/test.txt")
|
||||||
|
mountoption := "--mount=" + mountpoint
|
||||||
|
cmd := exec.Command(m.config.Beegfs, "--clientstats",
|
||||||
|
"--nodetype=storage", mountoption, "--allstats")
|
||||||
|
cmd.Stdin = strings.NewReader("\n")
|
||||||
|
cmdStdout := new(bytes.Buffer)
|
||||||
|
cmdStderr := new(bytes.Buffer)
|
||||||
|
cmd.Stdout = cmdStdout
|
||||||
|
cmd.Stderr = cmdStderr
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "BeegfsStorageCollector.Read(): Failed to execute command \"%s\": %s\n", cmd.String(), err.Error())
|
||||||
|
fmt.Fprintf(os.Stderr, "BeegfsStorageCollector.Read(): command exit code: \"%d\"\n", cmd.ProcessState.ExitCode())
|
||||||
|
data, _ := io.ReadAll(cmdStderr)
|
||||||
|
fmt.Fprintf(os.Stderr, "BeegfsStorageCollector.Read(): command stderr: \"%s\"\n", string(data))
|
||||||
|
data, _ = io.ReadAll(cmdStdout)
|
||||||
|
fmt.Fprintf(os.Stderr, "BeegfsStorageCollector.Read(): command stdout: \"%s\"\n", string(data))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Read I/O statistics
|
||||||
|
scanner := bufio.NewScanner(cmdStdout)
|
||||||
|
|
||||||
|
sumLine := regexp.MustCompile(`^Sum:\s+\d+\s+\[[a-zA-Z]+\]+`)
|
||||||
|
//Line := regexp.MustCompile(`^(.*)\s+(\d)+\s+\[([a-zA-Z]+)\]+`)
|
||||||
|
statsLine := regexp.MustCompile(`^(.*?)\s+?(\d.*?)$`)
|
||||||
|
singleSpacePattern := regexp.MustCompile(`\s+`)
|
||||||
|
removePattern := regexp.MustCompile(`[\[|\]]`)
|
||||||
|
|
||||||
|
for scanner.Scan() {
|
||||||
|
readLine := scanner.Text()
|
||||||
|
//fmt.Println(readLine)
|
||||||
|
// Jump few lines, we only want the I/O stats from nodes
|
||||||
|
if !sumLine.MatchString(readLine) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
match := statsLine.FindStringSubmatch(readLine)
|
||||||
|
// nodeName = "Sum:" or would be nodes
|
||||||
|
// nodeName := match[1]
|
||||||
|
//Remove multiple whitespaces
|
||||||
|
dummy := removePattern.ReplaceAllString(match[2], " ")
|
||||||
|
metaStats := strings.TrimSpace(singleSpacePattern.ReplaceAllString(dummy, " "))
|
||||||
|
split := strings.Split(metaStats, " ")
|
||||||
|
|
||||||
|
// fill map with values
|
||||||
|
// split[i+1] = mdname
|
||||||
|
// split[i] = amount of operations
|
||||||
|
for i := 0; i <= len(split)-1; i += 2 {
|
||||||
|
if _, ok := m.matches[split[i+1]]; ok {
|
||||||
|
m.matches["beegfs_cstorage_"+split[i+1]] = split[i]
|
||||||
|
//m.matches[split[i+1]] = split[i]
|
||||||
|
} else {
|
||||||
|
f1, err := strconv.ParseFloat(m.matches["other"], 32)
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(
|
||||||
|
m.name,
|
||||||
|
fmt.Sprintf("Metric (other): Failed to convert str written '%s' to float: %v", m.matches["other"], err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
f2, err := strconv.ParseFloat(split[i], 32)
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(
|
||||||
|
m.name,
|
||||||
|
fmt.Sprintf("Metric (other): Failed to convert str written '%s' to float: %v", m.matches["other"], err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
m.matches["beegfs_cstorage_other"] = fmt.Sprintf("%f", f1+f2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, data := range m.matches {
|
||||||
|
value, _ := strconv.ParseFloat(data, 32)
|
||||||
|
y, err := lp.NewMessage(key, m.tags, m.meta, map[string]interface{}{"value": value}, time.Now())
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *BeegfsStorageCollector) Close() {
|
||||||
|
m.init = false
|
||||||
|
}
|
||||||
55
collectors/beegfsstorageMetric.md
Normal file
55
collectors/beegfsstorageMetric.md
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
## `BeeGFS on Demand` collector
|
||||||
|
This Collector is to collect BeeGFS on Demand (BeeOND) storage stats.
|
||||||
|
|
||||||
|
```json
|
||||||
|
"beegfs_storage": {
|
||||||
|
"beegfs_path": "/usr/bin/beegfs-ctl",
|
||||||
|
"exclude_filesystem": [
|
||||||
|
"/mnt/ignore_me"
|
||||||
|
],
|
||||||
|
"exclude_metrics": [
|
||||||
|
"ack",
|
||||||
|
"storInf",
|
||||||
|
"unlnk"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `BeeGFS On Demand (BeeOND)` collector uses the `beegfs-ctl` command to read performance metrics for BeeGFS filesystems.
|
||||||
|
|
||||||
|
The reported filesystems can be filtered with the `exclude_filesystem` option
|
||||||
|
in the configuration.
|
||||||
|
|
||||||
|
The path to the `beegfs-ctl` command can be configured with the `beegfs_path` option
|
||||||
|
in the configuration.
|
||||||
|
|
||||||
|
When using the `exclude_metrics` option, the excluded metrics are summed as `other`.
|
||||||
|
|
||||||
|
Important: The metrics listed below, are similar to the naming of BeeGFS. The Collector prefixes these with `beegfs_cstorage_`(beegfs client meta).
|
||||||
|
For example beegfs metric `open`-> `beegfs_cstorage_`
|
||||||
|
|
||||||
|
Note: BeeGFS FS offers many Metadata Information. Probably it makes sense to exlcude most of them. Nevertheless, these excluded metrics will be summed as `beegfs_cstorage_other`.
|
||||||
|
|
||||||
|
Available Metrics:
|
||||||
|
|
||||||
|
* "sum"
|
||||||
|
* "ack"
|
||||||
|
* "sChDrct"
|
||||||
|
* "getFSize"
|
||||||
|
* "sAttr"
|
||||||
|
* "statfs"
|
||||||
|
* "trunc"
|
||||||
|
* "close"
|
||||||
|
* "fsync"
|
||||||
|
* "ops-rd"
|
||||||
|
* "MiB-rd/s"
|
||||||
|
* "ops-wr"
|
||||||
|
* "MiB-wr/s"
|
||||||
|
* "endbg"
|
||||||
|
* "hrtbeat"
|
||||||
|
* "remNode"
|
||||||
|
* "storInf"
|
||||||
|
* "unlnk"
|
||||||
|
|
||||||
|
|
||||||
|
The collector adds a `filesystem` tag to all metrics
|
||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
mct "github.com/ClusterCockpit/cc-metric-collector/internal/multiChanTicker"
|
mct "github.com/ClusterCockpit/cc-metric-collector/pkg/multiChanTicker"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Map of all available metric collectors
|
// Map of all available metric collectors
|
||||||
@@ -19,7 +19,6 @@ var AvailableCollectors = map[string]MetricCollector{
|
|||||||
"memstat": new(MemstatCollector),
|
"memstat": new(MemstatCollector),
|
||||||
"netstat": new(NetstatCollector),
|
"netstat": new(NetstatCollector),
|
||||||
"ibstat": new(InfinibandCollector),
|
"ibstat": new(InfinibandCollector),
|
||||||
"ibstat_perfquery": new(InfinibandPerfQueryCollector),
|
|
||||||
"lustrestat": new(LustreCollector),
|
"lustrestat": new(LustreCollector),
|
||||||
"cpustat": new(CpustatCollector),
|
"cpustat": new(CpustatCollector),
|
||||||
"topprocs": new(TopProcsCollector),
|
"topprocs": new(TopProcsCollector),
|
||||||
@@ -35,23 +34,33 @@ var AvailableCollectors = map[string]MetricCollector{
|
|||||||
"nfs3stat": new(Nfs3Collector),
|
"nfs3stat": new(Nfs3Collector),
|
||||||
"nfs4stat": new(Nfs4Collector),
|
"nfs4stat": new(Nfs4Collector),
|
||||||
"numastats": new(NUMAStatsCollector),
|
"numastats": new(NUMAStatsCollector),
|
||||||
|
"beegfs_meta": new(BeegfsMetaCollector),
|
||||||
|
"beegfs_storage": new(BeegfsStorageCollector),
|
||||||
|
"rapl": new(RAPLCollector),
|
||||||
|
"rocm_smi": new(RocmSmiCollector),
|
||||||
|
"self": new(SelfCollector),
|
||||||
|
"schedstat": new(SchedstatCollector),
|
||||||
|
"nfsiostat": new(NfsIOStatCollector),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metric collector manager data structure
|
// Metric collector manager data structure
|
||||||
type collectorManager struct {
|
type collectorManager struct {
|
||||||
collectors []MetricCollector // List of metric collectors to use
|
collectors []MetricCollector // List of metric collectors to read in parallel
|
||||||
output chan lp.CCMetric // Output channels
|
serial []MetricCollector // List of metric collectors to read serially
|
||||||
|
output chan lp.CCMessage // Output channels
|
||||||
done chan bool // channel to finish / stop metric collector manager
|
done chan bool // channel to finish / stop metric collector manager
|
||||||
ticker mct.MultiChanTicker // periodically ticking once each interval
|
ticker mct.MultiChanTicker // periodically ticking once each interval
|
||||||
duration time.Duration // duration (for metrics that measure over a given duration)
|
duration time.Duration // duration (for metrics that measure over a given duration)
|
||||||
wg *sync.WaitGroup // wait group for all goroutines in cc-metric-collector
|
wg *sync.WaitGroup // wait group for all goroutines in cc-metric-collector
|
||||||
config map[string]json.RawMessage // json encoded config for collector manager
|
config map[string]json.RawMessage // json encoded config for collector manager
|
||||||
|
collector_wg sync.WaitGroup // internally used wait group for the parallel reading of collector
|
||||||
|
parallel_run bool // Flag whether the collectors are currently read in parallel
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metric collector manager access functions
|
// Metric collector manager access functions
|
||||||
type CollectorManager interface {
|
type CollectorManager interface {
|
||||||
Init(ticker mct.MultiChanTicker, duration time.Duration, wg *sync.WaitGroup, collectConfigFile string) error
|
Init(ticker mct.MultiChanTicker, duration time.Duration, wg *sync.WaitGroup, collectConfigFile string) error
|
||||||
AddOutput(output chan lp.CCMetric)
|
AddOutput(output chan lp.CCMessage)
|
||||||
Start()
|
Start()
|
||||||
Close()
|
Close()
|
||||||
}
|
}
|
||||||
@@ -65,6 +74,7 @@ type CollectorManager interface {
|
|||||||
// Initialization is done for all configured collectors
|
// Initialization is done for all configured collectors
|
||||||
func (cm *collectorManager) Init(ticker mct.MultiChanTicker, duration time.Duration, wg *sync.WaitGroup, collectConfigFile string) error {
|
func (cm *collectorManager) Init(ticker mct.MultiChanTicker, duration time.Duration, wg *sync.WaitGroup, collectConfigFile string) error {
|
||||||
cm.collectors = make([]MetricCollector, 0)
|
cm.collectors = make([]MetricCollector, 0)
|
||||||
|
cm.serial = make([]MetricCollector, 0)
|
||||||
cm.output = nil
|
cm.output = nil
|
||||||
cm.done = make(chan bool)
|
cm.done = make(chan bool)
|
||||||
cm.wg = wg
|
cm.wg = wg
|
||||||
@@ -99,7 +109,11 @@ func (cm *collectorManager) Init(ticker mct.MultiChanTicker, duration time.Durat
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cclog.ComponentDebug("CollectorManager", "ADD COLLECTOR", collector.Name())
|
cclog.ComponentDebug("CollectorManager", "ADD COLLECTOR", collector.Name())
|
||||||
|
if collector.Parallel() {
|
||||||
cm.collectors = append(cm.collectors, collector)
|
cm.collectors = append(cm.collectors, collector)
|
||||||
|
} else {
|
||||||
|
cm.serial = append(cm.serial, collector)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -115,6 +129,10 @@ func (cm *collectorManager) Start() {
|
|||||||
// Collector manager is done
|
// Collector manager is done
|
||||||
done := func() {
|
done := func() {
|
||||||
// close all metric collectors
|
// close all metric collectors
|
||||||
|
if cm.parallel_run {
|
||||||
|
cm.collector_wg.Wait()
|
||||||
|
cm.parallel_run = false
|
||||||
|
}
|
||||||
for _, c := range cm.collectors {
|
for _, c := range cm.collectors {
|
||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
@@ -129,7 +147,26 @@ func (cm *collectorManager) Start() {
|
|||||||
done()
|
done()
|
||||||
return
|
return
|
||||||
case t := <-tick:
|
case t := <-tick:
|
||||||
|
cm.parallel_run = true
|
||||||
for _, c := range cm.collectors {
|
for _, c := range cm.collectors {
|
||||||
|
// Wait for done signal or execute the collector
|
||||||
|
select {
|
||||||
|
case <-cm.done:
|
||||||
|
done()
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
// Read metrics from collector c via goroutine
|
||||||
|
cclog.ComponentDebug("CollectorManager", c.Name(), t)
|
||||||
|
cm.collector_wg.Add(1)
|
||||||
|
go func(myc MetricCollector) {
|
||||||
|
myc.Read(cm.duration, cm.output)
|
||||||
|
cm.collector_wg.Done()
|
||||||
|
}(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cm.collector_wg.Wait()
|
||||||
|
cm.parallel_run = false
|
||||||
|
for _, c := range cm.serial {
|
||||||
// Wait for done signal or execute the collector
|
// Wait for done signal or execute the collector
|
||||||
select {
|
select {
|
||||||
case <-cm.done:
|
case <-cm.done:
|
||||||
@@ -150,7 +187,7 @@ func (cm *collectorManager) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddOutput adds the output channel to the metric collector manager
|
// AddOutput adds the output channel to the metric collector manager
|
||||||
func (cm *collectorManager) AddOutput(output chan lp.CCMetric) {
|
func (cm *collectorManager) AddOutput(output chan lp.CCMessage) {
|
||||||
cm.output = output
|
cm.output = output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,33 +10,22 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
)
|
)
|
||||||
|
|
||||||
//
|
|
||||||
// CPUFreqCollector
|
// CPUFreqCollector
|
||||||
// a metric collector to measure the current frequency of the CPUs
|
// a metric collector to measure the current frequency of the CPUs
|
||||||
// as obtained from /proc/cpuinfo
|
// as obtained from /proc/cpuinfo
|
||||||
// Only measure on the first hyperthread
|
// Only measure on the first hyperthread
|
||||||
//
|
|
||||||
type CPUFreqCpuInfoCollectorTopology struct {
|
type CPUFreqCpuInfoCollectorTopology struct {
|
||||||
processor string // logical processor number (continuous, starting at 0)
|
|
||||||
coreID string // socket local core ID
|
|
||||||
coreID_int int64
|
|
||||||
physicalPackageID string // socket / package ID
|
|
||||||
physicalPackageID_int int64
|
|
||||||
numPhysicalPackages string // number of sockets / packages
|
|
||||||
numPhysicalPackages_int int64
|
|
||||||
isHT bool
|
isHT bool
|
||||||
numNonHT string // number of non hyperthreading processors
|
|
||||||
numNonHT_int int64
|
|
||||||
tagSet map[string]string
|
tagSet map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type CPUFreqCpuInfoCollector struct {
|
type CPUFreqCpuInfoCollector struct {
|
||||||
metricCollector
|
metricCollector
|
||||||
topology []*CPUFreqCpuInfoCollectorTopology
|
topology []CPUFreqCpuInfoCollectorTopology
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CPUFreqCpuInfoCollector) Init(config json.RawMessage) error {
|
func (m *CPUFreqCpuInfoCollector) Init(config json.RawMessage) error {
|
||||||
@@ -48,6 +37,7 @@ func (m *CPUFreqCpuInfoCollector) Init(config json.RawMessage) error {
|
|||||||
m.setup()
|
m.setup()
|
||||||
|
|
||||||
m.name = "CPUFreqCpuInfoCollector"
|
m.name = "CPUFreqCpuInfoCollector"
|
||||||
|
m.parallel = true
|
||||||
m.meta = map[string]string{
|
m.meta = map[string]string{
|
||||||
"source": m.name,
|
"source": m.name,
|
||||||
"group": "CPU",
|
"group": "CPU",
|
||||||
@@ -57,18 +47,16 @@ func (m *CPUFreqCpuInfoCollector) Init(config json.RawMessage) error {
|
|||||||
const cpuInfoFile = "/proc/cpuinfo"
|
const cpuInfoFile = "/proc/cpuinfo"
|
||||||
file, err := os.Open(cpuInfoFile)
|
file, err := os.Open(cpuInfoFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to open file '%s': %v", cpuInfoFile, err)
|
return fmt.Errorf("failed to open file '%s': %v", cpuInfoFile, err)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
// Collect topology information from file cpuinfo
|
// Collect topology information from file cpuinfo
|
||||||
foundFreq := false
|
foundFreq := false
|
||||||
processor := ""
|
processor := ""
|
||||||
var numNonHT_int int64 = 0
|
|
||||||
coreID := ""
|
coreID := ""
|
||||||
physicalPackageID := ""
|
physicalPackageID := ""
|
||||||
var maxPhysicalPackageID int64 = 0
|
m.topology = make([]CPUFreqCpuInfoCollectorTopology, 0)
|
||||||
m.topology = make([]*CPUFreqCpuInfoCollectorTopology, 0)
|
|
||||||
coreSeenBefore := make(map[string]bool)
|
coreSeenBefore := make(map[string]bool)
|
||||||
|
|
||||||
// Read cpuinfo file, line by line
|
// Read cpuinfo file, line by line
|
||||||
@@ -97,41 +85,22 @@ func (m *CPUFreqCpuInfoCollector) Init(config json.RawMessage) error {
|
|||||||
len(coreID) > 0 &&
|
len(coreID) > 0 &&
|
||||||
len(physicalPackageID) > 0 {
|
len(physicalPackageID) > 0 {
|
||||||
|
|
||||||
topology := new(CPUFreqCpuInfoCollectorTopology)
|
|
||||||
|
|
||||||
// Processor
|
|
||||||
topology.processor = processor
|
|
||||||
|
|
||||||
// Core ID
|
|
||||||
topology.coreID = coreID
|
|
||||||
topology.coreID_int, err = strconv.ParseInt(coreID, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Unable to convert coreID '%s' to int64: %v", coreID, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Physical package ID
|
|
||||||
topology.physicalPackageID = physicalPackageID
|
|
||||||
topology.physicalPackageID_int, err = strconv.ParseInt(physicalPackageID, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Unable to convert physicalPackageID '%s' to int64: %v", physicalPackageID, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// increase maximun socket / package ID, when required
|
|
||||||
if topology.physicalPackageID_int > maxPhysicalPackageID {
|
|
||||||
maxPhysicalPackageID = topology.physicalPackageID_int
|
|
||||||
}
|
|
||||||
|
|
||||||
// is hyperthread?
|
|
||||||
globalID := physicalPackageID + ":" + coreID
|
globalID := physicalPackageID + ":" + coreID
|
||||||
topology.isHT = coreSeenBefore[globalID]
|
|
||||||
coreSeenBefore[globalID] = true
|
|
||||||
if !topology.isHT {
|
|
||||||
// increase number on non hyper thread cores
|
|
||||||
numNonHT_int++
|
|
||||||
}
|
|
||||||
|
|
||||||
// store collected topology information
|
// store collected topology information
|
||||||
m.topology = append(m.topology, topology)
|
m.topology = append(m.topology,
|
||||||
|
CPUFreqCpuInfoCollectorTopology{
|
||||||
|
isHT: coreSeenBefore[globalID],
|
||||||
|
tagSet: map[string]string{
|
||||||
|
"type": "hwthread",
|
||||||
|
"type-id": processor,
|
||||||
|
"package_id": physicalPackageID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// mark core as seen before
|
||||||
|
coreSeenBefore[globalID] = true
|
||||||
|
|
||||||
// reset topology information
|
// reset topology information
|
||||||
foundFreq = false
|
foundFreq = false
|
||||||
@@ -141,26 +110,16 @@ func (m *CPUFreqCpuInfoCollector) Init(config json.RawMessage) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
numPhysicalPackageID_int := maxPhysicalPackageID + 1
|
// Check if at least one CPU with frequency information was detected
|
||||||
numPhysicalPackageID := fmt.Sprint(numPhysicalPackageID_int)
|
if len(m.topology) == 0 {
|
||||||
numNonHT := fmt.Sprint(numNonHT_int)
|
return fmt.Errorf("no CPU frequency info found in %s", cpuInfoFile)
|
||||||
for _, t := range m.topology {
|
|
||||||
t.numPhysicalPackages = numPhysicalPackageID
|
|
||||||
t.numPhysicalPackages_int = numPhysicalPackageID_int
|
|
||||||
t.numNonHT = numNonHT
|
|
||||||
t.numNonHT_int = numNonHT_int
|
|
||||||
t.tagSet = map[string]string{
|
|
||||||
"type": "cpu",
|
|
||||||
"type-id": t.processor,
|
|
||||||
"package_id": t.physicalPackageID,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m.init = true
|
m.init = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CPUFreqCpuInfoCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *CPUFreqCpuInfoCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
// Check if already initialized
|
// Check if already initialized
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
@@ -195,7 +154,7 @@ func (m *CPUFreqCpuInfoCollector) Read(interval time.Duration, output chan lp.CC
|
|||||||
fmt.Sprintf("Read(): Failed to convert cpu MHz '%s' to float64: %v", lineSplit[1], err))
|
fmt.Sprintf("Read(): Failed to convert cpu MHz '%s' to float64: %v", lineSplit[1], err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if y, err := lp.New("cpufreq", t.tagSet, m.meta, map[string]interface{}{"value": value}, now); err == nil {
|
if y, err := lp.NewMessage("cpufreq", t.tagSet, m.meta, map[string]interface{}{"value": value}, now); err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
|
||||||
## `cpufreq_cpuinfo` collector
|
## `cpufreq_cpuinfo` collector
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"cpufreq_cpuinfo": {}
|
"cpufreq_cpuinfo": {}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `cpufreq_cpuinfo` collector reads the clock frequency from `/proc/cpuinfo` and outputs a handful **cpu** metrics.
|
The `cpufreq_cpuinfo` collector reads the clock frequency from `/proc/cpuinfo` and outputs a handful **hwthread** metrics.
|
||||||
|
|
||||||
Metrics:
|
Metrics:
|
||||||
|
|
||||||
* `cpufreq`
|
* `cpufreq`
|
||||||
|
|||||||
@@ -3,40 +3,29 @@ package collectors
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
"github.com/ClusterCockpit/cc-metric-collector/pkg/ccTopology"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CPUFreqCollectorTopology struct {
|
type CPUFreqCollectorTopology struct {
|
||||||
processor string // logical processor number (continuous, starting at 0)
|
|
||||||
coreID string // socket local core ID
|
|
||||||
coreID_int int64
|
|
||||||
physicalPackageID string // socket / package ID
|
|
||||||
physicalPackageID_int int64
|
|
||||||
numPhysicalPackages string // number of sockets / packages
|
|
||||||
numPhysicalPackages_int int64
|
|
||||||
isHT bool
|
|
||||||
numNonHT string // number of non hyperthreading processors
|
|
||||||
numNonHT_int int64
|
|
||||||
scalingCurFreqFile string
|
scalingCurFreqFile string
|
||||||
tagSet map[string]string
|
tagSet map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// CPUFreqCollector
|
// CPUFreqCollector
|
||||||
// a metric collector to measure the current frequency of the CPUs
|
// a metric collector to measure the current frequency of the CPUs
|
||||||
// as obtained from the hardware (in KHz)
|
// as obtained from the hardware (in KHz)
|
||||||
// Only measure on the first hyper thread
|
// Only measure on the first hyper-thread
|
||||||
//
|
//
|
||||||
// See: https://www.kernel.org/doc/html/latest/admin-guide/pm/cpufreq.html
|
// See: https://www.kernel.org/doc/html/latest/admin-guide/pm/cpufreq.html
|
||||||
//
|
|
||||||
type CPUFreqCollector struct {
|
type CPUFreqCollector struct {
|
||||||
metricCollector
|
metricCollector
|
||||||
topology []CPUFreqCollectorTopology
|
topology []CPUFreqCollectorTopology
|
||||||
@@ -53,6 +42,7 @@ func (m *CPUFreqCollector) Init(config json.RawMessage) error {
|
|||||||
|
|
||||||
m.name = "CPUFreqCollector"
|
m.name = "CPUFreqCollector"
|
||||||
m.setup()
|
m.setup()
|
||||||
|
m.parallel = true
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err := json.Unmarshal(config, &m.config)
|
err := json.Unmarshal(config, &m.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -62,116 +52,46 @@ func (m *CPUFreqCollector) Init(config json.RawMessage) error {
|
|||||||
m.meta = map[string]string{
|
m.meta = map[string]string{
|
||||||
"source": m.name,
|
"source": m.name,
|
||||||
"group": "CPU",
|
"group": "CPU",
|
||||||
"unit": "MHz",
|
"unit": "Hz",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop for all CPU directories
|
m.topology = make([]CPUFreqCollectorTopology, 0)
|
||||||
baseDir := "/sys/devices/system/cpu"
|
for _, c := range ccTopology.CpuData() {
|
||||||
globPattern := filepath.Join(baseDir, "cpu[0-9]*")
|
|
||||||
cpuDirs, err := filepath.Glob(globPattern)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Unable to glob files with pattern '%s': %v", globPattern, err)
|
|
||||||
}
|
|
||||||
if cpuDirs == nil {
|
|
||||||
return fmt.Errorf("Unable to find any files with pattern '%s'", globPattern)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize CPU topology
|
// Skip hyper threading CPUs
|
||||||
m.topology = make([]CPUFreqCollectorTopology, len(cpuDirs))
|
if c.CpuID != c.CoreCPUsList[0] {
|
||||||
for _, cpuDir := range cpuDirs {
|
continue
|
||||||
processor := strings.TrimPrefix(cpuDir, "/sys/devices/system/cpu/cpu")
|
|
||||||
processor_int, err := strconv.ParseInt(processor, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Unable to convert cpuID '%s' to int64: %v", processor, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read package ID
|
|
||||||
physicalPackageIDFile := filepath.Join(cpuDir, "topology", "physical_package_id")
|
|
||||||
line, err := ioutil.ReadFile(physicalPackageIDFile)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Unable to read physical package ID from file '%s': %v", physicalPackageIDFile, err)
|
|
||||||
}
|
|
||||||
physicalPackageID := strings.TrimSpace(string(line))
|
|
||||||
physicalPackageID_int, err := strconv.ParseInt(physicalPackageID, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Unable to convert packageID '%s' to int64: %v", physicalPackageID, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read core ID
|
|
||||||
coreIDFile := filepath.Join(cpuDir, "topology", "core_id")
|
|
||||||
line, err = ioutil.ReadFile(coreIDFile)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Unable to read core ID from file '%s': %v", coreIDFile, err)
|
|
||||||
}
|
|
||||||
coreID := strings.TrimSpace(string(line))
|
|
||||||
coreID_int, err := strconv.ParseInt(coreID, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Unable to convert coreID '%s' to int64: %v", coreID, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check access to current frequency file
|
// Check access to current frequency file
|
||||||
scalingCurFreqFile := filepath.Join(cpuDir, "cpufreq", "scaling_cur_freq")
|
scalingCurFreqFile := filepath.Join("/sys/devices/system/cpu", fmt.Sprintf("cpu%d", c.CpuID), "cpufreq/scaling_cur_freq")
|
||||||
err = unix.Access(scalingCurFreqFile, unix.R_OK)
|
err := unix.Access(scalingCurFreqFile, unix.R_OK)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to access file '%s': %v", scalingCurFreqFile, err)
|
return fmt.Errorf("unable to access file '%s': %v", scalingCurFreqFile, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t := &m.topology[processor_int]
|
m.topology = append(m.topology,
|
||||||
t.processor = processor
|
CPUFreqCollectorTopology{
|
||||||
t.physicalPackageID = physicalPackageID
|
tagSet: map[string]string{
|
||||||
t.physicalPackageID_int = physicalPackageID_int
|
"type": "hwthread",
|
||||||
t.coreID = coreID
|
"type-id": fmt.Sprint(c.CpuID),
|
||||||
t.coreID_int = coreID_int
|
"package_id": fmt.Sprint(c.Socket),
|
||||||
t.scalingCurFreqFile = scalingCurFreqFile
|
},
|
||||||
}
|
scalingCurFreqFile: scalingCurFreqFile,
|
||||||
|
},
|
||||||
// is processor a hyperthread?
|
)
|
||||||
coreSeenBefore := make(map[string]bool)
|
|
||||||
for i := range m.topology {
|
|
||||||
t := &m.topology[i]
|
|
||||||
|
|
||||||
globalID := t.physicalPackageID + ":" + t.coreID
|
|
||||||
t.isHT = coreSeenBefore[globalID]
|
|
||||||
coreSeenBefore[globalID] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// number of non hyper thread cores and packages / sockets
|
|
||||||
var numNonHT_int int64 = 0
|
|
||||||
var maxPhysicalPackageID int64 = 0
|
|
||||||
for i := range m.topology {
|
|
||||||
t := &m.topology[i]
|
|
||||||
|
|
||||||
// Update maxPackageID
|
|
||||||
if t.physicalPackageID_int > maxPhysicalPackageID {
|
|
||||||
maxPhysicalPackageID = t.physicalPackageID_int
|
|
||||||
}
|
|
||||||
|
|
||||||
if !t.isHT {
|
|
||||||
numNonHT_int++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
numPhysicalPackageID_int := maxPhysicalPackageID + 1
|
|
||||||
numPhysicalPackageID := fmt.Sprint(numPhysicalPackageID_int)
|
|
||||||
numNonHT := fmt.Sprint(numNonHT_int)
|
|
||||||
for i := range m.topology {
|
|
||||||
t := &m.topology[i]
|
|
||||||
t.numPhysicalPackages = numPhysicalPackageID
|
|
||||||
t.numPhysicalPackages_int = numPhysicalPackageID_int
|
|
||||||
t.numNonHT = numNonHT
|
|
||||||
t.numNonHT_int = numNonHT_int
|
|
||||||
t.tagSet = map[string]string{
|
|
||||||
"type": "cpu",
|
|
||||||
"type-id": t.processor,
|
|
||||||
"package_id": t.physicalPackageID,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialized
|
||||||
|
cclog.ComponentDebug(
|
||||||
|
m.name,
|
||||||
|
"initialized",
|
||||||
|
len(m.topology), "non-hyper-threading CPUs")
|
||||||
m.init = true
|
m.init = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CPUFreqCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *CPUFreqCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
// Check if already initialized
|
// Check if already initialized
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
@@ -181,13 +101,8 @@ func (m *CPUFreqCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
for i := range m.topology {
|
for i := range m.topology {
|
||||||
t := &m.topology[i]
|
t := &m.topology[i]
|
||||||
|
|
||||||
// skip hyperthreads
|
|
||||||
if t.isHT {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read current frequency
|
// Read current frequency
|
||||||
line, err := ioutil.ReadFile(t.scalingCurFreqFile)
|
line, err := os.ReadFile(t.scalingCurFreqFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.ComponentError(
|
cclog.ComponentError(
|
||||||
m.name,
|
m.name,
|
||||||
@@ -202,7 +117,7 @@ func (m *CPUFreqCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if y, err := lp.New("cpufreq", t.tagSet, m.meta, map[string]interface{}{"value": cpuFreq}, now); err == nil {
|
if y, err := lp.NewMessage("cpufreq", t.tagSet, m.meta, map[string]interface{}{"value": cpuFreq}, now); err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
## `cpufreq_cpuinfo` collector
|
## `cpufreq_cpuinfo` collector
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"cpufreq": {
|
"cpufreq": {
|
||||||
"exclude_metrics": []
|
"exclude_metrics": []
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `cpufreq` collector reads the clock frequency from `/sys/devices/system/cpu/cpu*/cpufreq` and outputs a handful **cpu** metrics.
|
The `cpufreq` collector reads the clock frequency from `/sys/devices/system/cpu/cpu*/cpufreq` and outputs a handful **hwthread** metrics.
|
||||||
|
|
||||||
Metrics:
|
Metrics:
|
||||||
|
|
||||||
* `cpufreq`
|
* `cpufreq`
|
||||||
@@ -9,8 +9,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
sysconf "github.com/tklauser/go-sysconf"
|
||||||
)
|
)
|
||||||
|
|
||||||
const CPUSTATFILE = `/proc/stat`
|
const CPUSTATFILE = `/proc/stat`
|
||||||
@@ -22,16 +23,18 @@ type CpustatCollectorConfig struct {
|
|||||||
type CpustatCollector struct {
|
type CpustatCollector struct {
|
||||||
metricCollector
|
metricCollector
|
||||||
config CpustatCollectorConfig
|
config CpustatCollectorConfig
|
||||||
|
lastTimestamp time.Time // Store time stamp of last tick to derive values
|
||||||
matches map[string]int
|
matches map[string]int
|
||||||
cputags map[string]map[string]string
|
cputags map[string]map[string]string
|
||||||
nodetags map[string]string
|
nodetags map[string]string
|
||||||
num_cpus_metric lp.CCMetric
|
olddata map[string]map[string]int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CpustatCollector) Init(config json.RawMessage) error {
|
func (m *CpustatCollector) Init(config json.RawMessage) error {
|
||||||
m.name = "CpustatCollector"
|
m.name = "CpustatCollector"
|
||||||
m.setup()
|
m.setup()
|
||||||
m.meta = map[string]string{"source": m.name, "group": "CPU", "unit": "Percent"}
|
m.parallel = true
|
||||||
|
m.meta = map[string]string{"source": m.name, "group": "CPU"}
|
||||||
m.nodetags = map[string]string{"type": "node"}
|
m.nodetags = map[string]string{"type": "node"}
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err := json.Unmarshal(config, &m.config)
|
err := json.Unmarshal(config, &m.config)
|
||||||
@@ -76,47 +79,73 @@ func (m *CpustatCollector) Init(config json.RawMessage) error {
|
|||||||
// Pre-generate tags for all CPUs
|
// Pre-generate tags for all CPUs
|
||||||
num_cpus := 0
|
num_cpus := 0
|
||||||
m.cputags = make(map[string]map[string]string)
|
m.cputags = make(map[string]map[string]string)
|
||||||
|
m.olddata = make(map[string]map[string]int64)
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
linefields := strings.Fields(line)
|
linefields := strings.Fields(line)
|
||||||
if strings.HasPrefix(linefields[0], "cpu") && strings.Compare(linefields[0], "cpu") != 0 {
|
if strings.Compare(linefields[0], "cpu") == 0 {
|
||||||
|
m.olddata["cpu"] = make(map[string]int64)
|
||||||
|
for k, v := range m.matches {
|
||||||
|
m.olddata["cpu"][k], _ = strconv.ParseInt(linefields[v], 0, 64)
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(linefields[0], "cpu") && strings.Compare(linefields[0], "cpu") != 0 {
|
||||||
cpustr := strings.TrimLeft(linefields[0], "cpu")
|
cpustr := strings.TrimLeft(linefields[0], "cpu")
|
||||||
cpu, _ := strconv.Atoi(cpustr)
|
cpu, _ := strconv.Atoi(cpustr)
|
||||||
m.cputags[linefields[0]] = map[string]string{"type": "cpu", "type-id": fmt.Sprintf("%d", cpu)}
|
m.cputags[linefields[0]] = map[string]string{"type": "hwthread", "type-id": fmt.Sprintf("%d", cpu)}
|
||||||
|
m.olddata[linefields[0]] = make(map[string]int64)
|
||||||
|
for k, v := range m.matches {
|
||||||
|
m.olddata[linefields[0]][k], _ = strconv.ParseInt(linefields[v], 0, 64)
|
||||||
|
}
|
||||||
num_cpus++
|
num_cpus++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m.lastTimestamp = time.Now()
|
||||||
m.init = true
|
m.init = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CpustatCollector) parseStatLine(linefields []string, tags map[string]string, output chan lp.CCMetric) {
|
func (m *CpustatCollector) parseStatLine(linefields []string, tags map[string]string, output chan lp.CCMessage, now time.Time, tsdelta time.Duration) {
|
||||||
values := make(map[string]float64)
|
values := make(map[string]float64)
|
||||||
total := 0.0
|
clktck, _ := sysconf.Sysconf(sysconf.SC_CLK_TCK)
|
||||||
for match, index := range m.matches {
|
for match, index := range m.matches {
|
||||||
if len(match) > 0 {
|
if len(match) > 0 {
|
||||||
x, err := strconv.ParseInt(linefields[index], 0, 64)
|
x, err := strconv.ParseInt(linefields[index], 0, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
values[match] = float64(x)
|
vdiff := x - m.olddata[linefields[0]][match]
|
||||||
total += values[match]
|
m.olddata[linefields[0]][match] = x // Store new value for next run
|
||||||
|
values[match] = float64(vdiff) / float64(tsdelta.Seconds()) / float64(clktck)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t := time.Now()
|
|
||||||
|
sum := float64(0)
|
||||||
for name, value := range values {
|
for name, value := range values {
|
||||||
y, err := lp.New(name, tags, m.meta, map[string]interface{}{"value": (value * 100.0) / total}, t)
|
sum += value
|
||||||
|
y, err := lp.NewMessage(name, tags, m.meta, map[string]interface{}{"value": value * 100}, now)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
y.AddTag("unit", "Percent")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := values["cpu_idle"]; ok {
|
||||||
|
sum -= v
|
||||||
|
y, err := lp.NewMessage("cpu_used", tags, m.meta, map[string]interface{}{"value": sum * 100}, now)
|
||||||
|
if err == nil {
|
||||||
|
y.AddTag("unit", "Percent")
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CpustatCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *CpustatCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
num_cpus := 0
|
num_cpus := 0
|
||||||
|
now := time.Now()
|
||||||
|
tsdelta := now.Sub(m.lastTimestamp)
|
||||||
|
|
||||||
file, err := os.Open(string(CPUSTATFILE))
|
file, err := os.Open(string(CPUSTATFILE))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.ComponentError(m.name, err.Error())
|
cclog.ComponentError(m.name, err.Error())
|
||||||
@@ -128,22 +157,24 @@ func (m *CpustatCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
linefields := strings.Fields(line)
|
linefields := strings.Fields(line)
|
||||||
if strings.Compare(linefields[0], "cpu") == 0 {
|
if strings.Compare(linefields[0], "cpu") == 0 {
|
||||||
m.parseStatLine(linefields, m.nodetags, output)
|
m.parseStatLine(linefields, m.nodetags, output, now, tsdelta)
|
||||||
} else if strings.HasPrefix(linefields[0], "cpu") {
|
} else if strings.HasPrefix(linefields[0], "cpu") {
|
||||||
m.parseStatLine(linefields, m.cputags[linefields[0]], output)
|
m.parseStatLine(linefields, m.cputags[linefields[0]], output, now, tsdelta)
|
||||||
num_cpus++
|
num_cpus++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
num_cpus_metric, err := lp.New("num_cpus",
|
num_cpus_metric, err := lp.NewMessage("num_cpus",
|
||||||
m.nodetags,
|
m.nodetags,
|
||||||
m.meta,
|
m.meta,
|
||||||
map[string]interface{}{"value": int(num_cpus)},
|
map[string]interface{}{"value": int(num_cpus)},
|
||||||
time.Now(),
|
now,
|
||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
output <- num_cpus_metric
|
output <- num_cpus_metric
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.lastTimestamp = now
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CpustatCollector) Close() {
|
func (m *CpustatCollector) Close() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
## `cpustat` collector
|
## `cpustat` collector
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"cpustat": {
|
"cpustat": {
|
||||||
"exclude_metrics": [
|
"exclude_metrics": [
|
||||||
@@ -8,16 +9,19 @@
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `cpustat` collector reads data from `/proc/stats` and outputs a handful **node** and **hwthread** metrics. If a metric is not required, it can be excluded from forwarding it to the sink.
|
The `cpustat` collector reads data from `/proc/stat` and outputs a handful **node** and **hwthread** metrics. If a metric is not required, it can be excluded from forwarding it to the sink.
|
||||||
|
|
||||||
Metrics:
|
Metrics:
|
||||||
* `cpu_user`
|
|
||||||
* `cpu_nice`
|
* `cpu_user` with `unit=Percent`
|
||||||
* `cpu_system`
|
* `cpu_nice` with `unit=Percent`
|
||||||
* `cpu_idle`
|
* `cpu_system` with `unit=Percent`
|
||||||
* `cpu_iowait`
|
* `cpu_idle` with `unit=Percent`
|
||||||
* `cpu_irq`
|
* `cpu_iowait` with `unit=Percent`
|
||||||
* `cpu_softirq`
|
* `cpu_irq` with `unit=Percent`
|
||||||
* `cpu_steal`
|
* `cpu_softirq` with `unit=Percent`
|
||||||
* `cpu_guest`
|
* `cpu_steal` with `unit=Percent`
|
||||||
* `cpu_guest_nice`
|
* `cpu_guest` with `unit=Percent`
|
||||||
|
* `cpu_guest_nice` with `unit=Percent`
|
||||||
|
* `cpu_used` = `cpu_* - cpu_idle` with `unit=Percent`
|
||||||
|
* `num_cpus`
|
||||||
@@ -3,13 +3,13 @@ package collectors
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
influx "github.com/influxdata/line-protocol"
|
influx "github.com/influxdata/line-protocol"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,6 +33,7 @@ type CustomCmdCollector struct {
|
|||||||
func (m *CustomCmdCollector) Init(config json.RawMessage) error {
|
func (m *CustomCmdCollector) Init(config json.RawMessage) error {
|
||||||
var err error
|
var err error
|
||||||
m.name = "CustomCmdCollector"
|
m.name = "CustomCmdCollector"
|
||||||
|
m.parallel = true
|
||||||
m.meta = map[string]string{"source": m.name, "group": "Custom"}
|
m.meta = map[string]string{"source": m.name, "group": "Custom"}
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err = json.Unmarshal(config, &m.config)
|
err = json.Unmarshal(config, &m.config)
|
||||||
@@ -47,12 +48,12 @@ func (m *CustomCmdCollector) Init(config json.RawMessage) error {
|
|||||||
command := exec.Command(cmdfields[0], strings.Join(cmdfields[1:], " "))
|
command := exec.Command(cmdfields[0], strings.Join(cmdfields[1:], " "))
|
||||||
command.Wait()
|
command.Wait()
|
||||||
_, err = command.Output()
|
_, err = command.Output()
|
||||||
if err != nil {
|
if err == nil {
|
||||||
m.commands = append(m.commands, c)
|
m.commands = append(m.commands, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, f := range m.config.Files {
|
for _, f := range m.config.Files {
|
||||||
_, err = ioutil.ReadFile(f)
|
_, err = os.ReadFile(f)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
m.files = append(m.files, f)
|
m.files = append(m.files, f)
|
||||||
} else {
|
} else {
|
||||||
@@ -61,7 +62,7 @@ func (m *CustomCmdCollector) Init(config json.RawMessage) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(m.files) == 0 && len(m.commands) == 0 {
|
if len(m.files) == 0 && len(m.commands) == 0 {
|
||||||
return errors.New("No metrics to collect")
|
return errors.New("no metrics to collect")
|
||||||
}
|
}
|
||||||
m.handler = influx.NewMetricHandler()
|
m.handler = influx.NewMetricHandler()
|
||||||
m.parser = influx.NewParser(m.handler)
|
m.parser = influx.NewParser(m.handler)
|
||||||
@@ -74,7 +75,7 @@ var DefaultTime = func() time.Time {
|
|||||||
return time.Unix(42, 0)
|
return time.Unix(42, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CustomCmdCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *CustomCmdCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -98,14 +99,11 @@ func (m *CustomCmdCollector) Read(interval time.Duration, output chan lp.CCMetri
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
y := lp.FromInfluxMetric(c)
|
output <- lp.FromInfluxMetric(c)
|
||||||
if err == nil {
|
|
||||||
output <- y
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, file := range m.files {
|
for _, file := range m.files {
|
||||||
buffer, err := ioutil.ReadFile(file)
|
buffer, err := os.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
return
|
return
|
||||||
@@ -120,10 +118,7 @@ func (m *CustomCmdCollector) Read(interval time.Duration, output chan lp.CCMetri
|
|||||||
if skip {
|
if skip {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
y := lp.FromInfluxMetric(f)
|
output <- lp.FromInfluxMetric(f)
|
||||||
if err == nil {
|
|
||||||
output <- y
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ package collectors
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
// "log"
|
// "log"
|
||||||
@@ -30,6 +29,7 @@ type DiskstatCollector struct {
|
|||||||
|
|
||||||
func (m *DiskstatCollector) Init(config json.RawMessage) error {
|
func (m *DiskstatCollector) Init(config json.RawMessage) error {
|
||||||
m.name = "DiskstatCollector"
|
m.name = "DiskstatCollector"
|
||||||
|
m.parallel = true
|
||||||
m.meta = map[string]string{"source": m.name, "group": "Disk"}
|
m.meta = map[string]string{"source": m.name, "group": "Disk"}
|
||||||
m.setup()
|
m.setup()
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
@@ -48,7 +48,7 @@ func (m *DiskstatCollector) Init(config json.RawMessage) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *DiskstatCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *DiskstatCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -78,31 +78,39 @@ func (m *DiskstatCollector) Read(interval time.Duration, output chan lp.CCMetric
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
path := strings.Replace(linefields[1], `\040`, " ", -1)
|
path := strings.Replace(linefields[1], `\040`, " ", -1)
|
||||||
stat := syscall.Statfs_t{}
|
stat := syscall.Statfs_t{
|
||||||
|
Blocks: 0,
|
||||||
|
Bsize: 0,
|
||||||
|
Bfree: 0,
|
||||||
|
}
|
||||||
err := syscall.Statfs(path, &stat)
|
err := syscall.Statfs(path, &stat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
continue
|
||||||
return
|
}
|
||||||
|
if stat.Blocks == 0 || stat.Bsize == 0 {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
tags := map[string]string{"type": "node", "device": linefields[0]}
|
tags := map[string]string{"type": "node", "device": linefields[0]}
|
||||||
total := (stat.Blocks * uint64(stat.Bsize)) / uint64(1000000000)
|
total := (stat.Blocks * uint64(stat.Bsize)) / uint64(1000000000)
|
||||||
y, err := lp.New("disk_total", tags, m.meta, map[string]interface{}{"value": total}, time.Now())
|
y, err := lp.NewMessage("disk_total", tags, m.meta, map[string]interface{}{"value": total}, time.Now())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
y.AddMeta("unit", "GBytes")
|
y.AddMeta("unit", "GBytes")
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
free := (stat.Bfree * uint64(stat.Bsize)) / uint64(1000000000)
|
free := (stat.Bfree * uint64(stat.Bsize)) / uint64(1000000000)
|
||||||
y, err = lp.New("disk_free", tags, m.meta, map[string]interface{}{"value": free}, time.Now())
|
y, err = lp.NewMessage("disk_free", tags, m.meta, map[string]interface{}{"value": free}, time.Now())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
y.AddMeta("unit", "GBytes")
|
y.AddMeta("unit", "GBytes")
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
if total > 0 {
|
||||||
perc := (100 * (total - free)) / total
|
perc := (100 * (total - free)) / total
|
||||||
if perc > part_max_used {
|
if perc > part_max_used {
|
||||||
part_max_used = perc
|
part_max_used = perc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
y, err := lp.New("part_max_used", map[string]string{"type": "node"}, m.meta, map[string]interface{}{"value": int(part_max_used)}, time.Now())
|
}
|
||||||
|
y, err := lp.NewMessage("part_max_used", map[string]string{"type": "node"}, m.meta, map[string]interface{}{"value": int(part_max_used)}, time.Now())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
y.AddMeta("unit", "percent")
|
y.AddMeta("unit", "percent")
|
||||||
output <- y
|
output <- y
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
@@ -13,18 +13,29 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const DEFAULT_GPFS_CMD = "mmpmon"
|
||||||
|
|
||||||
|
type GpfsCollectorLastState struct {
|
||||||
|
bytesRead int64
|
||||||
|
bytesWritten int64
|
||||||
|
}
|
||||||
|
|
||||||
type GpfsCollector struct {
|
type GpfsCollector struct {
|
||||||
metricCollector
|
metricCollector
|
||||||
tags map[string]string
|
tags map[string]string
|
||||||
config struct {
|
config struct {
|
||||||
Mmpmon string `json:"mmpmon_path,omitempty"`
|
Mmpmon string `json:"mmpmon_path,omitempty"`
|
||||||
ExcludeFilesystem []string `json:"exclude_filesystem,omitempty"`
|
ExcludeFilesystem []string `json:"exclude_filesystem,omitempty"`
|
||||||
|
SendBandwidths bool `json:"send_bandwidths"`
|
||||||
|
SendTotalValues bool `json:"send_total_values"`
|
||||||
}
|
}
|
||||||
skipFS map[string]struct{}
|
skipFS map[string]struct{}
|
||||||
|
lastTimestamp time.Time // Store time stamp of last tick to derive bandwidths
|
||||||
|
lastState map[string]GpfsCollectorLastState
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *GpfsCollector) Init(config json.RawMessage) error {
|
func (m *GpfsCollector) Init(config json.RawMessage) error {
|
||||||
@@ -36,9 +47,10 @@ func (m *GpfsCollector) Init(config json.RawMessage) error {
|
|||||||
var err error
|
var err error
|
||||||
m.name = "GpfsCollector"
|
m.name = "GpfsCollector"
|
||||||
m.setup()
|
m.setup()
|
||||||
|
m.parallel = true
|
||||||
|
|
||||||
// Set default mmpmon binary
|
// Set default mmpmon binary
|
||||||
m.config.Mmpmon = "/usr/lpp/mmfs/bin/mmpmon"
|
m.config.Mmpmon = DEFAULT_GPFS_CMD
|
||||||
|
|
||||||
// Read JSON configuration
|
// Read JSON configuration
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
@@ -60,32 +72,41 @@ func (m *GpfsCollector) Init(config json.RawMessage) error {
|
|||||||
for _, fs := range m.config.ExcludeFilesystem {
|
for _, fs := range m.config.ExcludeFilesystem {
|
||||||
m.skipFS[fs] = struct{}{}
|
m.skipFS[fs] = struct{}{}
|
||||||
}
|
}
|
||||||
|
m.lastState = make(map[string]GpfsCollectorLastState)
|
||||||
|
|
||||||
// GPFS / IBM Spectrum Scale file system statistics can only be queried by user root
|
// GPFS / IBM Spectrum Scale file system statistics can only be queried by user root
|
||||||
user, err := user.Current()
|
user, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to get current user: %v", err)
|
return fmt.Errorf("failed to get current user: %v", err)
|
||||||
}
|
}
|
||||||
if user.Uid != "0" {
|
if user.Uid != "0" {
|
||||||
return fmt.Errorf("GPFS file system statistics can only be queried by user root")
|
return fmt.Errorf("GPFS file system statistics can only be queried by user root")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if mmpmon is in executable search path
|
// Check if mmpmon is in executable search path
|
||||||
_, err = exec.LookPath(m.config.Mmpmon)
|
p, err := exec.LookPath(m.config.Mmpmon)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to find mmpmon binary '%s': %v", m.config.Mmpmon, err)
|
return fmt.Errorf("failed to find mmpmon binary '%s': %v", m.config.Mmpmon, err)
|
||||||
}
|
}
|
||||||
|
m.config.Mmpmon = p
|
||||||
|
|
||||||
m.init = true
|
m.init = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
// Check if already initialized
|
// Check if already initialized
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Current time stamp
|
||||||
|
now := time.Now()
|
||||||
|
// time difference to last time stamp
|
||||||
|
timeDiff := now.Sub(m.lastTimestamp).Seconds()
|
||||||
|
// Save current timestamp
|
||||||
|
m.lastTimestamp = now
|
||||||
|
|
||||||
// mmpmon:
|
// mmpmon:
|
||||||
// -p: generate output that can be parsed
|
// -p: generate output that can be parsed
|
||||||
// -s: suppress the prompt on input
|
// -s: suppress the prompt on input
|
||||||
@@ -98,8 +119,8 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
cmd.Stderr = cmdStderr
|
cmd.Stderr = cmdStderr
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dataStdErr, _ := ioutil.ReadAll(cmdStderr)
|
dataStdErr, _ := io.ReadAll(cmdStderr)
|
||||||
dataStdOut, _ := ioutil.ReadAll(cmdStdout)
|
dataStdOut, _ := io.ReadAll(cmdStdout)
|
||||||
cclog.ComponentError(
|
cclog.ComponentError(
|
||||||
m.name,
|
m.name,
|
||||||
fmt.Sprintf("Read(): Failed to execute command \"%s\": %v\n", cmd.String(), err),
|
fmt.Sprintf("Read(): Failed to execute command \"%s\": %v\n", cmd.String(), err),
|
||||||
@@ -144,8 +165,19 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add filesystem tag
|
||||||
m.tags["filesystem"] = filesystem
|
m.tags["filesystem"] = filesystem
|
||||||
|
|
||||||
|
// Create initial last state
|
||||||
|
if m.config.SendBandwidths {
|
||||||
|
if _, ok := m.lastState[filesystem]; !ok {
|
||||||
|
m.lastState[filesystem] = GpfsCollectorLastState{
|
||||||
|
bytesRead: -1,
|
||||||
|
bytesWritten: -1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// return code
|
// return code
|
||||||
rc, err := strconv.Atoi(key_value["_rc_"])
|
rc, err := strconv.Atoi(key_value["_rc_"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -185,9 +217,37 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
fmt.Sprintf("Read(): Failed to convert bytes read '%s' to int64: %v", key_value["_br_"], err))
|
fmt.Sprintf("Read(): Failed to convert bytes read '%s' to int64: %v", key_value["_br_"], err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if y, err := lp.New("gpfs_bytes_read", m.tags, m.meta, map[string]interface{}{"value": bytesRead}, timestamp); err == nil {
|
if y, err :=
|
||||||
|
lp.NewMessage(
|
||||||
|
"gpfs_bytes_read",
|
||||||
|
m.tags,
|
||||||
|
m.meta,
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": bytesRead,
|
||||||
|
},
|
||||||
|
timestamp,
|
||||||
|
); err == nil {
|
||||||
|
y.AddMeta("unit", "bytes")
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
if m.config.SendBandwidths {
|
||||||
|
if lastBytesRead := m.lastState[filesystem].bytesRead; lastBytesRead >= 0 {
|
||||||
|
bwRead := float64(bytesRead-lastBytesRead) / timeDiff
|
||||||
|
if y, err :=
|
||||||
|
lp.NewMessage(
|
||||||
|
"gpfs_bw_read",
|
||||||
|
m.tags,
|
||||||
|
m.meta,
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": bwRead,
|
||||||
|
},
|
||||||
|
timestamp,
|
||||||
|
); err == nil {
|
||||||
|
y.AddMeta("unit", "bytes/sec")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// bytes written
|
// bytes written
|
||||||
bytesWritten, err := strconv.ParseInt(key_value["_bw_"], 10, 64)
|
bytesWritten, err := strconv.ParseInt(key_value["_bw_"], 10, 64)
|
||||||
@@ -197,9 +257,44 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
fmt.Sprintf("Read(): Failed to convert bytes written '%s' to int64: %v", key_value["_bw_"], err))
|
fmt.Sprintf("Read(): Failed to convert bytes written '%s' to int64: %v", key_value["_bw_"], err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if y, err := lp.New("gpfs_bytes_written", m.tags, m.meta, map[string]interface{}{"value": bytesWritten}, timestamp); err == nil {
|
if y, err :=
|
||||||
|
lp.NewMessage(
|
||||||
|
"gpfs_bytes_written",
|
||||||
|
m.tags,
|
||||||
|
m.meta,
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": bytesWritten,
|
||||||
|
},
|
||||||
|
timestamp,
|
||||||
|
); err == nil {
|
||||||
|
y.AddMeta("unit", "bytes")
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
if m.config.SendBandwidths {
|
||||||
|
if lastBytesWritten := m.lastState[filesystem].bytesRead; lastBytesWritten >= 0 {
|
||||||
|
bwWrite := float64(bytesWritten-lastBytesWritten) / timeDiff
|
||||||
|
if y, err :=
|
||||||
|
lp.NewMessage(
|
||||||
|
"gpfs_bw_write",
|
||||||
|
m.tags,
|
||||||
|
m.meta,
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": bwWrite,
|
||||||
|
},
|
||||||
|
timestamp,
|
||||||
|
); err == nil {
|
||||||
|
y.AddMeta("unit", "bytes/sec")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.config.SendBandwidths {
|
||||||
|
m.lastState[filesystem] = GpfsCollectorLastState{
|
||||||
|
bytesRead: bytesRead,
|
||||||
|
bytesWritten: bytesWritten,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// number of opens
|
// number of opens
|
||||||
numOpens, err := strconv.ParseInt(key_value["_oc_"], 10, 64)
|
numOpens, err := strconv.ParseInt(key_value["_oc_"], 10, 64)
|
||||||
@@ -209,7 +304,7 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
fmt.Sprintf("Read(): Failed to convert number of opens '%s' to int64: %v", key_value["_oc_"], err))
|
fmt.Sprintf("Read(): Failed to convert number of opens '%s' to int64: %v", key_value["_oc_"], err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if y, err := lp.New("gpfs_num_opens", m.tags, m.meta, map[string]interface{}{"value": numOpens}, timestamp); err == nil {
|
if y, err := lp.NewMessage("gpfs_num_opens", m.tags, m.meta, map[string]interface{}{"value": numOpens}, timestamp); err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +316,7 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
fmt.Sprintf("Read(): Failed to convert number of closes: '%s' to int64: %v", key_value["_cc_"], err))
|
fmt.Sprintf("Read(): Failed to convert number of closes: '%s' to int64: %v", key_value["_cc_"], err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if y, err := lp.New("gpfs_num_closes", m.tags, m.meta, map[string]interface{}{"value": numCloses}, timestamp); err == nil {
|
if y, err := lp.NewMessage("gpfs_num_closes", m.tags, m.meta, map[string]interface{}{"value": numCloses}, timestamp); err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +328,7 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
fmt.Sprintf("Read(): Failed to convert number of reads: '%s' to int64: %v", key_value["_rdc_"], err))
|
fmt.Sprintf("Read(): Failed to convert number of reads: '%s' to int64: %v", key_value["_rdc_"], err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if y, err := lp.New("gpfs_num_reads", m.tags, m.meta, map[string]interface{}{"value": numReads}, timestamp); err == nil {
|
if y, err := lp.NewMessage("gpfs_num_reads", m.tags, m.meta, map[string]interface{}{"value": numReads}, timestamp); err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +340,7 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
fmt.Sprintf("Read(): Failed to convert number of writes: '%s' to int64: %v", key_value["_wc_"], err))
|
fmt.Sprintf("Read(): Failed to convert number of writes: '%s' to int64: %v", key_value["_wc_"], err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if y, err := lp.New("gpfs_num_writes", m.tags, m.meta, map[string]interface{}{"value": numWrites}, timestamp); err == nil {
|
if y, err := lp.NewMessage("gpfs_num_writes", m.tags, m.meta, map[string]interface{}{"value": numWrites}, timestamp); err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +352,7 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
fmt.Sprintf("Read(): Failed to convert number of read directories: '%s' to int64: %v", key_value["_dir_"], err))
|
fmt.Sprintf("Read(): Failed to convert number of read directories: '%s' to int64: %v", key_value["_dir_"], err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if y, err := lp.New("gpfs_num_readdirs", m.tags, m.meta, map[string]interface{}{"value": numReaddirs}, timestamp); err == nil {
|
if y, err := lp.NewMessage("gpfs_num_readdirs", m.tags, m.meta, map[string]interface{}{"value": numReaddirs}, timestamp); err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,9 +364,50 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
fmt.Sprintf("Read(): Failed to convert number of inode updates: '%s' to int: %v", key_value["_iu_"], err))
|
fmt.Sprintf("Read(): Failed to convert number of inode updates: '%s' to int: %v", key_value["_iu_"], err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if y, err := lp.New("gpfs_num_inode_updates", m.tags, m.meta, map[string]interface{}{"value": numInodeUpdates}, timestamp); err == nil {
|
if y, err := lp.NewMessage("gpfs_num_inode_updates", m.tags, m.meta, map[string]interface{}{"value": numInodeUpdates}, timestamp); err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Total values
|
||||||
|
if m.config.SendTotalValues {
|
||||||
|
bytesTotal := bytesRead + bytesWritten
|
||||||
|
if y, err :=
|
||||||
|
lp.NewMessage("gpfs_bytes_total",
|
||||||
|
m.tags,
|
||||||
|
m.meta,
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": bytesTotal,
|
||||||
|
},
|
||||||
|
timestamp,
|
||||||
|
); err == nil {
|
||||||
|
y.AddMeta("unit", "bytes")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
iops := numReads + numWrites
|
||||||
|
if y, err :=
|
||||||
|
lp.NewMessage("gpfs_iops",
|
||||||
|
m.tags,
|
||||||
|
m.meta,
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": iops,
|
||||||
|
},
|
||||||
|
timestamp,
|
||||||
|
); err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
metaops := numInodeUpdates + numCloses + numOpens + numReaddirs
|
||||||
|
if y, err :=
|
||||||
|
lp.NewMessage("gpfs_metaops",
|
||||||
|
m.tags,
|
||||||
|
m.meta,
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": metaops,
|
||||||
|
},
|
||||||
|
timestamp,
|
||||||
|
); err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,9 @@
|
|||||||
"mmpmon_path": "/path/to/mmpmon",
|
"mmpmon_path": "/path/to/mmpmon",
|
||||||
"exclude_filesystem": [
|
"exclude_filesystem": [
|
||||||
"fs1"
|
"fs1"
|
||||||
]
|
],
|
||||||
|
"send_bandwidths": true,
|
||||||
|
"send_total_values": true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -16,15 +18,22 @@ The reported filesystems can be filtered with the `exclude_filesystem` option
|
|||||||
in the configuration.
|
in the configuration.
|
||||||
|
|
||||||
The path to the `mmpmon` command can be configured with the `mmpmon_path` option
|
The path to the `mmpmon` command can be configured with the `mmpmon_path` option
|
||||||
in the configuration.
|
in the configuration. If nothing is set, the collector searches in `$PATH` for `mmpmon`.
|
||||||
|
|
||||||
|
|
||||||
Metrics:
|
Metrics:
|
||||||
* `bytes_read`
|
* `gpfs_bytes_read`
|
||||||
* `gpfs_bytes_written`
|
* `gpfs_bytes_written`
|
||||||
* `gpfs_num_opens`
|
* `gpfs_num_opens`
|
||||||
* `gpfs_num_closes`
|
* `gpfs_num_closes`
|
||||||
* `gpfs_num_reads`
|
* `gpfs_num_reads`
|
||||||
|
* `gpfs_num_writes`
|
||||||
* `gpfs_num_readdirs`
|
* `gpfs_num_readdirs`
|
||||||
* `gpfs_num_inode_updates`
|
* `gpfs_num_inode_updates`
|
||||||
|
* `gpfs_bytes_total = gpfs_bytes_read + gpfs_bytes_written` (if `send_total_values == true`)
|
||||||
|
* `gpfs_iops = gpfs_num_reads + gpfs_num_writes` (if `send_total_values == true`)
|
||||||
|
* `gpfs_metaops = gpfs_num_inode_updates + gpfs_num_closes + gpfs_num_opens + gpfs_num_readdirs` (if `send_total_values == true`)
|
||||||
|
* `gpfs_bw_read` (if `send_bandwidths == true`)
|
||||||
|
* `gpfs_bw_write` (if `send_bandwidths == true`)
|
||||||
|
|
||||||
The collector adds a `filesystem` tag to all metrics
|
The collector adds a `filesystem` tag to all metrics
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ package collectors
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -16,13 +15,24 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const IB_BASEPATH = `/sys/class/infiniband/`
|
const IB_BASEPATH = "/sys/class/infiniband/"
|
||||||
|
|
||||||
|
type InfinibandCollectorMetric struct {
|
||||||
|
name string
|
||||||
|
path string
|
||||||
|
unit string
|
||||||
|
scale int64
|
||||||
|
addToIBTotal bool
|
||||||
|
addToIBTotalPkgs bool
|
||||||
|
currentState int64
|
||||||
|
lastState int64
|
||||||
|
}
|
||||||
|
|
||||||
type InfinibandCollectorInfo struct {
|
type InfinibandCollectorInfo struct {
|
||||||
LID string // IB local Identifier (LID)
|
LID string // IB local Identifier (LID)
|
||||||
device string // IB device
|
device string // IB device
|
||||||
port string // IB device port
|
port string // IB device port
|
||||||
portCounterFiles map[string]string // mapping counter name -> sysfs file
|
portCounterFiles []InfinibandCollectorMetric // mapping counter name -> InfinibandCollectorMetric
|
||||||
tagSet map[string]string // corresponding tag list
|
tagSet map[string]string // corresponding tag list
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,8 +40,12 @@ type InfinibandCollector struct {
|
|||||||
metricCollector
|
metricCollector
|
||||||
config struct {
|
config struct {
|
||||||
ExcludeDevices []string `json:"exclude_devices,omitempty"` // IB device to exclude e.g. mlx5_0
|
ExcludeDevices []string `json:"exclude_devices,omitempty"` // IB device to exclude e.g. mlx5_0
|
||||||
|
SendAbsoluteValues bool `json:"send_abs_values"` // Send absolut values as read from sys filesystem
|
||||||
|
SendTotalValues bool `json:"send_total_values"` // Send computed total values
|
||||||
|
SendDerivedValues bool `json:"send_derived_values"` // Send derived values e.g. rates
|
||||||
}
|
}
|
||||||
info []*InfinibandCollectorInfo
|
info []InfinibandCollectorInfo
|
||||||
|
lastTimestamp time.Time // Store time stamp of last tick to derive bandwidths
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init initializes the Infiniband collector by walking through files below IB_BASEPATH
|
// Init initializes the Infiniband collector by walking through files below IB_BASEPATH
|
||||||
@@ -45,10 +59,16 @@ func (m *InfinibandCollector) Init(config json.RawMessage) error {
|
|||||||
var err error
|
var err error
|
||||||
m.name = "InfinibandCollector"
|
m.name = "InfinibandCollector"
|
||||||
m.setup()
|
m.setup()
|
||||||
|
m.parallel = true
|
||||||
m.meta = map[string]string{
|
m.meta = map[string]string{
|
||||||
"source": m.name,
|
"source": m.name,
|
||||||
"group": "Network",
|
"group": "Network",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set default configuration,
|
||||||
|
m.config.SendAbsoluteValues = true
|
||||||
|
m.config.SendDerivedValues = false
|
||||||
|
// Read configuration file, allow overwriting default config
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err = json.Unmarshal(config, &m.config)
|
err = json.Unmarshal(config, &m.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -60,16 +80,16 @@ func (m *InfinibandCollector) Init(config json.RawMessage) error {
|
|||||||
globPattern := filepath.Join(IB_BASEPATH, "*", "ports", "*")
|
globPattern := filepath.Join(IB_BASEPATH, "*", "ports", "*")
|
||||||
ibDirs, err := filepath.Glob(globPattern)
|
ibDirs, err := filepath.Glob(globPattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to glob files with pattern %s: %v", globPattern, err)
|
return fmt.Errorf("unable to glob files with pattern %s: %v", globPattern, err)
|
||||||
}
|
}
|
||||||
if ibDirs == nil {
|
if ibDirs == nil {
|
||||||
return fmt.Errorf("Unable to find any directories with pattern %s", globPattern)
|
return fmt.Errorf("unable to find any directories with pattern %s", globPattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, path := range ibDirs {
|
for _, path := range ibDirs {
|
||||||
|
|
||||||
// Skip, when no LID is assigned
|
// Skip, when no LID is assigned
|
||||||
line, err := ioutil.ReadFile(filepath.Join(path, "lid"))
|
line, err := os.ReadFile(filepath.Join(path, "lid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -97,21 +117,49 @@ func (m *InfinibandCollector) Init(config json.RawMessage) error {
|
|||||||
|
|
||||||
// Check access to counter files
|
// Check access to counter files
|
||||||
countersDir := filepath.Join(path, "counters")
|
countersDir := filepath.Join(path, "counters")
|
||||||
portCounterFiles := map[string]string{
|
portCounterFiles := []InfinibandCollectorMetric{
|
||||||
"ib_recv": filepath.Join(countersDir, "port_rcv_data"),
|
{
|
||||||
"ib_xmit": filepath.Join(countersDir, "port_xmit_data"),
|
name: "ib_recv",
|
||||||
"ib_recv_pkts": filepath.Join(countersDir, "port_rcv_packets"),
|
path: filepath.Join(countersDir, "port_rcv_data"),
|
||||||
"ib_xmit_pkts": filepath.Join(countersDir, "port_xmit_packets"),
|
unit: "bytes",
|
||||||
|
scale: 4,
|
||||||
|
addToIBTotal: true,
|
||||||
|
lastState: -1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ib_xmit",
|
||||||
|
path: filepath.Join(countersDir, "port_xmit_data"),
|
||||||
|
unit: "bytes",
|
||||||
|
scale: 4,
|
||||||
|
addToIBTotal: true,
|
||||||
|
lastState: -1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ib_recv_pkts",
|
||||||
|
path: filepath.Join(countersDir, "port_rcv_packets"),
|
||||||
|
unit: "packets",
|
||||||
|
scale: 1,
|
||||||
|
addToIBTotalPkgs: true,
|
||||||
|
lastState: -1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ib_xmit_pkts",
|
||||||
|
path: filepath.Join(countersDir, "port_xmit_packets"),
|
||||||
|
unit: "packets",
|
||||||
|
scale: 1,
|
||||||
|
addToIBTotalPkgs: true,
|
||||||
|
lastState: -1,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, counterFile := range portCounterFiles {
|
for _, counter := range portCounterFiles {
|
||||||
err := unix.Access(counterFile, unix.R_OK)
|
err := unix.Access(counter.path, unix.R_OK)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to access %s: %v", counterFile, err)
|
return fmt.Errorf("unable to access %s: %v", counter.path, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m.info = append(m.info,
|
m.info = append(m.info,
|
||||||
&InfinibandCollectorInfo{
|
InfinibandCollectorInfo{
|
||||||
LID: LID,
|
LID: LID,
|
||||||
device: device,
|
device: device,
|
||||||
port: port,
|
port: port,
|
||||||
@@ -126,7 +174,7 @@ func (m *InfinibandCollector) Init(config json.RawMessage) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(m.info) == 0 {
|
if len(m.info) == 0 {
|
||||||
return fmt.Errorf("Found no IB devices")
|
return fmt.Errorf("found no IB devices")
|
||||||
}
|
}
|
||||||
|
|
||||||
m.init = true
|
m.init = true
|
||||||
@@ -134,36 +182,127 @@ func (m *InfinibandCollector) Init(config json.RawMessage) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read reads Infiniband counter files below IB_BASEPATH
|
// Read reads Infiniband counter files below IB_BASEPATH
|
||||||
func (m *InfinibandCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *InfinibandCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
|
|
||||||
// Check if already initialized
|
// Check if already initialized
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Current time stamp
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
for _, info := range m.info {
|
// time difference to last time stamp
|
||||||
for counterName, counterFile := range info.portCounterFiles {
|
timeDiff := now.Sub(m.lastTimestamp).Seconds()
|
||||||
line, err := ioutil.ReadFile(counterFile)
|
// Save current timestamp
|
||||||
|
m.lastTimestamp = now
|
||||||
|
|
||||||
|
for i := range m.info {
|
||||||
|
info := &m.info[i]
|
||||||
|
|
||||||
|
var ib_total, ib_total_pkts int64
|
||||||
|
for i := range info.portCounterFiles {
|
||||||
|
counterDef := &info.portCounterFiles[i]
|
||||||
|
|
||||||
|
// Read counter file
|
||||||
|
line, err := os.ReadFile(counterDef.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.ComponentError(
|
cclog.ComponentError(
|
||||||
m.name,
|
m.name,
|
||||||
fmt.Sprintf("Read(): Failed to read from file '%s': %v", counterFile, err))
|
fmt.Sprintf("Read(): Failed to read from file '%s': %v", counterDef.path, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
data := strings.TrimSpace(string(line))
|
data := strings.TrimSpace(string(line))
|
||||||
|
|
||||||
|
// convert counter to int64
|
||||||
v, err := strconv.ParseInt(data, 10, 64)
|
v, err := strconv.ParseInt(data, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.ComponentError(
|
cclog.ComponentError(
|
||||||
m.name,
|
m.name,
|
||||||
fmt.Sprintf("Read(): Failed to convert Infininiband metrice %s='%s' to int64: %v", counterName, data, err))
|
fmt.Sprintf("Read(): Failed to convert Infininiband metrice %s='%s' to int64: %v", counterDef.name, data, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if y, err := lp.New(counterName, info.tagSet, m.meta, map[string]interface{}{"value": v}, now); err == nil {
|
// Scale raw value
|
||||||
|
v *= counterDef.scale
|
||||||
|
|
||||||
|
// Save current state
|
||||||
|
counterDef.currentState = v
|
||||||
|
|
||||||
|
// Send absolut values
|
||||||
|
if m.config.SendAbsoluteValues {
|
||||||
|
if y, err :=
|
||||||
|
lp.NewMessage(
|
||||||
|
counterDef.name,
|
||||||
|
info.tagSet,
|
||||||
|
m.meta,
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": counterDef.currentState,
|
||||||
|
},
|
||||||
|
now); err == nil {
|
||||||
|
y.AddMeta("unit", counterDef.unit)
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send derived values
|
||||||
|
if m.config.SendDerivedValues {
|
||||||
|
if counterDef.lastState >= 0 {
|
||||||
|
rate := float64((counterDef.currentState - counterDef.lastState)) / timeDiff
|
||||||
|
if y, err :=
|
||||||
|
lp.NewMessage(
|
||||||
|
counterDef.name+"_bw",
|
||||||
|
info.tagSet,
|
||||||
|
m.meta,
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": rate,
|
||||||
|
},
|
||||||
|
now); err == nil {
|
||||||
|
y.AddMeta("unit", counterDef.unit+"/sec")
|
||||||
|
output <- y
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
counterDef.lastState = counterDef.currentState
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sum up total values
|
||||||
|
if m.config.SendTotalValues {
|
||||||
|
switch {
|
||||||
|
case counterDef.addToIBTotal:
|
||||||
|
ib_total += counterDef.currentState
|
||||||
|
case counterDef.addToIBTotalPkgs:
|
||||||
|
ib_total_pkts += counterDef.currentState
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send total values
|
||||||
|
if m.config.SendTotalValues {
|
||||||
|
if y, err :=
|
||||||
|
lp.NewMessage(
|
||||||
|
"ib_total",
|
||||||
|
info.tagSet,
|
||||||
|
m.meta,
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": ib_total,
|
||||||
|
},
|
||||||
|
now); err == nil {
|
||||||
|
y.AddMeta("unit", "bytes")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
|
||||||
|
if y, err :=
|
||||||
|
lp.NewMessage(
|
||||||
|
"ib_total_pkts",
|
||||||
|
info.tagSet,
|
||||||
|
m.meta,
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": ib_total_pkts,
|
||||||
|
},
|
||||||
|
now); err == nil {
|
||||||
|
y.AddMeta("unit", "packets")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,9 @@
|
|||||||
"ibstat": {
|
"ibstat": {
|
||||||
"exclude_devices": [
|
"exclude_devices": [
|
||||||
"mlx4"
|
"mlx4"
|
||||||
]
|
],
|
||||||
|
"send_abs_values": true,
|
||||||
|
"send_derived_values": true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -15,12 +17,19 @@ LID file (`/sys/class/infiniband/<dev>/ports/<port>/lid`)
|
|||||||
|
|
||||||
The devices can be filtered with the `exclude_devices` option in the configuration.
|
The devices can be filtered with the `exclude_devices` option in the configuration.
|
||||||
|
|
||||||
For each found LID the collector reads data through the sysfs files below `/sys/class/infiniband/<device>`.
|
For each found LID the collector reads data through the sysfs files below `/sys/class/infiniband/<device>`. (See: <https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-infiniband>)
|
||||||
|
|
||||||
Metrics:
|
Metrics:
|
||||||
|
|
||||||
* `ib_recv`
|
* `ib_recv`
|
||||||
* `ib_xmit`
|
* `ib_xmit`
|
||||||
* `ib_recv_pkts`
|
* `ib_recv_pkts`
|
||||||
* `ib_xmit_pkts`
|
* `ib_xmit_pkts`
|
||||||
|
* `ib_total = ib_recv + ib_xmit` (if `send_total_values == true`)
|
||||||
|
* `ib_total_pkts = ib_recv_pkts + ib_xmit_pkts` (if `send_total_values == true`)
|
||||||
|
* `ib_recv_bw` (if `send_derived_values == true`)
|
||||||
|
* `ib_xmit_bw` (if `send_derived_values == true`)
|
||||||
|
* `ib_recv_pkts_bw` (if `send_derived_values == true`)
|
||||||
|
* `ib_xmit_pkts_bw` (if `send_derived_values == true`)
|
||||||
|
|
||||||
The collector adds a `device` tag to all metrics
|
The collector adds a `device` tag to all metrics
|
||||||
|
|||||||
@@ -1,232 +0,0 @@
|
|||||||
package collectors
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os/exec"
|
|
||||||
|
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
|
||||||
|
|
||||||
// "os"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const PERFQUERY = `/usr/sbin/perfquery`
|
|
||||||
|
|
||||||
type InfinibandPerfQueryCollector struct {
|
|
||||||
metricCollector
|
|
||||||
tags map[string]string
|
|
||||||
lids map[string]map[string]string
|
|
||||||
config struct {
|
|
||||||
ExcludeDevices []string `json:"exclude_devices,omitempty"`
|
|
||||||
PerfQueryPath string `json:"perfquery_path"`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *InfinibandPerfQueryCollector) Init(config json.RawMessage) error {
|
|
||||||
var err error
|
|
||||||
m.name = "InfinibandCollectorPerfQuery"
|
|
||||||
m.setup()
|
|
||||||
m.meta = map[string]string{"source": m.name, "group": "Network"}
|
|
||||||
m.tags = map[string]string{"type": "node"}
|
|
||||||
if len(config) > 0 {
|
|
||||||
err = json.Unmarshal(config, &m.config)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(m.config.PerfQueryPath) == 0 {
|
|
||||||
path, err := exec.LookPath("perfquery")
|
|
||||||
if err == nil {
|
|
||||||
m.config.PerfQueryPath = path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m.lids = make(map[string]map[string]string)
|
|
||||||
p := fmt.Sprintf("%s/*/ports/*/lid", string(IB_BASEPATH))
|
|
||||||
files, err := filepath.Glob(p)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, f := range files {
|
|
||||||
lid, err := ioutil.ReadFile(f)
|
|
||||||
if err == nil {
|
|
||||||
plist := strings.Split(strings.Replace(f, string(IB_BASEPATH), "", -1), "/")
|
|
||||||
skip := false
|
|
||||||
for _, d := range m.config.ExcludeDevices {
|
|
||||||
if d == plist[0] {
|
|
||||||
skip = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !skip {
|
|
||||||
m.lids[plist[0]] = make(map[string]string)
|
|
||||||
m.lids[plist[0]][plist[2]] = string(lid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, ports := range m.lids {
|
|
||||||
for port, lid := range ports {
|
|
||||||
args := fmt.Sprintf("-r %s %s 0xf000", lid, port)
|
|
||||||
command := exec.Command(m.config.PerfQueryPath, args)
|
|
||||||
command.Wait()
|
|
||||||
_, err := command.Output()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Failed to execute %s: %v", m.config.PerfQueryPath, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(m.lids) == 0 {
|
|
||||||
return errors.New("No usable IB devices")
|
|
||||||
}
|
|
||||||
|
|
||||||
m.init = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *InfinibandPerfQueryCollector) doPerfQuery(cmd string, dev string, lid string, port string, tags map[string]string, output chan lp.CCMetric) error {
|
|
||||||
|
|
||||||
args := fmt.Sprintf("-r %s %s 0xf000", lid, port)
|
|
||||||
command := exec.Command(cmd, args)
|
|
||||||
command.Wait()
|
|
||||||
stdout, err := command.Output()
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
ll := strings.Split(string(stdout), "\n")
|
|
||||||
|
|
||||||
for _, line := range ll {
|
|
||||||
if strings.HasPrefix(line, "PortRcvData") || strings.HasPrefix(line, "RcvData") {
|
|
||||||
lv := strings.Fields(line)
|
|
||||||
v, err := strconv.ParseFloat(lv[1], 64)
|
|
||||||
if err == nil {
|
|
||||||
y, err := lp.New("ib_recv", tags, m.meta, map[string]interface{}{"value": float64(v)}, time.Now())
|
|
||||||
if err == nil {
|
|
||||||
output <- y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(line, "PortXmitData") || strings.HasPrefix(line, "XmtData") {
|
|
||||||
lv := strings.Fields(line)
|
|
||||||
v, err := strconv.ParseFloat(lv[1], 64)
|
|
||||||
if err == nil {
|
|
||||||
y, err := lp.New("ib_xmit", tags, m.meta, map[string]interface{}{"value": float64(v)}, time.Now())
|
|
||||||
if err == nil {
|
|
||||||
output <- y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(line, "PortRcvPkts") || strings.HasPrefix(line, "RcvPkts") {
|
|
||||||
lv := strings.Fields(line)
|
|
||||||
v, err := strconv.ParseFloat(lv[1], 64)
|
|
||||||
if err == nil {
|
|
||||||
y, err := lp.New("ib_recv_pkts", tags, m.meta, map[string]interface{}{"value": float64(v)}, time.Now())
|
|
||||||
if err == nil {
|
|
||||||
output <- y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(line, "PortXmitPkts") || strings.HasPrefix(line, "XmtPkts") {
|
|
||||||
lv := strings.Fields(line)
|
|
||||||
v, err := strconv.ParseFloat(lv[1], 64)
|
|
||||||
if err == nil {
|
|
||||||
y, err := lp.New("ib_xmit_pkts", tags, m.meta, map[string]interface{}{"value": float64(v)}, time.Now())
|
|
||||||
if err == nil {
|
|
||||||
output <- y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(line, "PortRcvPkts") || strings.HasPrefix(line, "RcvPkts") {
|
|
||||||
lv := strings.Fields(line)
|
|
||||||
v, err := strconv.ParseFloat(lv[1], 64)
|
|
||||||
if err == nil {
|
|
||||||
y, err := lp.New("ib_recv_pkts", tags, m.meta, map[string]interface{}{"value": float64(v)}, time.Now())
|
|
||||||
if err == nil {
|
|
||||||
output <- y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(line, "PortXmitPkts") || strings.HasPrefix(line, "XmtPkts") {
|
|
||||||
lv := strings.Fields(line)
|
|
||||||
v, err := strconv.ParseFloat(lv[1], 64)
|
|
||||||
if err == nil {
|
|
||||||
y, err := lp.New("ib_xmit_pkts", tags, m.meta, map[string]interface{}{"value": float64(v)}, time.Now())
|
|
||||||
if err == nil {
|
|
||||||
output <- y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *InfinibandPerfQueryCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|
||||||
|
|
||||||
if m.init {
|
|
||||||
for dev, ports := range m.lids {
|
|
||||||
for port, lid := range ports {
|
|
||||||
tags := map[string]string{
|
|
||||||
"type": "node",
|
|
||||||
"device": dev,
|
|
||||||
"port": port,
|
|
||||||
"lid": lid}
|
|
||||||
path := fmt.Sprintf("%s/%s/ports/%s/counters/", string(IB_BASEPATH), dev, port)
|
|
||||||
buffer, err := ioutil.ReadFile(fmt.Sprintf("%s/port_rcv_data", path))
|
|
||||||
if err == nil {
|
|
||||||
data := strings.Replace(string(buffer), "\n", "", -1)
|
|
||||||
v, err := strconv.ParseFloat(data, 64)
|
|
||||||
if err == nil {
|
|
||||||
y, err := lp.New("ib_recv", tags, m.meta, map[string]interface{}{"value": float64(v)}, time.Now())
|
|
||||||
if err == nil {
|
|
||||||
output <- y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buffer, err = ioutil.ReadFile(fmt.Sprintf("%s/port_xmit_data", path))
|
|
||||||
if err == nil {
|
|
||||||
data := strings.Replace(string(buffer), "\n", "", -1)
|
|
||||||
v, err := strconv.ParseFloat(data, 64)
|
|
||||||
if err == nil {
|
|
||||||
y, err := lp.New("ib_xmit", tags, m.meta, map[string]interface{}{"value": float64(v)}, time.Now())
|
|
||||||
if err == nil {
|
|
||||||
output <- y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buffer, err = ioutil.ReadFile(fmt.Sprintf("%s/port_rcv_packets", path))
|
|
||||||
if err == nil {
|
|
||||||
data := strings.Replace(string(buffer), "\n", "", -1)
|
|
||||||
v, err := strconv.ParseFloat(data, 64)
|
|
||||||
if err == nil {
|
|
||||||
y, err := lp.New("ib_recv_pkts", tags, m.meta, map[string]interface{}{"value": float64(v)}, time.Now())
|
|
||||||
if err == nil {
|
|
||||||
output <- y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buffer, err = ioutil.ReadFile(fmt.Sprintf("%s/port_xmit_packets", path))
|
|
||||||
if err == nil {
|
|
||||||
data := strings.Replace(string(buffer), "\n", "", -1)
|
|
||||||
v, err := strconv.ParseFloat(data, 64)
|
|
||||||
if err == nil {
|
|
||||||
y, err := lp.New("ib_xmit_pkts", tags, m.meta, map[string]interface{}{"value": float64(v)}, time.Now())
|
|
||||||
if err == nil {
|
|
||||||
output <- y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *InfinibandPerfQueryCollector) Close() {
|
|
||||||
m.init = false
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
|
|
||||||
## `ibstat_perfquery` collector
|
|
||||||
|
|
||||||
```json
|
|
||||||
"ibstat_perfquery": {
|
|
||||||
"perfquery_path": "/path/to/perfquery",
|
|
||||||
"exclude_devices": [
|
|
||||||
"mlx4"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The `ibstat_perfquery` collector includes all Infiniband devices that can be
|
|
||||||
found below `/sys/class/infiniband/` and where any of the ports provides a
|
|
||||||
LID file (`/sys/class/infiniband/<dev>/ports/<port>/lid`)
|
|
||||||
|
|
||||||
The devices can be filtered with the `exclude_devices` option in the configuration.
|
|
||||||
|
|
||||||
For each found LID the collector calls the `perfquery` command. The path to the
|
|
||||||
`perfquery` command can be configured with the `perfquery_path` option in the configuration
|
|
||||||
|
|
||||||
Metrics:
|
|
||||||
* `ib_recv`
|
|
||||||
* `ib_xmit`
|
|
||||||
* `ib_recv_pkts`
|
|
||||||
* `ib_xmit_pkts`
|
|
||||||
|
|
||||||
The collector adds a `device` tag to all metrics
|
|
||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
|
||||||
// "log"
|
// "log"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -37,6 +37,7 @@ type IOstatCollector struct {
|
|||||||
func (m *IOstatCollector) Init(config json.RawMessage) error {
|
func (m *IOstatCollector) Init(config json.RawMessage) error {
|
||||||
var err error
|
var err error
|
||||||
m.name = "IOstatCollector"
|
m.name = "IOstatCollector"
|
||||||
|
m.parallel = true
|
||||||
m.meta = map[string]string{"source": m.name, "group": "Disk"}
|
m.meta = map[string]string{"source": m.name, "group": "Disk"}
|
||||||
m.setup()
|
m.setup()
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
@@ -106,7 +107,7 @@ func (m *IOstatCollector) Init(config json.RawMessage) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *IOstatCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *IOstatCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -138,7 +139,7 @@ func (m *IOstatCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
x, err := strconv.ParseInt(linefields[idx], 0, 64)
|
x, err := strconv.ParseInt(linefields[idx], 0, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
diff := x - entry.lastValues[name]
|
diff := x - entry.lastValues[name]
|
||||||
y, err := lp.New(name, entry.tags, m.meta, map[string]interface{}{"value": int(diff)}, time.Now())
|
y, err := lp.NewMessage(name, entry.tags, m.meta, map[string]interface{}{"value": int(diff)}, time.Now())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,85 +1,116 @@
|
|||||||
package collectors
|
package collectors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
const IPMITOOL_PATH = `ipmitool`
|
|
||||||
const IPMISENSORS_PATH = `ipmi-sensors`
|
const IPMISENSORS_PATH = `ipmi-sensors`
|
||||||
|
|
||||||
type IpmiCollectorConfig struct {
|
|
||||||
ExcludeDevices []string `json:"exclude_devices"`
|
|
||||||
IpmitoolPath string `json:"ipmitool_path"`
|
|
||||||
IpmisensorsPath string `json:"ipmisensors_path"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type IpmiCollector struct {
|
type IpmiCollector struct {
|
||||||
metricCollector
|
metricCollector
|
||||||
//tags map[string]string
|
config struct {
|
||||||
//matches map[string]string
|
ExcludeDevices []string `json:"exclude_devices"`
|
||||||
config IpmiCollectorConfig
|
IpmitoolPath string `json:"ipmitool_path"`
|
||||||
|
IpmisensorsPath string `json:"ipmisensors_path"`
|
||||||
|
}
|
||||||
ipmitool string
|
ipmitool string
|
||||||
ipmisensors string
|
ipmisensors string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *IpmiCollector) Init(config json.RawMessage) error {
|
func (m *IpmiCollector) Init(config json.RawMessage) error {
|
||||||
|
// Check if already initialized
|
||||||
|
if m.init {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
m.name = "IpmiCollector"
|
m.name = "IpmiCollector"
|
||||||
m.setup()
|
m.setup()
|
||||||
m.meta = map[string]string{"source": m.name, "group": "IPMI"}
|
m.parallel = true
|
||||||
m.config.IpmitoolPath = string(IPMITOOL_PATH)
|
m.meta = map[string]string{
|
||||||
m.config.IpmisensorsPath = string(IPMISENSORS_PATH)
|
"source": m.name,
|
||||||
m.ipmitool = ""
|
"group": "IPMI",
|
||||||
m.ipmisensors = ""
|
}
|
||||||
|
// default path to IPMI tools
|
||||||
|
m.config.IpmitoolPath = "ipmitool"
|
||||||
|
m.config.IpmisensorsPath = "ipmi-sensors"
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err := json.Unmarshal(config, &m.config)
|
err := json.Unmarshal(config, &m.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check if executables ipmitool or ipmisensors are found
|
||||||
p, err := exec.LookPath(m.config.IpmitoolPath)
|
p, err := exec.LookPath(m.config.IpmitoolPath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
command := exec.Command(p)
|
||||||
|
err := command.Run()
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(m.name, fmt.Sprintf("Failed to execute %s: %v", p, err.Error()))
|
||||||
|
m.ipmitool = ""
|
||||||
|
} else {
|
||||||
m.ipmitool = p
|
m.ipmitool = p
|
||||||
}
|
}
|
||||||
|
}
|
||||||
p, err = exec.LookPath(m.config.IpmisensorsPath)
|
p, err = exec.LookPath(m.config.IpmisensorsPath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
command := exec.Command(p)
|
||||||
|
err := command.Run()
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(m.name, fmt.Sprintf("Failed to execute %s: %v", p, err.Error()))
|
||||||
|
m.ipmisensors = ""
|
||||||
|
} else {
|
||||||
m.ipmisensors = p
|
m.ipmisensors = p
|
||||||
}
|
}
|
||||||
if len(m.ipmitool) == 0 && len(m.ipmisensors) == 0 {
|
|
||||||
return errors.New("No IPMI reader found")
|
|
||||||
}
|
}
|
||||||
|
if len(m.ipmitool) == 0 && len(m.ipmisensors) == 0 {
|
||||||
|
return errors.New("no usable IPMI reader found")
|
||||||
|
}
|
||||||
|
|
||||||
m.init = true
|
m.init = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *IpmiCollector) readIpmiTool(cmd string, output chan lp.CCMetric) {
|
func (m *IpmiCollector) readIpmiTool(cmd string, output chan lp.CCMessage) {
|
||||||
|
|
||||||
|
// Setup ipmitool command
|
||||||
command := exec.Command(cmd, "sensor")
|
command := exec.Command(cmd, "sensor")
|
||||||
command.Wait()
|
stdout, _ := command.StdoutPipe()
|
||||||
stdout, err := command.Output()
|
errBuf := new(bytes.Buffer)
|
||||||
if err != nil {
|
command.Stderr = errBuf
|
||||||
log.Print(err)
|
|
||||||
|
// start command
|
||||||
|
if err := command.Start(); err != nil {
|
||||||
|
cclog.ComponentError(
|
||||||
|
m.name,
|
||||||
|
fmt.Sprintf("readIpmiTool(): Failed to start command \"%s\": %v", command.String(), err),
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ll := strings.Split(string(stdout), "\n")
|
// Read command output
|
||||||
|
scanner := bufio.NewScanner(stdout)
|
||||||
for _, line := range ll {
|
for scanner.Scan() {
|
||||||
lv := strings.Split(line, "|")
|
lv := strings.Split(scanner.Text(), "|")
|
||||||
if len(lv) < 3 {
|
if len(lv) < 3 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
v, err := strconv.ParseFloat(strings.Trim(lv[1], " "), 64)
|
v, err := strconv.ParseFloat(strings.TrimSpace(lv[1]), 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
name := strings.ToLower(strings.Replace(strings.Trim(lv[0], " "), " ", "_", -1))
|
name := strings.ToLower(strings.Replace(strings.TrimSpace(lv[0]), " ", "_", -1))
|
||||||
unit := strings.Trim(lv[2], " ")
|
unit := strings.TrimSpace(lv[2])
|
||||||
if unit == "Volts" {
|
if unit == "Volts" {
|
||||||
unit = "Volts"
|
unit = "Volts"
|
||||||
} else if unit == "degrees C" {
|
} else if unit == "degrees C" {
|
||||||
@@ -90,16 +121,27 @@ func (m *IpmiCollector) readIpmiTool(cmd string, output chan lp.CCMetric) {
|
|||||||
unit = "Watts"
|
unit = "Watts"
|
||||||
}
|
}
|
||||||
|
|
||||||
y, err := lp.New(name, map[string]string{"type": "node"}, m.meta, map[string]interface{}{"value": v}, time.Now())
|
y, err := lp.NewMessage(name, map[string]string{"type": "node"}, m.meta, map[string]interface{}{"value": v}, time.Now())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
y.AddMeta("unit", unit)
|
y.AddMeta("unit", unit)
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for command end
|
||||||
|
if err := command.Wait(); err != nil {
|
||||||
|
errMsg, _ := io.ReadAll(errBuf)
|
||||||
|
cclog.ComponentError(
|
||||||
|
m.name,
|
||||||
|
fmt.Sprintf("readIpmiTool(): Failed to wait for the end of command \"%s\": %v\n", command.String(), err),
|
||||||
|
)
|
||||||
|
cclog.ComponentError(m.name, fmt.Sprintf("readIpmiTool(): command stderr: \"%s\"\n", strings.TrimSpace(string(errMsg))))
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *IpmiCollector) readIpmiSensors(cmd string, output chan lp.CCMetric) {
|
func (m *IpmiCollector) readIpmiSensors(cmd string, output chan lp.CCMessage) {
|
||||||
|
|
||||||
command := exec.Command(cmd, "--comma-separated-output", "--sdr-cache-recreate")
|
command := exec.Command(cmd, "--comma-separated-output", "--sdr-cache-recreate")
|
||||||
command.Wait()
|
command.Wait()
|
||||||
@@ -117,7 +159,7 @@ func (m *IpmiCollector) readIpmiSensors(cmd string, output chan lp.CCMetric) {
|
|||||||
v, err := strconv.ParseFloat(lv[3], 64)
|
v, err := strconv.ParseFloat(lv[3], 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
name := strings.ToLower(strings.Replace(lv[1], " ", "_", -1))
|
name := strings.ToLower(strings.Replace(lv[1], " ", "_", -1))
|
||||||
y, err := lp.New(name, map[string]string{"type": "node"}, m.meta, map[string]interface{}{"value": v}, time.Now())
|
y, err := lp.NewMessage(name, map[string]string{"type": "node"}, m.meta, map[string]interface{}{"value": v}, time.Now())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if len(lv) > 4 {
|
if len(lv) > 4 {
|
||||||
y.AddMeta("unit", lv[4])
|
y.AddMeta("unit", lv[4])
|
||||||
@@ -129,18 +171,18 @@ func (m *IpmiCollector) readIpmiSensors(cmd string, output chan lp.CCMetric) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *IpmiCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *IpmiCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
|
|
||||||
|
// Check if already initialized
|
||||||
|
if !m.init {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if len(m.config.IpmitoolPath) > 0 {
|
if len(m.config.IpmitoolPath) > 0 {
|
||||||
_, err := os.Stat(m.config.IpmitoolPath)
|
|
||||||
if err == nil {
|
|
||||||
m.readIpmiTool(m.config.IpmitoolPath, output)
|
m.readIpmiTool(m.config.IpmitoolPath, output)
|
||||||
}
|
|
||||||
} else if len(m.config.IpmisensorsPath) > 0 {
|
} else if len(m.config.IpmisensorsPath) > 0 {
|
||||||
_, err := os.Stat(m.config.IpmisensorsPath)
|
|
||||||
if err == nil {
|
|
||||||
m.readIpmiSensors(m.config.IpmisensorsPath, output)
|
m.readIpmiSensors(m.config.IpmisensorsPath, output)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *IpmiCollector) Close() {
|
func (m *IpmiCollector) Close() {
|
||||||
|
|||||||
@@ -11,6 +11,3 @@
|
|||||||
The `ipmistat` collector reads data from `ipmitool` (`ipmitool sensor`) or `ipmi-sensors` (`ipmi-sensors --sdr-cache-recreate --comma-separated-output`).
|
The `ipmistat` collector reads data from `ipmitool` (`ipmitool sensor`) or `ipmi-sensors` (`ipmi-sensors --sdr-cache-recreate --comma-separated-output`).
|
||||||
|
|
||||||
The metrics depend on the output of the underlying tools but contain temperature, power and energy metrics.
|
The metrics depend on the output of the underlying tools but contain temperature, power and energy metrics.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -3,34 +3,77 @@
|
|||||||
|
|
||||||
The `likwid` collector is probably the most complicated collector. The LIKWID library is included as static library with *direct* access mode. The *direct* access mode is suitable if the daemon is executed by a root user. The static library does not contain the performance groups, so all information needs to be provided in the configuration.
|
The `likwid` collector is probably the most complicated collector. The LIKWID library is included as static library with *direct* access mode. The *direct* access mode is suitable if the daemon is executed by a root user. The static library does not contain the performance groups, so all information needs to be provided in the configuration.
|
||||||
|
|
||||||
The `likwid` configuration consists of two parts, the "eventsets" and "globalmetrics":
|
```json
|
||||||
- An event set list itself has two parts, the "events" and a set of derivable "metrics". Each of the "events" is a counter:event pair in LIKWID's syntax. The "metrics" are a list of formulas to derive the metric value from the measurements of the "events". Each metric has a name, the formula, a scope and a publish flag. Counter names can be used like variables in the formulas, so `PMC0+PMC1` sums the measurements for the both events configured in the counters `PMC0` and `PMC1`. The scope tells the Collector whether it is a metric for each hardware thread (`cpu`) or each CPU socket (`socket`). The last one is the publishing flag. It tells the collector whether a metric should be sent to the router.
|
"likwid": {
|
||||||
- The global metrics are metrics which require data from all event set measurements to be derived. The inputs are the metrics in the event sets. Similar to the metrics in the event sets, the global metrics are defined by a name, a formula, a scope and a publish flag. See event set metrics for details. The only difference is that there is no access to the raw event measurements anymore but only to the metrics. So, the idea is to derive a metric in the "eventsets" section and reuse it in the "globalmetrics" part. If you need a metric only for deriving the global metrics, disable forwarding of the event set metrics. **Be aware** that the combination might be misleading because the "behavior" of a metric changes over time and the multiple measurements might count different computing phases.
|
"force_overwrite" : false,
|
||||||
|
"invalid_to_zero" : false,
|
||||||
|
"liblikwid_path" : "/path/to/liblikwid.so",
|
||||||
|
"accessdaemon_path" : "/folder/that/contains/likwid-accessD",
|
||||||
|
"access_mode" : "direct or accessdaemon or perf_event",
|
||||||
|
"lockfile_path" : "/var/run/likwid.lock",
|
||||||
|
"eventsets": [
|
||||||
|
{
|
||||||
|
"events" : {
|
||||||
|
"COUNTER0": "EVENT0",
|
||||||
|
"COUNTER1": "EVENT1"
|
||||||
|
},
|
||||||
|
"metrics" : [
|
||||||
|
{
|
||||||
|
"name": "sum_01",
|
||||||
|
"calc": "COUNTER0 + COUNTER1",
|
||||||
|
"publish": false,
|
||||||
|
"unit": "myunit",
|
||||||
|
"type": "hwthread"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"globalmetrics" : [
|
||||||
|
{
|
||||||
|
"name": "global_sum",
|
||||||
|
"calc": "sum_01",
|
||||||
|
"publish": true,
|
||||||
|
"unit": "myunit",
|
||||||
|
"type": "hwthread"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `likwid` configuration consists of two parts, the `eventsets` and `globalmetrics`:
|
||||||
|
|
||||||
|
- An event set list itself has two parts, the `events` and a set of derivable `metrics`. Each of the `events` is a `counter:event` pair in LIKWID's syntax. The `metrics` are a list of formulas to derive the metric value from the measurements of the `events`' values. Each metric has a name, the formula, a type and a publish flag. There is an optional `unit` field. Counter names can be used like variables in the formulas, so `PMC0+PMC1` sums the measurements for the both events configured in the counters `PMC0` and `PMC1`. You can optionally use `time` for the measurement time and `inverseClock` for `1.0/baseCpuFrequency`. The type tells the LikwidCollector whether it is a metric for each hardware thread (`cpu`) or each CPU socket (`socket`). You may specify a unit for the metric with `unit`. The last one is the publishing flag. It tells the LikwidCollector whether a metric should be sent to the router or is only used internally to compute a global metric.
|
||||||
|
- The `globalmetrics` are metrics which require data from multiple event set measurements to be derived. The inputs are the metrics in the event sets. Similar to the metrics in the event sets, the global metrics are defined by a name, a formula, a type and a publish flag. See event set metrics for details. The only difference is that there is no access to the raw event measurements anymore but only to the metrics. Also `time` and `inverseClock` cannot be used anymore. So, the idea is to derive a metric in the `eventsets` section and reuse it in the `globalmetrics` part. If you need a metric only for deriving the global metrics, disable forwarding of the event set metrics (`"publish": false`). **Be aware** that the combination might be misleading because the "behavior" of a metric changes over time and the multiple measurements might count different computing phases. Similar to the metrics in the eventset, you can specify a metric unit with the `unit` field.
|
||||||
|
|
||||||
Additional options:
|
Additional options:
|
||||||
- `access_mode` : Method to use for hardware performance monitoring (`direct` access as root user, `accessdaemon` for the daemon mode)
|
|
||||||
- `accessdaemon_path`: Folder with the access daemon `likwid-accessD`, commonly `$LIKWID_INSTALL_LOC/sbin`
|
|
||||||
- `force_overwrite`: Same as setting `LIKWID_FORCE=1`. In case counters are already in-use, LIKWID overwrites their configuration to do its measurements
|
- `force_overwrite`: Same as setting `LIKWID_FORCE=1`. In case counters are already in-use, LIKWID overwrites their configuration to do its measurements
|
||||||
- `invalid_to_zero`: In some cases, the calculations result in `NaN` or `Inf`. With this option, all `NaN` and `Inf` values are replaces with `0.0`.
|
- `invalid_to_zero`: In some cases, the calculations result in `NaN` or `Inf`. With this option, all `NaN` and `Inf` values are replaces with `0.0`. See below in [seperate section](./likwidMetric.md#invalid_to_zero-option)
|
||||||
|
- `access_mode`: Specify LIKWID access mode: `direct` for direct register access as root user or `accessdaemon`. The access mode `perf_event` is current untested.
|
||||||
|
- `accessdaemon_path`: Folder of the accessDaemon `likwid-accessD` (like `/usr/local/sbin`)
|
||||||
|
- `liblikwid_path`: Location of `liblikwid.so` including file name like `/usr/local/lib/liblikwid.so`
|
||||||
|
- `lockfile_path`: Location of LIKWID's lock file if multiple tools should access the hardware counters. Default `/var/run/likwid.lock`
|
||||||
|
|
||||||
### Available metric scopes
|
### Available metric types
|
||||||
|
|
||||||
Hardware performance counters are scattered all over the system nowadays. A counter coveres a specific part of the system. While there are hardware thread specific counter for CPU cycles, instructions and so on, some others are specific for a whole CPU socket/package. To address that, the collector provides the specification of a 'scope' for each metric.
|
Hardware performance counters are scattered all over the system nowadays. A counter coveres a specific part of the system. While there are hardware thread specific counter for CPU cycles, instructions and so on, some others are specific for a whole CPU socket/package. To address that, the LikwidCollector provides the specification of a `type` for each metric.
|
||||||
|
|
||||||
- `cpu` : One metric per CPU hardware thread with the tags `"type" : "cpu"` and `"type-id" : "$cpu_id"`
|
- `hwthread` : One metric per CPU hardware thread with the tags `"type" : "hwthread"` and `"type-id" : "$hwthread_id"`
|
||||||
- `socket` : One metric per CPU socket/package with the tags `"type" : "socket"` and `"type-id" : "$socket_id"`
|
- `socket` : One metric per CPU socket/package with the tags `"type" : "socket"` and `"type-id" : "$socket_id"`
|
||||||
|
|
||||||
**Note:** You cannot specify `socket` scope for a metric that is measured at `cpu` scope, so some kind of expert knowledge or lookup work in the [Likwid Wiki](https://github.com/RRZE-HPC/likwid/wiki) is required. Get the scope of each counter from the *Architecture* pages and as soon as one counter in a metric is socket-specific, the whole metric is socket-specific.
|
**Note:** You cannot specify `socket` type for a metric that is measured at `hwthread` type, so some kind of expert knowledge or lookup work in the [Likwid Wiki](https://github.com/RRZE-HPC/likwid/wiki) is required. Get the type of each counter from the *Architecture* pages and as soon as one counter in a metric is socket-specific, the whole metric is socket-specific.
|
||||||
|
|
||||||
As a guideline:
|
As a guideline:
|
||||||
- All counters `FIXCx`, `PMCy` and `TMAz` have the scope `cpu`
|
|
||||||
- All counters names containing `BOX` have the scope `socket`
|
- All counters `FIXCx`, `PMCy` and `TMAz` have the type `hwthread`
|
||||||
- All `PWRx` counters have scope `socket`, except `"PWR1" : "RAPL_CORE_ENERGY"` has `cpu` scope
|
- All counters names containing `BOX` have the type `socket`
|
||||||
- All `DFCx` counters have scope `socket`
|
- All `PWRx` counters have type `socket`, except `"PWR1" : "RAPL_CORE_ENERGY"` has `hwthread` type
|
||||||
|
- All `DFCx` counters have type `socket`
|
||||||
|
|
||||||
### Help with the configuration
|
### Help with the configuration
|
||||||
|
|
||||||
The configuration for the `likwid` collector is quite complicated. Most users don't use LIKWID with the event:counter notation but rely on the performance groups defined by the LIKWID team for each architecture. In order to help with the `likwid` collector configuration, we included a script `scripts/likwid_perfgroup_to_cc_config.py` that creates the configuration of an `eventset` from a performance group (using a LIKWID installation in `$PATH`):
|
The configuration for the `likwid` collector is quite complicated. Most users don't use LIKWID with the event:counter notation but rely on the performance groups defined by the LIKWID team for each architecture. In order to help with the `likwid` collector configuration, we included a script `scripts/likwid_perfgroup_to_cc_config.py` that creates the configuration of an `eventset` from a performance group (using a LIKWID installation in `$PATH`):
|
||||||
|
|
||||||
```
|
```
|
||||||
$ likwid-perfctr -i
|
$ likwid-perfctr -i
|
||||||
[...]
|
[...]
|
||||||
@@ -47,6 +90,7 @@ $ scripts/likwid_perfgroup_to_cc_config.py ICX MEM_DP
|
|||||||
{
|
{
|
||||||
"events": {
|
"events": {
|
||||||
"FIXC0": "INSTR_RETIRED_ANY",
|
"FIXC0": "INSTR_RETIRED_ANY",
|
||||||
|
"FIXC1": "CPU_CLK_UNHALTED_CORE",
|
||||||
"..." : "..."
|
"..." : "..."
|
||||||
},
|
},
|
||||||
"metrics" : [
|
"metrics" : [
|
||||||
@@ -54,7 +98,8 @@ $ scripts/likwid_perfgroup_to_cc_config.py ICX MEM_DP
|
|||||||
"calc": "time",
|
"calc": "time",
|
||||||
"name": "Runtime (RDTSC) [s]",
|
"name": "Runtime (RDTSC) [s]",
|
||||||
"publish": true,
|
"publish": true,
|
||||||
"scope": "hwthread"
|
"unit": "seconds"
|
||||||
|
"type": "hwthread"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"..." : "..."
|
"..." : "..."
|
||||||
@@ -70,22 +115,40 @@ You can copy this JSON and add it to the `eventsets` list. If you specify multip
|
|||||||
LIKWID checks the file `/var/run/likwid.lock` before performing any interfering operations. Who is allowed to access the counters is determined by the owner of the file. If it does not exist, it is created for the current user. So, if you want to temporarly allow counter access to a user (e.g. in a job):
|
LIKWID checks the file `/var/run/likwid.lock` before performing any interfering operations. Who is allowed to access the counters is determined by the owner of the file. If it does not exist, it is created for the current user. So, if you want to temporarly allow counter access to a user (e.g. in a job):
|
||||||
|
|
||||||
Before (SLURM prolog, ...)
|
Before (SLURM prolog, ...)
|
||||||
```
|
|
||||||
$ chwon $JOBUSER /var/run/likwid.lock
|
```bash
|
||||||
|
chown $JOBUSER /var/run/likwid.lock
|
||||||
```
|
```
|
||||||
|
|
||||||
After (SLURM epilog, ...)
|
After (SLURM epilog, ...)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
chown $CCUSER /var/run/likwid.lock
|
||||||
```
|
```
|
||||||
$ chwon $CCUSER /var/run/likwid.lock
|
|
||||||
```
|
### `invalid_to_zero` option
|
||||||
|
|
||||||
|
In some cases LIKWID returns `0.0` for some events that are further used in processing and maybe used as divisor in a calculation. After evaluation of a metric, the result might be `NaN` or `+-Inf`. These resulting metrics are commonly not created and forwarded to the router because the [InfluxDB line protocol](https://docs.influxdata.com/influxdb/cloud/reference/syntax/line-protocol/#float) does not support these special floating-point values. If you want to have them sent, this option forces these metric values to be `0.0` instead.
|
||||||
|
|
||||||
|
One might think this does not happen often but often used metrics in the world of performance engineering like Instructions-per-Cycle (IPC) or more frequently the actual CPU clock are derived with events like `CPU_CLK_UNHALTED_CORE` (Intel) which do not increment in halted state (as the name implies). In there are different power management systems in a chip which can cause a hardware thread to go in such a state. Moreover, if no cycles are executed by the core, also many other events are not incremented as well (like `INSTR_RETIRED_ANY` for retired instructions and part of IPC).
|
||||||
|
|
||||||
|
### `lockfile_path` option
|
||||||
|
LIKWID can be configured with a lock file with which the access to the performance monitoring registers can be disabled (only the owner of the lock file is allowed to access the registers). When the `lockfile_path` option is set, the collector subscribes to changes to this file to stop monitoring if the owner of the lock file changes. This feature is useful when users should be able to perform own hardware performance counter measurements through LIKWID or any other tool.
|
||||||
|
|
||||||
|
### `send_*_total values` option
|
||||||
|
|
||||||
|
- `send_core_total_values`: Metrics, which are usually collected on a per hardware thread basis, are additionally summed up per CPU core.
|
||||||
|
- `send_socket_total_values` Metrics, which are usually collected on a per hardware thread basis, are additionally summed up per CPU socket.
|
||||||
|
- `send_node_total_values` Metrics, which are usually collected on a per hardware thread basis, are additionally summed up per node.
|
||||||
|
|
||||||
### Example configuration
|
### Example configuration
|
||||||
|
|
||||||
|
#### AMD Zen3
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"likwid": {
|
"likwid": {
|
||||||
"force_overwrite" : false,
|
"force_overwrite" : false,
|
||||||
"nan_to_zero" : false,
|
"invalid_to_zero" : false,
|
||||||
"eventsets": [
|
"eventsets": [
|
||||||
{
|
{
|
||||||
"events": {
|
"events": {
|
||||||
@@ -104,25 +167,28 @@ $ chwon $CCUSER /var/run/likwid.lock
|
|||||||
{
|
{
|
||||||
"name": "ipc",
|
"name": "ipc",
|
||||||
"calc": "PMC0/PMC1",
|
"calc": "PMC0/PMC1",
|
||||||
"scope": "cpu",
|
"type": "hwthread",
|
||||||
"publish": true
|
"publish": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "flops_any",
|
"name": "flops_any",
|
||||||
"calc": "0.000001*PMC2/time",
|
"calc": "0.000001*PMC2/time",
|
||||||
"scope": "cpu",
|
"unit": "MFlops/s",
|
||||||
|
"type": "hwthread",
|
||||||
"publish": true
|
"publish": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "clock_mhz",
|
"name": "clock",
|
||||||
"calc": "0.000001*(FIXC1/FIXC2)/inverseClock",
|
"calc": "0.000001*(FIXC1/FIXC2)/inverseClock",
|
||||||
"scope": "cpu",
|
"type": "hwthread",
|
||||||
|
"unit": "MHz",
|
||||||
"publish": true
|
"publish": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "mem1",
|
"name": "mem1",
|
||||||
"calc": "0.000001*(DFC0+DFC1+DFC2+DFC3)*64.0/time",
|
"calc": "0.000001*(DFC0+DFC1+DFC2+DFC3)*64.0/time",
|
||||||
"scope": "socket",
|
"unit": "Mbyte/s",
|
||||||
|
"type": "socket",
|
||||||
"publish": false
|
"publish": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -140,19 +206,22 @@ $ chwon $CCUSER /var/run/likwid.lock
|
|||||||
{
|
{
|
||||||
"name": "pwr_core",
|
"name": "pwr_core",
|
||||||
"calc": "PWR0/time",
|
"calc": "PWR0/time",
|
||||||
"scope": "socket",
|
"unit": "Watt"
|
||||||
|
"type": "socket",
|
||||||
"publish": true
|
"publish": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pwr_pkg",
|
"name": "pwr_pkg",
|
||||||
"calc": "PWR1/time",
|
"calc": "PWR1/time",
|
||||||
"scope": "socket",
|
"type": "socket",
|
||||||
|
"unit": "Watt"
|
||||||
"publish": true
|
"publish": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "mem2",
|
"name": "mem2",
|
||||||
"calc": "0.000001*(DFC0+DFC1+DFC2+DFC3)*64.0/time",
|
"calc": "0.000001*(DFC0+DFC1+DFC2+DFC3)*64.0/time",
|
||||||
"scope": "socket",
|
"unit": "Mbyte/s",
|
||||||
|
"type": "socket",
|
||||||
"publish": false
|
"publish": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -162,7 +231,8 @@ $ chwon $CCUSER /var/run/likwid.lock
|
|||||||
{
|
{
|
||||||
"name": "mem_bw",
|
"name": "mem_bw",
|
||||||
"calc": "mem1+mem2",
|
"calc": "mem1+mem2",
|
||||||
"scope": "socket",
|
"type": "socket",
|
||||||
|
"unit": "Mbyte/s",
|
||||||
"publish": true
|
"publish": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -171,9 +241,10 @@ $ chwon $CCUSER /var/run/likwid.lock
|
|||||||
|
|
||||||
### How to get the eventsets and metrics from LIKWID
|
### How to get the eventsets and metrics from LIKWID
|
||||||
|
|
||||||
The `likwid` collector reads hardware performance counters at a **cpu** and **socket** level. The configuration looks quite complicated but it is basically copy&paste from [LIKWID's performance groups](https://github.com/RRZE-HPC/likwid/tree/master/groups). The collector made multiple iterations and tried to use the performance groups but it lacked flexibility. The current way of configuration provides most flexibility.
|
The `likwid` collector reads hardware performance counters at a **hwthread** and **socket** level. The configuration looks quite complicated but it is basically copy&paste from [LIKWID's performance groups](https://github.com/RRZE-HPC/likwid/tree/master/groups). The collector made multiple iterations and tried to use the performance groups but it lacked flexibility. The current way of configuration provides most flexibility.
|
||||||
|
|
||||||
The logic is as following: There are multiple eventsets, each consisting of a list of counters+events and a list of metrics. If you compare a common performance group with the example setting above, there is not much difference:
|
The logic is as following: There are multiple eventsets, each consisting of a list of counters+events and a list of metrics. If you compare a common performance group with the example setting above, there is not much difference:
|
||||||
|
|
||||||
```
|
```
|
||||||
EVENTSET -> "events": {
|
EVENTSET -> "events": {
|
||||||
FIXC1 ACTUAL_CPU_CLOCK -> "FIXC1": "ACTUAL_CPU_CLOCK",
|
FIXC1 ACTUAL_CPU_CLOCK -> "FIXC1": "ACTUAL_CPU_CLOCK",
|
||||||
@@ -192,9 +263,10 @@ METRICS -> "metrics": [
|
|||||||
IPC PMC0/PMC1 -> {
|
IPC PMC0/PMC1 -> {
|
||||||
-> "name" : "IPC",
|
-> "name" : "IPC",
|
||||||
-> "calc" : "PMC0/PMC1",
|
-> "calc" : "PMC0/PMC1",
|
||||||
-> "scope": "cpu",
|
-> "type": "hwthread",
|
||||||
-> "publish": true
|
-> "publish": true
|
||||||
-> }
|
-> }
|
||||||
-> ]
|
-> ]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The script `scripts/likwid_perfgroup_to_cc_config.py` might help you.
|
||||||
|
|||||||
@@ -3,23 +3,21 @@ package collectors
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
)
|
)
|
||||||
|
|
||||||
//
|
|
||||||
// LoadavgCollector collects:
|
// LoadavgCollector collects:
|
||||||
// * load average of last 1, 5 & 15 minutes
|
// * load average of last 1, 5 & 15 minutes
|
||||||
// * number of processes currently runnable
|
// * number of processes currently runnable
|
||||||
// * total number of processes in system
|
// * total number of processes in system
|
||||||
//
|
//
|
||||||
// See: https://www.kernel.org/doc/html/latest/filesystems/proc.html
|
// See: https://www.kernel.org/doc/html/latest/filesystems/proc.html
|
||||||
//
|
|
||||||
const LOADAVGFILE = "/proc/loadavg"
|
const LOADAVGFILE = "/proc/loadavg"
|
||||||
|
|
||||||
type LoadavgCollector struct {
|
type LoadavgCollector struct {
|
||||||
@@ -36,6 +34,7 @@ type LoadavgCollector struct {
|
|||||||
|
|
||||||
func (m *LoadavgCollector) Init(config json.RawMessage) error {
|
func (m *LoadavgCollector) Init(config json.RawMessage) error {
|
||||||
m.name = "LoadavgCollector"
|
m.name = "LoadavgCollector"
|
||||||
|
m.parallel = true
|
||||||
m.setup()
|
m.setup()
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err := json.Unmarshal(config, &m.config)
|
err := json.Unmarshal(config, &m.config)
|
||||||
@@ -67,17 +66,15 @@ func (m *LoadavgCollector) Init(config json.RawMessage) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *LoadavgCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *LoadavgCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
buffer, err := ioutil.ReadFile(LOADAVGFILE)
|
buffer, err := os.ReadFile(LOADAVGFILE)
|
||||||
if err != nil {
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.ComponentError(
|
cclog.ComponentError(
|
||||||
m.name,
|
m.name,
|
||||||
fmt.Sprintf("Read(): Failed to read file '%s': %v", LOADAVGFILE, err))
|
fmt.Sprintf("Read(): Failed to read file '%s': %v", LOADAVGFILE, err))
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
@@ -95,7 +92,7 @@ func (m *LoadavgCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
if m.load_skips[i] {
|
if m.load_skips[i] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
y, err := lp.New(name, m.tags, m.meta, map[string]interface{}{"value": x}, now)
|
y, err := lp.NewMessage(name, m.tags, m.meta, map[string]interface{}{"value": x}, now)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
@@ -114,7 +111,7 @@ func (m *LoadavgCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
if m.proc_skips[i] {
|
if m.proc_skips[i] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
y, err := lp.New(name, m.tags, m.meta, map[string]interface{}{"value": x}, now)
|
y, err := lp.NewMessage(name, m.tags, m.meta, map[string]interface{}{"value": x}, now)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
const LUSTRE_SYSFS = `/sys/fs/lustre`
|
const LUSTRE_SYSFS = `/sys/fs/lustre`
|
||||||
@@ -19,20 +19,31 @@ const LCTL_CMD = `lctl`
|
|||||||
const LCTL_OPTION = `get_param`
|
const LCTL_OPTION = `get_param`
|
||||||
|
|
||||||
type LustreCollectorConfig struct {
|
type LustreCollectorConfig struct {
|
||||||
LCtlCommand string `json:"lctl_command"`
|
LCtlCommand string `json:"lctl_command,omitempty"`
|
||||||
ExcludeMetrics []string `json:"exclude_metrics"`
|
ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
|
||||||
SendAllMetrics bool `json:"send_all_metrics"`
|
Sudo bool `json:"use_sudo,omitempty"`
|
||||||
Sudo bool `json:"use_sudo"`
|
SendAbsoluteValues bool `json:"send_abs_values,omitempty"`
|
||||||
|
SendDerivedValues bool `json:"send_derived_values,omitempty"`
|
||||||
|
SendDiffValues bool `json:"send_diff_values,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LustreMetricDefinition struct {
|
||||||
|
name string
|
||||||
|
lineprefix string
|
||||||
|
lineoffset int
|
||||||
|
unit string
|
||||||
|
calc string
|
||||||
}
|
}
|
||||||
|
|
||||||
type LustreCollector struct {
|
type LustreCollector struct {
|
||||||
metricCollector
|
metricCollector
|
||||||
tags map[string]string
|
tags map[string]string
|
||||||
matches map[string]map[string]int
|
|
||||||
stats map[string]map[string]int64
|
|
||||||
config LustreCollectorConfig
|
config LustreCollectorConfig
|
||||||
lctl string
|
lctl string
|
||||||
sudoCmd string
|
sudoCmd string
|
||||||
|
lastTimestamp time.Time // Store time stamp of last tick to derive bandwidths
|
||||||
|
definitions []LustreMetricDefinition // Combined list without excluded metrics
|
||||||
|
stats map[string]map[string]int64 // Data for last value per device and metric
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *LustreCollector) getDeviceDataCommand(device string) []string {
|
func (m *LustreCollector) getDeviceDataCommand(device string) []string {
|
||||||
@@ -75,21 +86,209 @@ func (m *LustreCollector) getDevices() []string {
|
|||||||
return devices
|
return devices
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getMetricData(lines []string, prefix string, offset int) (int64, error) {
|
||||||
|
for _, line := range lines {
|
||||||
|
if strings.HasPrefix(line, prefix) {
|
||||||
|
lf := strings.Fields(line)
|
||||||
|
return strconv.ParseInt(lf[offset], 0, 64)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, errors.New("no such line in data")
|
||||||
|
}
|
||||||
|
|
||||||
// //Version reading the stats data of a device from sysfs
|
// //Version reading the stats data of a device from sysfs
|
||||||
// func (m *LustreCollector) getDeviceDataSysfs(device string) []string {
|
// func (m *LustreCollector) getDeviceDataSysfs(device string) []string {
|
||||||
// llitedir := filepath.Join(LUSTRE_SYSFS, "llite")
|
// llitedir := filepath.Join(LUSTRE_SYSFS, "llite")
|
||||||
// devdir := filepath.Join(llitedir, device)
|
// devdir := filepath.Join(llitedir, device)
|
||||||
// statsfile := filepath.Join(devdir, "stats")
|
// statsfile := filepath.Join(devdir, "stats")
|
||||||
// buffer, err := ioutil.ReadFile(statsfile)
|
// buffer, err := os.ReadFile(statsfile)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// return make([]string, 0)
|
// return make([]string, 0)
|
||||||
// }
|
// }
|
||||||
// return strings.Split(string(buffer), "\n")
|
// return strings.Split(string(buffer), "\n")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
var LustreAbsMetrics = []LustreMetricDefinition{
|
||||||
|
{
|
||||||
|
name: "lustre_read_requests",
|
||||||
|
lineprefix: "read_bytes",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "requests",
|
||||||
|
calc: "none",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_write_requests",
|
||||||
|
lineprefix: "write_bytes",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "requests",
|
||||||
|
calc: "none",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_read_bytes",
|
||||||
|
lineprefix: "read_bytes",
|
||||||
|
lineoffset: 6,
|
||||||
|
unit: "bytes",
|
||||||
|
calc: "none",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_write_bytes",
|
||||||
|
lineprefix: "write_bytes",
|
||||||
|
lineoffset: 6,
|
||||||
|
unit: "bytes",
|
||||||
|
calc: "none",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_open",
|
||||||
|
lineprefix: "open",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "",
|
||||||
|
calc: "none",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_close",
|
||||||
|
lineprefix: "close",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "",
|
||||||
|
calc: "none",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_setattr",
|
||||||
|
lineprefix: "setattr",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "",
|
||||||
|
calc: "none",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_getattr",
|
||||||
|
lineprefix: "getattr",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "",
|
||||||
|
calc: "none",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_statfs",
|
||||||
|
lineprefix: "statfs",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "",
|
||||||
|
calc: "none",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_inode_permission",
|
||||||
|
lineprefix: "inode_permission",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "",
|
||||||
|
calc: "none",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var LustreDiffMetrics = []LustreMetricDefinition{
|
||||||
|
{
|
||||||
|
name: "lustre_read_requests_diff",
|
||||||
|
lineprefix: "read_bytes",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "requests",
|
||||||
|
calc: "difference",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_write_requests_diff",
|
||||||
|
lineprefix: "write_bytes",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "requests",
|
||||||
|
calc: "difference",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_read_bytes_diff",
|
||||||
|
lineprefix: "read_bytes",
|
||||||
|
lineoffset: 6,
|
||||||
|
unit: "bytes",
|
||||||
|
calc: "difference",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_write_bytes_diff",
|
||||||
|
lineprefix: "write_bytes",
|
||||||
|
lineoffset: 6,
|
||||||
|
unit: "bytes",
|
||||||
|
calc: "difference",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_open_diff",
|
||||||
|
lineprefix: "open",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "",
|
||||||
|
calc: "difference",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_close_diff",
|
||||||
|
lineprefix: "close",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "",
|
||||||
|
calc: "difference",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_setattr_diff",
|
||||||
|
lineprefix: "setattr",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "",
|
||||||
|
calc: "difference",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_getattr_diff",
|
||||||
|
lineprefix: "getattr",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "",
|
||||||
|
calc: "difference",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_statfs_diff",
|
||||||
|
lineprefix: "statfs",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "",
|
||||||
|
calc: "difference",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_inode_permission_diff",
|
||||||
|
lineprefix: "inode_permission",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "",
|
||||||
|
calc: "difference",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var LustreDeriveMetrics = []LustreMetricDefinition{
|
||||||
|
{
|
||||||
|
name: "lustre_read_requests_rate",
|
||||||
|
lineprefix: "read_bytes",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "requests/sec",
|
||||||
|
calc: "derivative",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_write_requests_rate",
|
||||||
|
lineprefix: "write_bytes",
|
||||||
|
lineoffset: 1,
|
||||||
|
unit: "requests/sec",
|
||||||
|
calc: "derivative",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_read_bw",
|
||||||
|
lineprefix: "read_bytes",
|
||||||
|
lineoffset: 6,
|
||||||
|
unit: "bytes/sec",
|
||||||
|
calc: "derivative",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "lustre_write_bw",
|
||||||
|
lineprefix: "write_bytes",
|
||||||
|
lineoffset: 6,
|
||||||
|
unit: "bytes/sec",
|
||||||
|
calc: "derivative",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
func (m *LustreCollector) Init(config json.RawMessage) error {
|
func (m *LustreCollector) Init(config json.RawMessage) error {
|
||||||
var err error
|
var err error
|
||||||
m.name = "LustreCollector"
|
m.name = "LustreCollector"
|
||||||
|
m.parallel = true
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err = json.Unmarshal(config, &m.config)
|
err = json.Unmarshal(config, &m.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -99,17 +298,10 @@ func (m *LustreCollector) Init(config json.RawMessage) error {
|
|||||||
m.setup()
|
m.setup()
|
||||||
m.tags = map[string]string{"type": "node"}
|
m.tags = map[string]string{"type": "node"}
|
||||||
m.meta = map[string]string{"source": m.name, "group": "Lustre"}
|
m.meta = map[string]string{"source": m.name, "group": "Lustre"}
|
||||||
defmatches := map[string]map[string]int{
|
|
||||||
"read_bytes": {"lustre_read_bytes": 6, "lustre_read_requests": 1},
|
|
||||||
"write_bytes": {"lustre_write_bytes": 6, "lustre_write_requests": 1},
|
|
||||||
"open": {"lustre_open": 1},
|
|
||||||
"close": {"lustre_close": 1},
|
|
||||||
"setattr": {"lustre_setattr": 1},
|
|
||||||
"getattr": {"lustre_getattr": 1},
|
|
||||||
"statfs": {"lustre_statfs": 1},
|
|
||||||
"inode_permission": {"lustre_inode_permission": 1}}
|
|
||||||
|
|
||||||
// Lustre file system statistics can only be queried by user root
|
// Lustre file system statistics can only be queried by user root
|
||||||
|
// or with password-less sudo
|
||||||
|
if !m.config.Sudo {
|
||||||
user, err := user.Current()
|
user, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.ComponentError(m.name, "Failed to get current user:", err.Error())
|
cclog.ComponentError(m.name, "Failed to get current user:", err.Error())
|
||||||
@@ -119,22 +311,15 @@ func (m *LustreCollector) Init(config json.RawMessage) error {
|
|||||||
cclog.ComponentError(m.name, "Lustre file system statistics can only be queried by user root")
|
cclog.ComponentError(m.name, "Lustre file system statistics can only be queried by user root")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
p, err := exec.LookPath("sudo")
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(m.name, "Cannot find 'sudo'")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
m.sudoCmd = p
|
||||||
|
}
|
||||||
|
|
||||||
m.matches = make(map[string]map[string]int)
|
|
||||||
for lineprefix, names := range defmatches {
|
|
||||||
for metricname, offset := range names {
|
|
||||||
_, skip := stringArrayContains(m.config.ExcludeMetrics, metricname)
|
|
||||||
if skip {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if _, prefixExist := m.matches[lineprefix]; !prefixExist {
|
|
||||||
m.matches[lineprefix] = make(map[string]int)
|
|
||||||
}
|
|
||||||
if _, metricExist := m.matches[lineprefix][metricname]; !metricExist {
|
|
||||||
m.matches[lineprefix][metricname] = offset
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p, err := exec.LookPath(m.config.LCtlCommand)
|
p, err := exec.LookPath(m.config.LCtlCommand)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p, err = exec.LookPath(LCTL_CMD)
|
p, err = exec.LookPath(LCTL_CMD)
|
||||||
@@ -143,82 +328,102 @@ func (m *LustreCollector) Init(config json.RawMessage) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.lctl = p
|
m.lctl = p
|
||||||
if m.config.Sudo {
|
|
||||||
p, err := exec.LookPath("sudo")
|
m.definitions = []LustreMetricDefinition{}
|
||||||
if err != nil {
|
if m.config.SendAbsoluteValues {
|
||||||
m.sudoCmd = p
|
for _, def := range LustreAbsMetrics {
|
||||||
|
if _, skip := stringArrayContains(m.config.ExcludeMetrics, def.name); !skip {
|
||||||
|
m.definitions = append(m.definitions, def)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if m.config.SendDiffValues {
|
||||||
|
for _, def := range LustreDiffMetrics {
|
||||||
|
if _, skip := stringArrayContains(m.config.ExcludeMetrics, def.name); !skip {
|
||||||
|
m.definitions = append(m.definitions, def)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if m.config.SendDerivedValues {
|
||||||
|
for _, def := range LustreDeriveMetrics {
|
||||||
|
if _, skip := stringArrayContains(m.config.ExcludeMetrics, def.name); !skip {
|
||||||
|
m.definitions = append(m.definitions, def)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(m.definitions) == 0 {
|
||||||
|
return errors.New("no metrics to collect")
|
||||||
|
}
|
||||||
|
|
||||||
devices := m.getDevices()
|
devices := m.getDevices()
|
||||||
if len(devices) == 0 {
|
if len(devices) == 0 {
|
||||||
return errors.New("no metrics to collect")
|
return errors.New("no Lustre devices found")
|
||||||
}
|
}
|
||||||
m.stats = make(map[string]map[string]int64)
|
m.stats = make(map[string]map[string]int64)
|
||||||
for _, d := range devices {
|
for _, d := range devices {
|
||||||
m.stats[d] = make(map[string]int64)
|
m.stats[d] = make(map[string]int64)
|
||||||
for _, names := range m.matches {
|
data := m.getDeviceDataCommand(d)
|
||||||
for metricname := range names {
|
for _, def := range m.definitions {
|
||||||
m.stats[d][metricname] = 0
|
x, err := getMetricData(data, def.lineprefix, def.lineoffset)
|
||||||
|
if err == nil {
|
||||||
|
m.stats[d][def.name] = x
|
||||||
|
} else {
|
||||||
|
m.stats[d][def.name] = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m.lastTimestamp = time.Now()
|
||||||
m.init = true
|
m.init = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *LustreCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *LustreCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
now := time.Now()
|
||||||
|
tdiff := now.Sub(m.lastTimestamp)
|
||||||
for device, devData := range m.stats {
|
for device, devData := range m.stats {
|
||||||
stats := m.getDeviceDataCommand(device)
|
data := m.getDeviceDataCommand(device)
|
||||||
processed := []string{}
|
for _, def := range m.definitions {
|
||||||
|
var use_x int64
|
||||||
for _, line := range stats {
|
var err error
|
||||||
lf := strings.Fields(line)
|
var y lp.CCMessage
|
||||||
if len(lf) > 1 {
|
x, err := getMetricData(data, def.lineprefix, def.lineoffset)
|
||||||
if fields, ok := m.matches[lf[0]]; ok {
|
if err == nil {
|
||||||
for name, idx := range fields {
|
use_x = x
|
||||||
x, err := strconv.ParseInt(lf[idx], 0, 64)
|
} else {
|
||||||
if err != nil {
|
use_x = devData[def.name]
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
value := x - devData[name]
|
var value interface{}
|
||||||
devData[name] = x
|
switch def.calc {
|
||||||
if value < 0 {
|
case "none":
|
||||||
|
value = use_x
|
||||||
|
y, err = lp.NewMessage(def.name, m.tags, m.meta, map[string]interface{}{"value": value}, time.Now())
|
||||||
|
case "difference":
|
||||||
|
value = use_x - devData[def.name]
|
||||||
|
if value.(int64) < 0 {
|
||||||
value = 0
|
value = 0
|
||||||
}
|
}
|
||||||
y, err := lp.New(name, m.tags, m.meta, map[string]interface{}{"value": value}, time.Now())
|
y, err = lp.NewMessage(def.name, m.tags, m.meta, map[string]interface{}{"value": value}, time.Now())
|
||||||
|
case "derivative":
|
||||||
|
value = float64(use_x-devData[def.name]) / tdiff.Seconds()
|
||||||
|
if value.(float64) < 0 {
|
||||||
|
value = 0
|
||||||
|
}
|
||||||
|
y, err = lp.NewMessage(def.name, m.tags, m.meta, map[string]interface{}{"value": value}, time.Now())
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
y.AddTag("device", device)
|
y.AddTag("device", device)
|
||||||
if strings.Contains(name, "byte") {
|
if len(def.unit) > 0 {
|
||||||
y.AddMeta("unit", "Byte")
|
y.AddMeta("unit", def.unit)
|
||||||
}
|
|
||||||
output <- y
|
|
||||||
if m.config.SendAllMetrics {
|
|
||||||
processed = append(processed, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if m.config.SendAllMetrics {
|
|
||||||
for name := range devData {
|
|
||||||
if _, done := stringArrayContains(processed, name); !done {
|
|
||||||
y, err := lp.New(name, m.tags, m.meta, map[string]interface{}{"value": 0}, time.Now())
|
|
||||||
if err == nil {
|
|
||||||
y.AddTag("device", device)
|
|
||||||
if strings.Contains(name, "byte") {
|
|
||||||
y.AddMeta("unit", "Byte")
|
|
||||||
}
|
}
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
devData[def.name] = use_x
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
m.lastTimestamp = now
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *LustreCollector) Close() {
|
func (m *LustreCollector) Close() {
|
||||||
|
|||||||
@@ -3,27 +3,44 @@
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
"lustrestat": {
|
"lustrestat": {
|
||||||
"procfiles" : [
|
"lctl_command": "/path/to/lctl",
|
||||||
"/proc/fs/lustre/llite/lnec-XXXXXX/stats"
|
|
||||||
],
|
|
||||||
"exclude_metrics": [
|
"exclude_metrics": [
|
||||||
"setattr",
|
"setattr",
|
||||||
"getattr"
|
"getattr"
|
||||||
]
|
],
|
||||||
|
"send_abs_values" : true,
|
||||||
|
"send_derived_values" : true,
|
||||||
|
"send_diff_values": true,
|
||||||
|
"use_sudo": false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `lustrestat` collector reads from the procfs stat files for Lustre like `/proc/fs/lustre/llite/lnec-XXXXXX/stats`.
|
The `lustrestat` collector uses the `lctl` application with the `get_param` option to get all `llite` metrics (Lustre client). The `llite` metrics are only available for root users. If password-less sudo is configured, you can enable `sudo` in the configuration.
|
||||||
|
|
||||||
Metrics:
|
Metrics:
|
||||||
* `read_bytes`
|
* `lustre_read_bytes` (unit `bytes`)
|
||||||
* `read_requests`
|
* `lustre_read_requests` (unit `requests`)
|
||||||
* `write_bytes`
|
* `lustre_write_bytes` (unit `bytes`)
|
||||||
* `write_requests`
|
* `lustre_write_requests` (unit `requests`)
|
||||||
* `open`
|
* `lustre_open`
|
||||||
* `close`
|
* `lustre_close`
|
||||||
* `getattr`
|
* `lustre_getattr`
|
||||||
* `setattr`
|
* `lustre_setattr`
|
||||||
* `statfs`
|
* `lustre_statfs`
|
||||||
* `inode_permission`
|
* `lustre_inode_permission`
|
||||||
|
* `lustre_read_bw` (if `send_derived_values == true`, unit `bytes/sec`)
|
||||||
|
* `lustre_write_bw` (if `send_derived_values == true`, unit `bytes/sec`)
|
||||||
|
* `lustre_read_requests_rate` (if `send_derived_values == true`, unit `requests/sec`)
|
||||||
|
* `lustre_write_requests_rate` (if `send_derived_values == true`, unit `requests/sec`)
|
||||||
|
* `lustre_read_bytes_diff` (if `send_diff_values == true`, unit `bytes`)
|
||||||
|
* `lustre_read_requests_diff` (if `send_diff_values == true`, unit `requests`)
|
||||||
|
* `lustre_write_bytes_diff` (if `send_diff_values == true`, unit `bytes`)
|
||||||
|
* `lustre_write_requests_diff` (if `send_diff_values == true`, unit `requests`)
|
||||||
|
* `lustre_open_diff` (if `send_diff_values == true`)
|
||||||
|
* `lustre_close_diff` (if `send_diff_values == true`)
|
||||||
|
* `lustre_getattr_diff` (if `send_diff_values == true`)
|
||||||
|
* `lustre_setattr_diff` (if `send_diff_values == true`)
|
||||||
|
* `lustre_statfs_diff` (if `send_diff_values == true`)
|
||||||
|
* `lustre_inode_permission_diff` (if `send_diff_values == true`)
|
||||||
|
|
||||||
|
This collector adds an `device` tag.
|
||||||
@@ -12,8 +12,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MEMSTATFILE = "/proc/meminfo"
|
const MEMSTATFILE = "/proc/meminfo"
|
||||||
@@ -37,10 +37,16 @@ type MemstatCollector struct {
|
|||||||
matches map[string]string
|
matches map[string]string
|
||||||
config MemstatCollectorConfig
|
config MemstatCollectorConfig
|
||||||
nodefiles map[int]MemstatCollectorNode
|
nodefiles map[int]MemstatCollectorNode
|
||||||
|
sendMemUsed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStats(filename string) map[string]float64 {
|
type MemstatStats struct {
|
||||||
stats := make(map[string]float64)
|
value float64
|
||||||
|
unit string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStats(filename string) map[string]MemstatStats {
|
||||||
|
stats := make(map[string]MemstatStats)
|
||||||
file, err := os.Open(filename)
|
file, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.Error(err.Error())
|
cclog.Error(err.Error())
|
||||||
@@ -54,12 +60,19 @@ func getStats(filename string) map[string]float64 {
|
|||||||
if len(linefields) == 3 {
|
if len(linefields) == 3 {
|
||||||
v, err := strconv.ParseFloat(linefields[1], 64)
|
v, err := strconv.ParseFloat(linefields[1], 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
stats[strings.Trim(linefields[0], ":")] = v
|
stats[strings.Trim(linefields[0], ":")] = MemstatStats{
|
||||||
|
value: v,
|
||||||
|
unit: linefields[2],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if len(linefields) == 5 {
|
} else if len(linefields) == 5 {
|
||||||
v, err := strconv.ParseFloat(linefields[3], 64)
|
v, err := strconv.ParseFloat(linefields[3], 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
stats[strings.Trim(linefields[0], ":")] = v
|
cclog.ComponentDebug("getStats", strings.Trim(linefields[2], ":"), v, linefields[4])
|
||||||
|
stats[strings.Trim(linefields[2], ":")] = MemstatStats{
|
||||||
|
value: v,
|
||||||
|
unit: linefields[4],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,6 +82,7 @@ func getStats(filename string) map[string]float64 {
|
|||||||
func (m *MemstatCollector) Init(config json.RawMessage) error {
|
func (m *MemstatCollector) Init(config json.RawMessage) error {
|
||||||
var err error
|
var err error
|
||||||
m.name = "MemstatCollector"
|
m.name = "MemstatCollector"
|
||||||
|
m.parallel = true
|
||||||
m.config.NodeStats = true
|
m.config.NodeStats = true
|
||||||
m.config.NumaStats = false
|
m.config.NumaStats = false
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
@@ -77,7 +91,7 @@ func (m *MemstatCollector) Init(config json.RawMessage) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.meta = map[string]string{"source": m.name, "group": "Memory", "unit": "kByte"}
|
m.meta = map[string]string{"source": m.name, "group": "Memory"}
|
||||||
m.stats = make(map[string]int64)
|
m.stats = make(map[string]int64)
|
||||||
m.matches = make(map[string]string)
|
m.matches = make(map[string]string)
|
||||||
m.tags = map[string]string{"type": "node"}
|
m.tags = map[string]string{"type": "node"}
|
||||||
@@ -99,6 +113,10 @@ func (m *MemstatCollector) Init(config json.RawMessage) error {
|
|||||||
m.matches[k] = v
|
m.matches[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m.sendMemUsed = false
|
||||||
|
if _, skip := stringArrayContains(m.config.ExcludeMetrics, "mem_used"); !skip {
|
||||||
|
m.sendMemUsed = true
|
||||||
|
}
|
||||||
if len(m.matches) == 0 {
|
if len(m.matches) == 0 {
|
||||||
return errors.New("no metrics to collect")
|
return errors.New("no metrics to collect")
|
||||||
}
|
}
|
||||||
@@ -141,36 +159,64 @@ func (m *MemstatCollector) Init(config json.RawMessage) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MemstatCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *MemstatCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sendStats := func(stats map[string]float64, tags map[string]string) {
|
sendStats := func(stats map[string]MemstatStats, tags map[string]string) {
|
||||||
for match, name := range m.matches {
|
for match, name := range m.matches {
|
||||||
var value float64 = 0
|
var value float64 = 0
|
||||||
|
var unit string = ""
|
||||||
if v, ok := stats[match]; ok {
|
if v, ok := stats[match]; ok {
|
||||||
value = v
|
value = v.value
|
||||||
|
if len(v.unit) > 0 {
|
||||||
|
unit = v.unit
|
||||||
}
|
}
|
||||||
y, err := lp.New(name, tags, m.meta, map[string]interface{}{"value": value}, time.Now())
|
}
|
||||||
|
|
||||||
|
y, err := lp.NewMessage(name, tags, m.meta, map[string]interface{}{"value": value}, time.Now())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
if len(unit) > 0 {
|
||||||
|
y.AddMeta("unit", unit)
|
||||||
|
}
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, skip := stringArrayContains(m.config.ExcludeMetrics, "mem_used"); !skip {
|
if m.sendMemUsed {
|
||||||
|
memUsed := 0.0
|
||||||
|
unit := ""
|
||||||
|
if totalVal, total := stats["MemTotal"]; total {
|
||||||
if freeVal, free := stats["MemFree"]; free {
|
if freeVal, free := stats["MemFree"]; free {
|
||||||
|
memUsed = totalVal.value - freeVal.value
|
||||||
|
if len(totalVal.unit) > 0 {
|
||||||
|
unit = totalVal.unit
|
||||||
|
} else if len(freeVal.unit) > 0 {
|
||||||
|
unit = freeVal.unit
|
||||||
|
}
|
||||||
if bufVal, buffers := stats["Buffers"]; buffers {
|
if bufVal, buffers := stats["Buffers"]; buffers {
|
||||||
|
memUsed -= bufVal.value
|
||||||
|
if len(bufVal.unit) > 0 && len(unit) == 0 {
|
||||||
|
unit = bufVal.unit
|
||||||
|
}
|
||||||
if cacheVal, cached := stats["Cached"]; cached {
|
if cacheVal, cached := stats["Cached"]; cached {
|
||||||
memUsed := stats["MemTotal"] - (freeVal + bufVal + cacheVal)
|
memUsed -= cacheVal.value
|
||||||
y, err := lp.New("mem_used", tags, m.meta, map[string]interface{}{"value": memUsed}, time.Now())
|
if len(cacheVal.unit) > 0 && len(unit) == 0 {
|
||||||
|
unit = cacheVal.unit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
y, err := lp.NewMessage("mem_used", tags, m.meta, map[string]interface{}{"value": memUsed}, time.Now())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
if len(unit) > 0 {
|
||||||
|
y.AddMeta("unit", unit)
|
||||||
|
}
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if m.config.NodeStats {
|
if m.config.NodeStats {
|
||||||
nodestats := getStats(MEMSTATFILE)
|
nodestats := getStats(MEMSTATFILE)
|
||||||
|
|||||||
@@ -3,26 +3,24 @@ package collectors
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MetricCollector interface {
|
type MetricCollector interface {
|
||||||
Name() string // Name of the metric collector
|
Name() string // Name of the metric collector
|
||||||
Init(config json.RawMessage) error // Initialize metric collector
|
Init(config json.RawMessage) error // Initialize metric collector
|
||||||
Initialized() bool // Is metric collector initialized?
|
Initialized() bool // Is metric collector initialized?
|
||||||
Read(duration time.Duration, output chan lp.CCMetric) // Read metrics from metric collector
|
Parallel() bool
|
||||||
|
Read(duration time.Duration, output chan lp.CCMessage) // Read metrics from metric collector
|
||||||
Close() // Close / finish metric collector
|
Close() // Close / finish metric collector
|
||||||
}
|
}
|
||||||
|
|
||||||
type metricCollector struct {
|
type metricCollector struct {
|
||||||
name string // name of the metric
|
name string // name of the metric
|
||||||
init bool // is metric collector initialized?
|
init bool // is metric collector initialized?
|
||||||
|
parallel bool // can the metric collector be executed in parallel with others
|
||||||
meta map[string]string // static meta data tags
|
meta map[string]string // static meta data tags
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,6 +29,11 @@ func (c *metricCollector) Name() string {
|
|||||||
return c.name
|
return c.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Name returns the name of the metric collector
|
||||||
|
func (c *metricCollector) Parallel() bool {
|
||||||
|
return c.parallel
|
||||||
|
}
|
||||||
|
|
||||||
// Setup is for future use
|
// Setup is for future use
|
||||||
func (c *metricCollector) setup() error {
|
func (c *metricCollector) setup() error {
|
||||||
return nil
|
return nil
|
||||||
@@ -65,58 +68,6 @@ func stringArrayContains(array []string, str string) (int, bool) {
|
|||||||
return -1, false
|
return -1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// SocketList returns the list of physical sockets as read from /proc/cpuinfo
|
|
||||||
func SocketList() []int {
|
|
||||||
buffer, err := ioutil.ReadFile("/proc/cpuinfo")
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
ll := strings.Split(string(buffer), "\n")
|
|
||||||
var packs []int
|
|
||||||
for _, line := range ll {
|
|
||||||
if strings.HasPrefix(line, "physical id") {
|
|
||||||
lv := strings.Fields(line)
|
|
||||||
id, err := strconv.ParseInt(lv[3], 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return packs
|
|
||||||
}
|
|
||||||
_, found := intArrayContains(packs, int(id))
|
|
||||||
if !found {
|
|
||||||
packs = append(packs, int(id))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return packs
|
|
||||||
}
|
|
||||||
|
|
||||||
// CpuList returns the list of physical CPUs (in contrast to logical CPUs) as read from /proc/cpuinfo
|
|
||||||
func CpuList() []int {
|
|
||||||
buffer, err := ioutil.ReadFile("/proc/cpuinfo")
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
ll := strings.Split(string(buffer), "\n")
|
|
||||||
var cpulist []int
|
|
||||||
for _, line := range ll {
|
|
||||||
if strings.HasPrefix(line, "processor") {
|
|
||||||
lv := strings.Fields(line)
|
|
||||||
id, err := strconv.ParseInt(lv[2], 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return cpulist
|
|
||||||
}
|
|
||||||
_, found := intArrayContains(cpulist, int(id))
|
|
||||||
if !found {
|
|
||||||
cpulist = append(cpulist, int(id))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cpulist
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveFromStringList removes the string r from the array of strings s
|
// RemoveFromStringList removes the string r from the array of strings s
|
||||||
// If r is not contained in the array an error is returned
|
// If r is not contained in the array an error is returned
|
||||||
func RemoveFromStringList(s []string, r string) ([]string, error) {
|
func RemoveFromStringList(s []string, r string) ([]string, error) {
|
||||||
@@ -125,5 +76,5 @@ func RemoveFromStringList(s []string, r string) ([]string, error) {
|
|||||||
return append(s[:i], s[i+1:]...), nil
|
return append(s[:i], s[i+1:]...), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s, fmt.Errorf("No such string in list")
|
return s, fmt.Errorf("no such string in list")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,42 +9,66 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
const NETSTATFILE = `/proc/net/dev`
|
const NETSTATFILE = "/proc/net/dev"
|
||||||
|
|
||||||
type NetstatCollectorConfig struct {
|
type NetstatCollectorConfig struct {
|
||||||
IncludeDevices []string `json:"include_devices"`
|
IncludeDevices []string `json:"include_devices"`
|
||||||
|
SendAbsoluteValues bool `json:"send_abs_values"`
|
||||||
|
SendDerivedValues bool `json:"send_derived_values"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NetstatCollectorMetric struct {
|
type NetstatCollectorMetric struct {
|
||||||
|
name string
|
||||||
index int
|
index int
|
||||||
lastValue float64
|
tags map[string]string
|
||||||
|
meta map[string]string
|
||||||
|
meta_rates map[string]string
|
||||||
|
lastValue int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type NetstatCollector struct {
|
type NetstatCollector struct {
|
||||||
metricCollector
|
metricCollector
|
||||||
config NetstatCollectorConfig
|
config NetstatCollectorConfig
|
||||||
matches map[string]map[string]NetstatCollectorMetric
|
matches map[string][]NetstatCollectorMetric
|
||||||
devtags map[string]map[string]string
|
|
||||||
lastTimestamp time.Time
|
lastTimestamp time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *NetstatCollector) Init(config json.RawMessage) error {
|
func (m *NetstatCollector) Init(config json.RawMessage) error {
|
||||||
m.name = "NetstatCollector"
|
m.name = "NetstatCollector"
|
||||||
|
m.parallel = true
|
||||||
m.setup()
|
m.setup()
|
||||||
m.lastTimestamp = time.Now()
|
m.lastTimestamp = time.Now()
|
||||||
m.meta = map[string]string{"source": m.name, "group": "Network"}
|
|
||||||
m.devtags = make(map[string]map[string]string)
|
const (
|
||||||
nameIndexMap := map[string]int{
|
fieldInterface = iota
|
||||||
"net_bytes_in": 1,
|
fieldReceiveBytes
|
||||||
"net_pkts_in": 2,
|
fieldReceivePackets
|
||||||
"net_bytes_out": 9,
|
fieldReceiveErrs
|
||||||
"net_pkts_out": 10,
|
fieldReceiveDrop
|
||||||
}
|
fieldReceiveFifo
|
||||||
m.matches = make(map[string]map[string]NetstatCollectorMetric)
|
fieldReceiveFrame
|
||||||
|
fieldReceiveCompressed
|
||||||
|
fieldReceiveMulticast
|
||||||
|
fieldTransmitBytes
|
||||||
|
fieldTransmitPackets
|
||||||
|
fieldTransmitErrs
|
||||||
|
fieldTransmitDrop
|
||||||
|
fieldTransmitFifo
|
||||||
|
fieldTransmitColls
|
||||||
|
fieldTransmitCarrier
|
||||||
|
fieldTransmitCompressed
|
||||||
|
)
|
||||||
|
|
||||||
|
m.matches = make(map[string][]NetstatCollectorMetric)
|
||||||
|
|
||||||
|
// Set default configuration,
|
||||||
|
m.config.SendAbsoluteValues = true
|
||||||
|
m.config.SendDerivedValues = false
|
||||||
|
// Read configuration file, allow overwriting default config
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err := json.Unmarshal(config, &m.config)
|
err := json.Unmarshal(config, &m.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -52,7 +76,9 @@ func (m *NetstatCollector) Init(config json.RawMessage) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file, err := os.Open(string(NETSTATFILE))
|
|
||||||
|
// Check access to net statistic file
|
||||||
|
file, err := os.Open(NETSTATFILE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.ComponentError(m.name, err.Error())
|
cclog.ComponentError(m.name, err.Error())
|
||||||
return err
|
return err
|
||||||
@@ -62,77 +88,131 @@ func (m *NetstatCollector) Init(config json.RawMessage) error {
|
|||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
l := scanner.Text()
|
l := scanner.Text()
|
||||||
|
|
||||||
|
// Skip lines with no net device entry
|
||||||
if !strings.Contains(l, ":") {
|
if !strings.Contains(l, ":") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Split line into fields
|
||||||
f := strings.Fields(l)
|
f := strings.Fields(l)
|
||||||
|
|
||||||
|
// Get net device entry
|
||||||
dev := strings.Trim(f[0], ": ")
|
dev := strings.Trim(f[0], ": ")
|
||||||
|
|
||||||
|
// Check if device is a included device
|
||||||
if _, ok := stringArrayContains(m.config.IncludeDevices, dev); ok {
|
if _, ok := stringArrayContains(m.config.IncludeDevices, dev); ok {
|
||||||
m.matches[dev] = make(map[string]NetstatCollectorMetric)
|
tags := map[string]string{"stype": "network", "stype-id": dev, "type": "node"}
|
||||||
for name, idx := range nameIndexMap {
|
meta_unit_byte := map[string]string{"source": m.name, "group": "Network", "unit": "bytes"}
|
||||||
m.matches[dev][name] = NetstatCollectorMetric{
|
meta_unit_byte_per_sec := map[string]string{"source": m.name, "group": "Network", "unit": "bytes/sec"}
|
||||||
index: idx,
|
meta_unit_pkts := map[string]string{"source": m.name, "group": "Network", "unit": "packets"}
|
||||||
lastValue: 0,
|
meta_unit_pkts_per_sec := map[string]string{"source": m.name, "group": "Network", "unit": "packets/sec"}
|
||||||
|
|
||||||
|
m.matches[dev] = []NetstatCollectorMetric{
|
||||||
|
{
|
||||||
|
name: "net_bytes_in",
|
||||||
|
index: fieldReceiveBytes,
|
||||||
|
lastValue: -1,
|
||||||
|
tags: tags,
|
||||||
|
meta: meta_unit_byte,
|
||||||
|
meta_rates: meta_unit_byte_per_sec,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "net_pkts_in",
|
||||||
|
index: fieldReceivePackets,
|
||||||
|
lastValue: -1,
|
||||||
|
tags: tags,
|
||||||
|
meta: meta_unit_pkts,
|
||||||
|
meta_rates: meta_unit_pkts_per_sec,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "net_bytes_out",
|
||||||
|
index: fieldTransmitBytes,
|
||||||
|
lastValue: -1,
|
||||||
|
tags: tags,
|
||||||
|
meta: meta_unit_byte,
|
||||||
|
meta_rates: meta_unit_byte_per_sec,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "net_pkts_out",
|
||||||
|
index: fieldTransmitPackets,
|
||||||
|
lastValue: -1,
|
||||||
|
tags: tags,
|
||||||
|
meta: meta_unit_pkts,
|
||||||
|
meta_rates: meta_unit_pkts_per_sec,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.devtags[dev] = map[string]string{"device": dev, "type": "node"}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if len(m.devtags) == 0 {
|
if len(m.matches) == 0 {
|
||||||
return errors.New("no devices to collector metrics found")
|
return errors.New("no devices to collector metrics found")
|
||||||
}
|
}
|
||||||
m.init = true
|
m.init = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *NetstatCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *NetstatCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Current time stamp
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
// time difference to last time stamp
|
||||||
|
timeDiff := now.Sub(m.lastTimestamp).Seconds()
|
||||||
|
// Save current timestamp
|
||||||
|
m.lastTimestamp = now
|
||||||
|
|
||||||
file, err := os.Open(string(NETSTATFILE))
|
file, err := os.Open(string(NETSTATFILE))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.ComponentError(m.name, err.Error())
|
cclog.ComponentError(m.name, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
tdiff := now.Sub(m.lastTimestamp)
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
l := scanner.Text()
|
l := scanner.Text()
|
||||||
|
|
||||||
|
// Skip lines with no net device entry
|
||||||
if !strings.Contains(l, ":") {
|
if !strings.Contains(l, ":") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Split line into fields
|
||||||
f := strings.Fields(l)
|
f := strings.Fields(l)
|
||||||
|
|
||||||
|
// Get net device entry
|
||||||
dev := strings.Trim(f[0], ":")
|
dev := strings.Trim(f[0], ":")
|
||||||
|
|
||||||
|
// Check if device is a included device
|
||||||
if devmetrics, ok := m.matches[dev]; ok {
|
if devmetrics, ok := m.matches[dev]; ok {
|
||||||
for name, data := range devmetrics {
|
for i := range devmetrics {
|
||||||
v, err := strconv.ParseFloat(f[data.index], 64)
|
metric := &devmetrics[i]
|
||||||
if err == nil {
|
|
||||||
vdiff := v - data.lastValue
|
// Read value
|
||||||
value := vdiff / tdiff.Seconds()
|
v, err := strconv.ParseInt(f[metric.index], 10, 64)
|
||||||
if data.lastValue == 0 {
|
if err != nil {
|
||||||
value = 0
|
continue
|
||||||
}
|
|
||||||
data.lastValue = v
|
|
||||||
y, err := lp.New(name, m.devtags[dev], m.meta, map[string]interface{}{"value": value}, now)
|
|
||||||
if err == nil {
|
|
||||||
switch {
|
|
||||||
case strings.Contains(name, "byte"):
|
|
||||||
y.AddMeta("unit", "bytes/sec")
|
|
||||||
case strings.Contains(name, "pkt"):
|
|
||||||
y.AddMeta("unit", "packets/sec")
|
|
||||||
}
|
}
|
||||||
|
if m.config.SendAbsoluteValues {
|
||||||
|
if y, err := lp.NewMessage(metric.name, metric.tags, metric.meta, map[string]interface{}{"value": v}, now); err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
devmetrics[name] = data
|
}
|
||||||
|
if m.config.SendDerivedValues {
|
||||||
|
if metric.lastValue >= 0 {
|
||||||
|
rate := float64(v-metric.lastValue) / timeDiff
|
||||||
|
if y, err := lp.NewMessage(metric.name+"_bw", metric.tags, metric.meta_rates, map[string]interface{}{"value": rate}, now); err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
metric.lastValue = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.lastTimestamp = time.Now()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *NetstatCollector) Close() {
|
func (m *NetstatCollector) Close() {
|
||||||
|
|||||||
@@ -5,17 +5,23 @@
|
|||||||
"netstat": {
|
"netstat": {
|
||||||
"include_devices": [
|
"include_devices": [
|
||||||
"eth0"
|
"eth0"
|
||||||
]
|
],
|
||||||
|
"send_abs_values" : true,
|
||||||
|
"send_derived_values" : true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `netstat` collector reads data from `/proc/net/dev` and outputs a handful **node** metrics. With the `include_devices` list you can specify which network devices should be measured. **Note**: Most other collectors use an _exclude_ list instead of an include list.
|
The `netstat` collector reads data from `/proc/net/dev` and outputs a handful **node** metrics. With the `include_devices` list you can specify which network devices should be measured. **Note**: Most other collectors use an _exclude_ list instead of an include list.
|
||||||
|
|
||||||
Metrics:
|
Metrics:
|
||||||
* `net_bytes_in` (`unit=bytes/sec`)
|
* `net_bytes_in` (`unit=bytes`)
|
||||||
* `net_bytes_out` (`unit=bytes/sec`)
|
* `net_bytes_out` (`unit=bytes`)
|
||||||
* `net_pkts_in` (`unit=packets/sec`)
|
* `net_pkts_in` (`unit=packets`)
|
||||||
* `net_pkts_out` (`unit=packets/sec`)
|
* `net_pkts_out` (`unit=packets`)
|
||||||
|
* `net_bytes_in_bw` (`unit=bytes/sec` if `send_derived_values == true`)
|
||||||
|
* `net_bytes_out_bw` (`unit=bytes/sec` if `send_derived_values == true`)
|
||||||
|
* `net_pkts_in_bw` (`unit=packets/sec` if `send_derived_values == true`)
|
||||||
|
* `net_pkts_out_bw` (`unit=packets/sec` if `send_derived_values == true`)
|
||||||
|
|
||||||
The device name is added as tag `device`.
|
The device name is added as tag `stype=network,stype-id=<device>`.
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
// First part contains the code for the general NfsCollector.
|
// First part contains the code for the general NfsCollector.
|
||||||
@@ -36,7 +36,7 @@ type nfsCollector struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *nfsCollector) initStats() error {
|
func (m *nfsCollector) initStats() error {
|
||||||
cmd := exec.Command(m.config.Nfsstats, `-l`)
|
cmd := exec.Command(m.config.Nfsstats, `-l`, `--all`)
|
||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
buffer, err := cmd.Output()
|
buffer, err := cmd.Output()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -52,7 +52,7 @@ func (m *nfsCollector) initStats() error {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
x := m.data[name]
|
x := m.data[name]
|
||||||
x.current = value
|
x.current = value
|
||||||
x.last = 0
|
x.last = value
|
||||||
m.data[name] = x
|
m.data[name] = x
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ func (m *nfsCollector) initStats() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *nfsCollector) updateStats() error {
|
func (m *nfsCollector) updateStats() error {
|
||||||
cmd := exec.Command(m.config.Nfsstats, `-l`)
|
cmd := exec.Command(m.config.Nfsstats, `-l`, `--all`)
|
||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
buffer, err := cmd.Output()
|
buffer, err := cmd.Output()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -114,10 +114,11 @@ func (m *nfsCollector) MainInit(config json.RawMessage) error {
|
|||||||
m.data = make(map[string]NfsCollectorData)
|
m.data = make(map[string]NfsCollectorData)
|
||||||
m.initStats()
|
m.initStats()
|
||||||
m.init = true
|
m.init = true
|
||||||
|
m.parallel = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *nfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *nfsCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -139,7 +140,7 @@ func (m *nfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
value := data.current - data.last
|
value := data.current - data.last
|
||||||
y, err := lp.New(fmt.Sprintf("%s_%s", prefix, name), m.tags, m.meta, map[string]interface{}{"value": value}, timestamp)
|
y, err := lp.NewMessage(fmt.Sprintf("%s_%s", prefix, name), m.tags, m.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
y.AddMeta("version", m.version)
|
y.AddMeta("version", m.version)
|
||||||
output <- y
|
output <- y
|
||||||
|
|||||||
166
collectors/nfsiostatMetric.go
Normal file
166
collectors/nfsiostatMetric.go
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
package collectors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
)
|
||||||
|
|
||||||
|
// These are the fields we read from the JSON configuration
|
||||||
|
type NfsIOStatCollectorConfig struct {
|
||||||
|
ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
|
||||||
|
ExcludeFilesystem []string `json:"exclude_filesystem,omitempty"`
|
||||||
|
UseServerAddressAsSType bool `json:"use_server_as_stype,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// This contains all variables we need during execution and the variables
|
||||||
|
// defined by metricCollector (name, init, ...)
|
||||||
|
type NfsIOStatCollector struct {
|
||||||
|
metricCollector
|
||||||
|
config NfsIOStatCollectorConfig // the configuration structure
|
||||||
|
meta map[string]string // default meta information
|
||||||
|
tags map[string]string // default tags
|
||||||
|
data map[string]map[string]int64 // data storage for difference calculation
|
||||||
|
key string // which device info should be used as subtype ID? 'server' or 'mntpoint', see NfsIOStatCollectorConfig.UseServerAddressAsSType
|
||||||
|
}
|
||||||
|
|
||||||
|
var deviceRegex = regexp.MustCompile(`device (?P<server>[^ ]+) mounted on (?P<mntpoint>[^ ]+) with fstype nfs(?P<version>\d*) statvers=[\d\.]+`)
|
||||||
|
var bytesRegex = regexp.MustCompile(`\s+bytes:\s+(?P<nread>[^ ]+) (?P<nwrite>[^ ]+) (?P<dread>[^ ]+) (?P<dwrite>[^ ]+) (?P<nfsread>[^ ]+) (?P<nfswrite>[^ ]+) (?P<pageread>[^ ]+) (?P<pagewrite>[^ ]+)`)
|
||||||
|
|
||||||
|
func resolve_regex_fields(s string, regex *regexp.Regexp) map[string]string {
|
||||||
|
fields := make(map[string]string)
|
||||||
|
groups := regex.SubexpNames()
|
||||||
|
for _, match := range regex.FindAllStringSubmatch(s, -1) {
|
||||||
|
for groupIdx, group := range match {
|
||||||
|
if len(groups[groupIdx]) > 0 {
|
||||||
|
fields[groups[groupIdx]] = group
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fields
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *NfsIOStatCollector) readNfsiostats() map[string]map[string]int64 {
|
||||||
|
data := make(map[string]map[string]int64)
|
||||||
|
filename := "/proc/self/mountstats"
|
||||||
|
stats, err := os.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := strings.Split(string(stats), "\n")
|
||||||
|
var current map[string]string = nil
|
||||||
|
for _, l := range lines {
|
||||||
|
// Is this a device line with mount point, remote target and NFS version?
|
||||||
|
dev := resolve_regex_fields(l, deviceRegex)
|
||||||
|
if len(dev) > 0 {
|
||||||
|
if _, ok := stringArrayContains(m.config.ExcludeFilesystem, dev[m.key]); !ok {
|
||||||
|
current = dev
|
||||||
|
if len(current["version"]) == 0 {
|
||||||
|
current["version"] = "3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(current) > 0 {
|
||||||
|
// Byte line parsing (if found the device for it)
|
||||||
|
bytes := resolve_regex_fields(l, bytesRegex)
|
||||||
|
if len(bytes) > 0 {
|
||||||
|
data[current[m.key]] = make(map[string]int64)
|
||||||
|
for name, sval := range bytes {
|
||||||
|
if _, ok := stringArrayContains(m.config.ExcludeMetrics, name); !ok {
|
||||||
|
val, err := strconv.ParseInt(sval, 10, 64)
|
||||||
|
if err == nil {
|
||||||
|
data[current[m.key]][name] = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
current = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *NfsIOStatCollector) Init(config json.RawMessage) error {
|
||||||
|
var err error = nil
|
||||||
|
m.name = "NfsIOStatCollector"
|
||||||
|
m.setup()
|
||||||
|
m.parallel = true
|
||||||
|
m.meta = map[string]string{"source": m.name, "group": "NFS", "unit": "bytes"}
|
||||||
|
m.tags = map[string]string{"type": "node"}
|
||||||
|
m.config.UseServerAddressAsSType = false
|
||||||
|
if len(config) > 0 {
|
||||||
|
err = json.Unmarshal(config, &m.config)
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(m.name, "Error reading config:", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.key = "mntpoint"
|
||||||
|
if m.config.UseServerAddressAsSType {
|
||||||
|
m.key = "server"
|
||||||
|
}
|
||||||
|
m.data = m.readNfsiostats()
|
||||||
|
m.init = true
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *NfsIOStatCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
|
timestamp := time.Now()
|
||||||
|
|
||||||
|
// Get the current values for all mountpoints
|
||||||
|
newdata := m.readNfsiostats()
|
||||||
|
|
||||||
|
for mntpoint, values := range newdata {
|
||||||
|
// Was the mount point already present in the last iteration
|
||||||
|
if old, ok := m.data[mntpoint]; ok {
|
||||||
|
// Calculate the difference of old and new values
|
||||||
|
for i := range values {
|
||||||
|
x := values[i] - old[i]
|
||||||
|
y, err := lp.NewMessage(fmt.Sprintf("nfsio_%s", i), m.tags, m.meta, map[string]interface{}{"value": x}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
if strings.HasPrefix(i, "page") {
|
||||||
|
y.AddMeta("unit", "4K_Pages")
|
||||||
|
}
|
||||||
|
y.AddTag("stype", "filesystem")
|
||||||
|
y.AddTag("stype-id", mntpoint)
|
||||||
|
// Send it to output channel
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
// Update old to the new value for the next iteration
|
||||||
|
old[i] = values[i]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// First time we see this mount point, store all values
|
||||||
|
m.data[mntpoint] = values
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Reset entries that do not exist anymore
|
||||||
|
for mntpoint := range m.data {
|
||||||
|
found := false
|
||||||
|
for new := range newdata {
|
||||||
|
if new == mntpoint {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
m.data[mntpoint] = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *NfsIOStatCollector) Close() {
|
||||||
|
// Unset flag
|
||||||
|
m.init = false
|
||||||
|
}
|
||||||
27
collectors/nfsiostatMetric.md
Normal file
27
collectors/nfsiostatMetric.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
## `nfsiostat` collector
|
||||||
|
|
||||||
|
```json
|
||||||
|
"nfsiostat": {
|
||||||
|
"exclude_metrics": [
|
||||||
|
"nfsio_oread"
|
||||||
|
],
|
||||||
|
"exclude_filesystems" : [
|
||||||
|
"/mnt",
|
||||||
|
],
|
||||||
|
"use_server_as_stype": false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `nfsiostat` collector reads data from `/proc/self/mountstats` and outputs a handful **node** metrics for each NFS filesystem. If a metric or filesystem is not required, it can be excluded from forwarding it to the sink.
|
||||||
|
|
||||||
|
Metrics:
|
||||||
|
* `nfsio_nread`: Bytes transferred by normal `read()` calls
|
||||||
|
* `nfsio_nwrite`: Bytes transferred by normal `write()` calls
|
||||||
|
* `nfsio_oread`: Bytes transferred by `read()` calls with `O_DIRECT`
|
||||||
|
* `nfsio_owrite`: Bytes transferred by `write()` calls with `O_DIRECT`
|
||||||
|
* `nfsio_pageread`: Pages transferred by `read()` calls
|
||||||
|
* `nfsio_pagewrite`: Pages transferred by `write()` calls
|
||||||
|
* `nfsio_nfsread`: Bytes transferred for reading from the server
|
||||||
|
* `nfsio_nfswrite`: Pages transferred by writing to the server
|
||||||
|
|
||||||
|
The `nfsiostat` collector adds the mountpoint to the tags as `stype=filesystem,stype-id=<mountpoint>`. If the server address should be used instead of the mountpoint, use the `use_server_as_stype` config setting.
|
||||||
@@ -10,33 +10,42 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
//
|
// Non-Uniform Memory Access (NUMA) policy hit/miss statistics
|
||||||
// Numa policy hit/miss statistics
|
|
||||||
//
|
//
|
||||||
// numa_hit:
|
// numa_hit:
|
||||||
|
//
|
||||||
// A process wanted to allocate memory from this node, and succeeded.
|
// A process wanted to allocate memory from this node, and succeeded.
|
||||||
|
//
|
||||||
// numa_miss:
|
// numa_miss:
|
||||||
|
//
|
||||||
// A process wanted to allocate memory from another node,
|
// A process wanted to allocate memory from another node,
|
||||||
// but ended up with memory from this node.
|
// but ended up with memory from this node.
|
||||||
|
//
|
||||||
// numa_foreign:
|
// numa_foreign:
|
||||||
|
//
|
||||||
// A process wanted to allocate on this node,
|
// A process wanted to allocate on this node,
|
||||||
// but ended up with memory from another node.
|
// but ended up with memory from another node.
|
||||||
|
//
|
||||||
// local_node:
|
// local_node:
|
||||||
|
//
|
||||||
// A process ran on this node's CPU,
|
// A process ran on this node's CPU,
|
||||||
// and got memory from this node.
|
// and got memory from this node.
|
||||||
|
//
|
||||||
// other_node:
|
// other_node:
|
||||||
|
//
|
||||||
// A process ran on a different node's CPU
|
// A process ran on a different node's CPU
|
||||||
// and got memory from this node.
|
// and got memory from this node.
|
||||||
|
//
|
||||||
// interleave_hit:
|
// interleave_hit:
|
||||||
|
//
|
||||||
// Interleaving wanted to allocate from this node
|
// Interleaving wanted to allocate from this node
|
||||||
// and succeeded.
|
// and succeeded.
|
||||||
//
|
//
|
||||||
// See: https://www.kernel.org/doc/html/latest/admin-guide/numastat.html
|
// See: https://www.kernel.org/doc/html/latest/admin-guide/numastat.html
|
||||||
//
|
|
||||||
type NUMAStatsCollectorTopolgy struct {
|
type NUMAStatsCollectorTopolgy struct {
|
||||||
file string
|
file string
|
||||||
tagSet map[string]string
|
tagSet map[string]string
|
||||||
@@ -54,6 +63,7 @@ func (m *NUMAStatsCollector) Init(config json.RawMessage) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.name = "NUMAStatsCollector"
|
m.name = "NUMAStatsCollector"
|
||||||
|
m.parallel = true
|
||||||
m.setup()
|
m.setup()
|
||||||
m.meta = map[string]string{
|
m.meta = map[string]string{
|
||||||
"source": m.name,
|
"source": m.name,
|
||||||
@@ -81,11 +91,13 @@ func (m *NUMAStatsCollector) Init(config json.RawMessage) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialized
|
||||||
|
cclog.ComponentDebug(m.name, "initialized", len(m.topology), "NUMA domains")
|
||||||
m.init = true
|
m.init = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *NUMAStatsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *NUMAStatsCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -118,7 +130,7 @@ func (m *NUMAStatsCollector) Read(interval time.Duration, output chan lp.CCMetri
|
|||||||
fmt.Sprintf("Read(): Failed to convert %s='%s' to int64: %v", key, split[1], err))
|
fmt.Sprintf("Read(): Failed to convert %s='%s' to int64: %v", key, split[1], err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
y, err := lp.New(
|
y, err := lp.NewMessage(
|
||||||
"numastats_"+key,
|
"numastats_"+key,
|
||||||
t.tagSet,
|
t.tagSet,
|
||||||
m.meta,
|
m.meta,
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
|
|
||||||
## `numastat` collector
|
## `numastat` collector
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"numastat": {}
|
"numastats": {}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `numastat` collector reads data from `/sys/devices/system/node/node*/numastat` and outputs a handful **memoryDomain** metrics. See: https://www.kernel.org/doc/html/latest/admin-guide/numastat.html
|
The `numastat` collector reads data from `/sys/devices/system/node/node*/numastat` and outputs a handful **memoryDomain** metrics. See: <https://www.kernel.org/doc/html/latest/admin-guide/numastat.html>
|
||||||
|
|
||||||
Metrics:
|
Metrics:
|
||||||
|
|
||||||
* `numastats_numa_hit`: A process wanted to allocate memory from this node, and succeeded.
|
* `numastats_numa_hit`: A process wanted to allocate memory from this node, and succeeded.
|
||||||
* `numastats_numa_miss`: A process wanted to allocate memory from another node, but ended up with memory from this node.
|
* `numastats_numa_miss`: A process wanted to allocate memory from another node, but ended up with memory from this node.
|
||||||
* `numastats_numa_foreign`: A process wanted to allocate on this node, but ended up with memory from another node.
|
* `numastats_numa_foreign`: A process wanted to allocate on this node, but ended up with memory from another node.
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -3,38 +3,74 @@
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
"nvidia": {
|
"nvidia": {
|
||||||
"exclude_devices" : [
|
"exclude_devices": [
|
||||||
"0","1"
|
"0","1", "0000000:ff:01.0"
|
||||||
],
|
],
|
||||||
"exclude_metrics": [
|
"exclude_metrics": [
|
||||||
"nv_fb_memory",
|
"nv_fb_mem_used",
|
||||||
"nv_fan"
|
"nv_fan"
|
||||||
]
|
],
|
||||||
|
"process_mig_devices": false,
|
||||||
|
"use_pci_info_as_type_id": true,
|
||||||
|
"add_pci_info_tag": false,
|
||||||
|
"add_uuid_meta": false,
|
||||||
|
"add_board_number_meta": false,
|
||||||
|
"add_serial_meta": false,
|
||||||
|
"use_uuid_for_mig_device": false,
|
||||||
|
"use_slice_for_mig_device": false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The `nvidia` collector can be configured to leave out specific devices with the `exclude_devices` option. It takes IDs as supplied to the NVML with `nvmlDeviceGetHandleByIndex()` or the PCI address in NVML format (`%08X:%02X:%02X.0`). Metrics (listed below) that should not be sent to the MetricRouter can be excluded with the `exclude_metrics` option. Commonly only the physical GPUs are monitored. If MIG devices should be analyzed as well, set `process_mig_devices` (adds `stype=mig,stype-id=<mig_index>`). With the options `use_uuid_for_mig_device` and `use_slice_for_mig_device`, the `<mig_index>` can be replaced with the UUID (e.g. `MIG-6a9f7cc8-6d5b-5ce0-92de-750edc4d8849`) or the MIG slice name (e.g. `1g.5gb`).
|
||||||
|
|
||||||
|
The metrics sent by the `nvidia` collector use `accelerator` as `type` tag. For the `type-id`, it uses the device handle index by default. With the `use_pci_info_as_type_id` option, the PCI ID is used instead. If both values should be added as tags, activate the `add_pci_info_tag` option. It uses the device handle index as `type-id` and adds the PCI ID as separate `pci_identifier` tag.
|
||||||
|
|
||||||
|
Optionally, it is possible to add the UUID, the board part number and the serial to the meta informations. They are not sent to the sinks (if not configured otherwise).
|
||||||
|
|
||||||
|
|
||||||
Metrics:
|
Metrics:
|
||||||
* `nv_util`
|
* `nv_util`
|
||||||
* `nv_mem_util`
|
* `nv_mem_util`
|
||||||
* `nv_mem_total`
|
* `nv_fb_mem_total`
|
||||||
* `nv_fb_memory`
|
* `nv_fb_mem_used`
|
||||||
|
* `nv_bar1_mem_total`
|
||||||
|
* `nv_bar1_mem_used`
|
||||||
* `nv_temp`
|
* `nv_temp`
|
||||||
* `nv_fan`
|
* `nv_fan`
|
||||||
* `nv_ecc_mode`
|
* `nv_ecc_mode`
|
||||||
* `nv_perf_state`
|
* `nv_perf_state`
|
||||||
* `nv_power_usage_report`
|
* `nv_power_usage`
|
||||||
* `nv_graphics_clock_report`
|
* `nv_graphics_clock`
|
||||||
* `nv_sm_clock_report`
|
* `nv_sm_clock`
|
||||||
* `nv_mem_clock_report`
|
* `nv_mem_clock`
|
||||||
|
* `nv_video_clock`
|
||||||
* `nv_max_graphics_clock`
|
* `nv_max_graphics_clock`
|
||||||
* `nv_max_sm_clock`
|
* `nv_max_sm_clock`
|
||||||
* `nv_max_mem_clock`
|
* `nv_max_mem_clock`
|
||||||
* `nv_ecc_db_error`
|
* `nv_max_video_clock`
|
||||||
* `nv_ecc_sb_error`
|
* `nv_ecc_uncorrected_error`
|
||||||
* `nv_power_man_limit`
|
* `nv_ecc_corrected_error`
|
||||||
|
* `nv_power_max_limit`
|
||||||
* `nv_encoder_util`
|
* `nv_encoder_util`
|
||||||
* `nv_decoder_util`
|
* `nv_decoder_util`
|
||||||
|
* `nv_remapped_rows_corrected`
|
||||||
|
* `nv_remapped_rows_uncorrected`
|
||||||
|
* `nv_remapped_rows_pending`
|
||||||
|
* `nv_remapped_rows_failure`
|
||||||
|
* `nv_compute_processes`
|
||||||
|
* `nv_graphics_processes`
|
||||||
|
* `nv_violation_power`
|
||||||
|
* `nv_violation_thermal`
|
||||||
|
* `nv_violation_sync_boost`
|
||||||
|
* `nv_violation_board_limit`
|
||||||
|
* `nv_violation_low_util`
|
||||||
|
* `nv_violation_reliability`
|
||||||
|
* `nv_violation_below_app_clock`
|
||||||
|
* `nv_violation_below_base_clock`
|
||||||
|
* `nv_nvlink_crc_flit_errors`
|
||||||
|
* `nv_nvlink_crc_errors`
|
||||||
|
* `nv_nvlink_ecc_errors`
|
||||||
|
* `nv_nvlink_replay_errors`
|
||||||
|
* `nv_nvlink_recovery_errors`
|
||||||
|
|
||||||
It uses a separate `type` in the metrics. The output metric looks like this:
|
Some metrics add the additional sub type tag (`stype`) like the `nv_nvlink_*` metrics set `stype=nvlink,stype-id=<link_number>`.
|
||||||
`<name>,type=accelerator,type-id=<nvidia-gpu-id> value=<metric value> <timestamp>`
|
|
||||||
|
|
||||||
262
collectors/raplMetric.go
Normal file
262
collectors/raplMetric.go
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
package collectors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
)
|
||||||
|
|
||||||
|
// running average power limit (RAPL) monitoring attributes for a zone
|
||||||
|
type RAPLZoneInfo struct {
|
||||||
|
// tags describing the RAPL zone:
|
||||||
|
// * zone_name, subzone_name: e.g. psys, dram, core, uncore, package-0
|
||||||
|
// * zone_id: e.g. 0:1 (zone 0 sub zone 1)
|
||||||
|
tags map[string]string
|
||||||
|
energyFilepath string // path to a file containing the zones current energy counter in micro joules
|
||||||
|
energy int64 // current reading of the energy counter in micro joules
|
||||||
|
energyTimestamp time.Time // timestamp when energy counter was read
|
||||||
|
maxEnergyRange int64 // Range of the above energy counter in micro-joules
|
||||||
|
}
|
||||||
|
|
||||||
|
type RAPLCollector struct {
|
||||||
|
metricCollector
|
||||||
|
config struct {
|
||||||
|
// Exclude IDs for RAPL zones, e.g.
|
||||||
|
// * 0 for zone 0
|
||||||
|
// * 0:1 for zone 0 subzone 1
|
||||||
|
ExcludeByID []string `json:"exclude_device_by_id,omitempty"`
|
||||||
|
// Exclude names for RAPL zones, e.g. psys, dram, core, uncore, package-0
|
||||||
|
ExcludeByName []string `json:"exclude_device_by_name,omitempty"`
|
||||||
|
}
|
||||||
|
RAPLZoneInfo []RAPLZoneInfo
|
||||||
|
meta map[string]string // default meta information
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init initializes the running average power limit (RAPL) collector
|
||||||
|
func (m *RAPLCollector) Init(config json.RawMessage) error {
|
||||||
|
|
||||||
|
// Check if already initialized
|
||||||
|
if m.init {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error = nil
|
||||||
|
m.name = "RAPLCollector"
|
||||||
|
m.setup()
|
||||||
|
m.parallel = true
|
||||||
|
m.meta = map[string]string{
|
||||||
|
"source": m.name,
|
||||||
|
"group": "energy",
|
||||||
|
"unit": "Watt",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read in the JSON configuration
|
||||||
|
if len(config) > 0 {
|
||||||
|
err = json.Unmarshal(config, &m.config)
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(m.name, "Error reading config:", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure excluded RAPL zones
|
||||||
|
isIDExcluded := make(map[string]bool)
|
||||||
|
if m.config.ExcludeByID != nil {
|
||||||
|
for _, ID := range m.config.ExcludeByID {
|
||||||
|
isIDExcluded[ID] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isNameExcluded := make(map[string]bool)
|
||||||
|
if m.config.ExcludeByName != nil {
|
||||||
|
for _, name := range m.config.ExcludeByName {
|
||||||
|
isNameExcluded[name] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// readZoneInfo reads RAPL monitoring attributes for a zone given by zonePath
|
||||||
|
// See: https://www.kernel.org/doc/html/latest/power/powercap/powercap.html#monitoring-attributes
|
||||||
|
readZoneInfo := func(zonePath string) (z struct {
|
||||||
|
name string // zones name e.g. psys, dram, core, uncore, package-0
|
||||||
|
energyFilepath string // path to a file containing the zones current energy counter in micro joules
|
||||||
|
energy int64 // current reading of the energy counter in micro joules
|
||||||
|
energyTimestamp time.Time // timestamp when energy counter was read
|
||||||
|
maxEnergyRange int64 // Range of the above energy counter in micro-joules
|
||||||
|
ok bool // Are all information available?
|
||||||
|
}) {
|
||||||
|
// zones name e.g. psys, dram, core, uncore, package-0
|
||||||
|
foundName := false
|
||||||
|
if v, err :=
|
||||||
|
os.ReadFile(
|
||||||
|
filepath.Join(zonePath, "name")); err == nil {
|
||||||
|
foundName = true
|
||||||
|
z.name = strings.TrimSpace(string(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// path to a file containing the zones current energy counter in micro joules
|
||||||
|
z.energyFilepath = filepath.Join(zonePath, "energy_uj")
|
||||||
|
|
||||||
|
// current reading of the energy counter in micro joules
|
||||||
|
foundEnergy := false
|
||||||
|
if v, err := os.ReadFile(z.energyFilepath); err == nil {
|
||||||
|
// timestamp when energy counter was read
|
||||||
|
z.energyTimestamp = time.Now()
|
||||||
|
if i, err := strconv.ParseInt(strings.TrimSpace(string(v)), 10, 64); err == nil {
|
||||||
|
foundEnergy = true
|
||||||
|
z.energy = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Range of the above energy counter in micro-joules
|
||||||
|
foundMaxEnergyRange := false
|
||||||
|
if v, err :=
|
||||||
|
os.ReadFile(
|
||||||
|
filepath.Join(zonePath, "max_energy_range_uj")); err == nil {
|
||||||
|
if i, err := strconv.ParseInt(strings.TrimSpace(string(v)), 10, 64); err == nil {
|
||||||
|
foundMaxEnergyRange = true
|
||||||
|
z.maxEnergyRange = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Are all information available?
|
||||||
|
z.ok = foundName && foundEnergy && foundMaxEnergyRange
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
powerCapPrefix := "/sys/devices/virtual/powercap"
|
||||||
|
controlType := "intel-rapl"
|
||||||
|
controlTypePath := filepath.Join(powerCapPrefix, controlType)
|
||||||
|
|
||||||
|
// Find all RAPL zones
|
||||||
|
zonePrefix := filepath.Join(controlTypePath, controlType+":")
|
||||||
|
zonesPath, err := filepath.Glob(zonePrefix + "*")
|
||||||
|
if err != nil || zonesPath == nil {
|
||||||
|
return fmt.Errorf("unable to find any zones under %s", controlTypePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, zonePath := range zonesPath {
|
||||||
|
zoneID := strings.TrimPrefix(zonePath, zonePrefix)
|
||||||
|
z := readZoneInfo(zonePath)
|
||||||
|
if z.ok &&
|
||||||
|
!isIDExcluded[zoneID] &&
|
||||||
|
!isNameExcluded[z.name] {
|
||||||
|
|
||||||
|
// Add RAPL monitoring attributes for a zone
|
||||||
|
m.RAPLZoneInfo =
|
||||||
|
append(
|
||||||
|
m.RAPLZoneInfo,
|
||||||
|
RAPLZoneInfo{
|
||||||
|
tags: map[string]string{
|
||||||
|
"id": zoneID,
|
||||||
|
"zone_name": z.name,
|
||||||
|
},
|
||||||
|
energyFilepath: z.energyFilepath,
|
||||||
|
energy: z.energy,
|
||||||
|
energyTimestamp: z.energyTimestamp,
|
||||||
|
maxEnergyRange: z.maxEnergyRange,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// find all sub zones for the given zone
|
||||||
|
subZonePrefix := filepath.Join(zonePath, controlType+":"+zoneID+":")
|
||||||
|
subZonesPath, err := filepath.Glob(subZonePrefix + "*")
|
||||||
|
if err != nil || subZonesPath == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, subZonePath := range subZonesPath {
|
||||||
|
subZoneID := strings.TrimPrefix(subZonePath, subZonePrefix)
|
||||||
|
sz := readZoneInfo(subZonePath)
|
||||||
|
if len(zoneID) > 0 && len(z.name) > 0 &&
|
||||||
|
sz.ok &&
|
||||||
|
!isIDExcluded[zoneID+":"+subZoneID] &&
|
||||||
|
!isNameExcluded[sz.name] {
|
||||||
|
m.RAPLZoneInfo =
|
||||||
|
append(
|
||||||
|
m.RAPLZoneInfo,
|
||||||
|
RAPLZoneInfo{
|
||||||
|
tags: map[string]string{
|
||||||
|
"id": zoneID + ":" + subZoneID,
|
||||||
|
"zone_name": z.name,
|
||||||
|
"sub_zone_name": sz.name,
|
||||||
|
},
|
||||||
|
energyFilepath: sz.energyFilepath,
|
||||||
|
energy: sz.energy,
|
||||||
|
energyTimestamp: sz.energyTimestamp,
|
||||||
|
maxEnergyRange: sz.maxEnergyRange,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.RAPLZoneInfo == nil {
|
||||||
|
return fmt.Errorf("no running average power limit (RAPL) device found in %s", controlTypePath)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialized
|
||||||
|
cclog.ComponentDebug(
|
||||||
|
m.name,
|
||||||
|
"initialized",
|
||||||
|
len(m.RAPLZoneInfo),
|
||||||
|
"zones with running average power limit (RAPL) monitoring attributes")
|
||||||
|
m.init = true
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read reads running average power limit (RAPL) monitoring attributes for all initialized zones
|
||||||
|
// See: https://www.kernel.org/doc/html/latest/power/powercap/powercap.html#monitoring-attributes
|
||||||
|
func (m *RAPLCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
|
|
||||||
|
for i := range m.RAPLZoneInfo {
|
||||||
|
p := &m.RAPLZoneInfo[i]
|
||||||
|
|
||||||
|
// Read current value of the energy counter in micro joules
|
||||||
|
if v, err := os.ReadFile(p.energyFilepath); err == nil {
|
||||||
|
energyTimestamp := time.Now()
|
||||||
|
if i, err := strconv.ParseInt(strings.TrimSpace(string(v)), 10, 64); err == nil {
|
||||||
|
energy := i
|
||||||
|
|
||||||
|
// Compute average power (Δ energy / Δ time)
|
||||||
|
energyDiff := energy - p.energy
|
||||||
|
if energyDiff < 0 {
|
||||||
|
// Handle overflow:
|
||||||
|
// ( p.maxEnergyRange - p.energy ) + energy
|
||||||
|
// = p.maxEnergyRange + ( energy - p.energy )
|
||||||
|
// = p.maxEnergyRange + diffEnergy
|
||||||
|
energyDiff += p.maxEnergyRange
|
||||||
|
}
|
||||||
|
timeDiff := energyTimestamp.Sub(p.energyTimestamp)
|
||||||
|
averagePower := float64(energyDiff) / float64(timeDiff.Microseconds())
|
||||||
|
|
||||||
|
y, err := lp.NewMessage(
|
||||||
|
"rapl_average_power",
|
||||||
|
p.tags,
|
||||||
|
m.meta,
|
||||||
|
map[string]interface{}{"value": averagePower},
|
||||||
|
energyTimestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save current energy counter state
|
||||||
|
p.energy = energy
|
||||||
|
p.energyTimestamp = energyTimestamp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close closes running average power limit (RAPL) metric collector
|
||||||
|
func (m *RAPLCollector) Close() {
|
||||||
|
// Unset flag
|
||||||
|
m.init = false
|
||||||
|
}
|
||||||
18
collectors/raplMetric.md
Normal file
18
collectors/raplMetric.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Running average power limit (RAPL) metric collector
|
||||||
|
|
||||||
|
This collector reads running average power limit (RAPL) monitoring attributes to compute average power consumption metrics. See <https://www.kernel.org/doc/html/latest/power/powercap/powercap.html#monitoring-attributes>.
|
||||||
|
|
||||||
|
The Likwid metric collector provides similar functionality.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
```json
|
||||||
|
"rapl": {
|
||||||
|
"exclude_device_by_id": ["0:1", "0:2"],
|
||||||
|
"exclude_device_by_name": ["psys"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Metrics
|
||||||
|
|
||||||
|
* `rapl_average_power`: average power consumption in Watt. The average is computed over the entire runtime from the last measurement to the current measurement
|
||||||
319
collectors/rocmsmiMetric.go
Normal file
319
collectors/rocmsmiMetric.go
Normal file
@@ -0,0 +1,319 @@
|
|||||||
|
package collectors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
"github.com/ClusterCockpit/go-rocm-smi/pkg/rocm_smi"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RocmSmiCollectorConfig struct {
|
||||||
|
ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
|
||||||
|
ExcludeDevices []string `json:"exclude_devices,omitempty"`
|
||||||
|
AddPciInfoTag bool `json:"add_pci_info_tag,omitempty"`
|
||||||
|
UsePciInfoAsTypeId bool `json:"use_pci_info_as_type_id,omitempty"`
|
||||||
|
AddSerialMeta bool `json:"add_serial_meta,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RocmSmiCollectorDevice struct {
|
||||||
|
device rocm_smi.DeviceHandle
|
||||||
|
index int
|
||||||
|
tags map[string]string // default tags
|
||||||
|
meta map[string]string // default meta information
|
||||||
|
excludeMetrics map[string]bool // copy of exclude metrics from config
|
||||||
|
}
|
||||||
|
|
||||||
|
type RocmSmiCollector struct {
|
||||||
|
metricCollector
|
||||||
|
config RocmSmiCollectorConfig // the configuration structure
|
||||||
|
devices []RocmSmiCollectorDevice
|
||||||
|
}
|
||||||
|
|
||||||
|
// Functions to implement MetricCollector interface
|
||||||
|
// Init(...), Read(...), Close()
|
||||||
|
// See: metricCollector.go
|
||||||
|
|
||||||
|
// Init initializes the sample collector
|
||||||
|
// Called once by the collector manager
|
||||||
|
// All tags, meta data tags and metrics that do not change over the runtime should be set here
|
||||||
|
func (m *RocmSmiCollector) Init(config json.RawMessage) error {
|
||||||
|
var err error = nil
|
||||||
|
// Always set the name early in Init() to use it in cclog.Component* functions
|
||||||
|
m.name = "RocmSmiCollector"
|
||||||
|
// This is for later use, also call it early
|
||||||
|
m.setup()
|
||||||
|
// Define meta information sent with each metric
|
||||||
|
// (Can also be dynamic or this is the basic set with extension through AddMeta())
|
||||||
|
//m.meta = map[string]string{"source": m.name, "group": "AMD"}
|
||||||
|
// Define tags sent with each metric
|
||||||
|
// The 'type' tag is always needed, it defines the granulatity of the metric
|
||||||
|
// node -> whole system
|
||||||
|
// socket -> CPU socket (requires socket ID as 'type-id' tag)
|
||||||
|
// cpu -> single CPU hardware thread (requires cpu ID as 'type-id' tag)
|
||||||
|
//m.tags = map[string]string{"type": "node"}
|
||||||
|
// Read in the JSON configuration
|
||||||
|
if len(config) > 0 {
|
||||||
|
err = json.Unmarshal(config, &m.config)
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(m.name, "Error reading config:", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := rocm_smi.Init()
|
||||||
|
if ret != rocm_smi.STATUS_SUCCESS {
|
||||||
|
err = errors.New("failed to initialize ROCm SMI library")
|
||||||
|
cclog.ComponentError(m.name, err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
numDevs, ret := rocm_smi.NumMonitorDevices()
|
||||||
|
if ret != rocm_smi.STATUS_SUCCESS {
|
||||||
|
err = errors.New("failed to get number of GPUs from ROCm SMI library")
|
||||||
|
cclog.ComponentError(m.name, err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
exclDev := func(s string) bool {
|
||||||
|
skip_device := false
|
||||||
|
for _, excl := range m.config.ExcludeDevices {
|
||||||
|
if excl == s {
|
||||||
|
skip_device = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return skip_device
|
||||||
|
}
|
||||||
|
|
||||||
|
m.devices = make([]RocmSmiCollectorDevice, 0)
|
||||||
|
|
||||||
|
for i := 0; i < numDevs; i++ {
|
||||||
|
str_i := fmt.Sprintf("%d", i)
|
||||||
|
if exclDev(str_i) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
device, ret := rocm_smi.DeviceGetHandleByIndex(i)
|
||||||
|
if ret != rocm_smi.STATUS_SUCCESS {
|
||||||
|
err = fmt.Errorf("failed to get handle for GPU %d", i)
|
||||||
|
cclog.ComponentError(m.name, err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pciInfo, ret := rocm_smi.DeviceGetPciInfo(device)
|
||||||
|
if ret != rocm_smi.STATUS_SUCCESS {
|
||||||
|
err = fmt.Errorf("failed to get PCI information for GPU %d", i)
|
||||||
|
cclog.ComponentError(m.name, err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pciId := fmt.Sprintf(
|
||||||
|
"%08X:%02X:%02X.%X",
|
||||||
|
pciInfo.Domain,
|
||||||
|
pciInfo.Bus,
|
||||||
|
pciInfo.Device,
|
||||||
|
pciInfo.Function)
|
||||||
|
|
||||||
|
if exclDev(pciId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
dev := RocmSmiCollectorDevice{
|
||||||
|
device: device,
|
||||||
|
tags: map[string]string{
|
||||||
|
"type": "accelerator",
|
||||||
|
"type-id": str_i,
|
||||||
|
},
|
||||||
|
meta: map[string]string{
|
||||||
|
"source": m.name,
|
||||||
|
"group": "AMD",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if m.config.UsePciInfoAsTypeId {
|
||||||
|
dev.tags["type-id"] = pciId
|
||||||
|
} else if m.config.AddPciInfoTag {
|
||||||
|
dev.tags["pci_identifier"] = pciId
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.config.AddSerialMeta {
|
||||||
|
serial, ret := rocm_smi.DeviceGetSerialNumber(device)
|
||||||
|
if ret != rocm_smi.STATUS_SUCCESS {
|
||||||
|
cclog.ComponentError(m.name, "Unable to get serial number for device at index", i, ":", rocm_smi.StatusStringNoError(ret))
|
||||||
|
} else {
|
||||||
|
dev.meta["serial"] = serial
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add excluded metrics
|
||||||
|
dev.excludeMetrics = map[string]bool{}
|
||||||
|
for _, e := range m.config.ExcludeMetrics {
|
||||||
|
dev.excludeMetrics[e] = true
|
||||||
|
}
|
||||||
|
dev.index = i
|
||||||
|
m.devices = append(m.devices, dev)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set this flag only if everything is initialized properly, all required files exist, ...
|
||||||
|
m.init = true
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read collects all metrics belonging to the sample collector
|
||||||
|
// and sends them through the output channel to the collector manager
|
||||||
|
func (m *RocmSmiCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
|
// Create a sample metric
|
||||||
|
timestamp := time.Now()
|
||||||
|
|
||||||
|
for _, dev := range m.devices {
|
||||||
|
metrics, ret := rocm_smi.DeviceGetMetrics(dev.device)
|
||||||
|
if ret != rocm_smi.STATUS_SUCCESS {
|
||||||
|
cclog.ComponentError(m.name, "Unable to get metrics for device at index", dev.index, ":", rocm_smi.StatusStringNoError(ret))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !dev.excludeMetrics["rocm_gfx_util"] {
|
||||||
|
value := metrics.Average_gfx_activity
|
||||||
|
y, err := lp.NewMessage("rocm_gfx_util", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_umc_util"] {
|
||||||
|
value := metrics.Average_umc_activity
|
||||||
|
y, err := lp.NewMessage("rocm_umc_util", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_mm_util"] {
|
||||||
|
value := metrics.Average_mm_activity
|
||||||
|
y, err := lp.NewMessage("rocm_mm_util", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_avg_power"] {
|
||||||
|
value := metrics.Average_socket_power
|
||||||
|
y, err := lp.NewMessage("rocm_avg_power", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_temp_mem"] {
|
||||||
|
value := metrics.Temperature_mem
|
||||||
|
y, err := lp.NewMessage("rocm_temp_mem", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_temp_hotspot"] {
|
||||||
|
value := metrics.Temperature_hotspot
|
||||||
|
y, err := lp.NewMessage("rocm_temp_hotspot", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_temp_edge"] {
|
||||||
|
value := metrics.Temperature_edge
|
||||||
|
y, err := lp.NewMessage("rocm_temp_edge", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_temp_vrgfx"] {
|
||||||
|
value := metrics.Temperature_vrgfx
|
||||||
|
y, err := lp.NewMessage("rocm_temp_vrgfx", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_temp_vrsoc"] {
|
||||||
|
value := metrics.Temperature_vrsoc
|
||||||
|
y, err := lp.NewMessage("rocm_temp_vrsoc", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_temp_vrmem"] {
|
||||||
|
value := metrics.Temperature_vrmem
|
||||||
|
y, err := lp.NewMessage("rocm_temp_vrmem", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_gfx_clock"] {
|
||||||
|
value := metrics.Average_gfxclk_frequency
|
||||||
|
y, err := lp.NewMessage("rocm_gfx_clock", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_soc_clock"] {
|
||||||
|
value := metrics.Average_socclk_frequency
|
||||||
|
y, err := lp.NewMessage("rocm_soc_clock", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_u_clock"] {
|
||||||
|
value := metrics.Average_uclk_frequency
|
||||||
|
y, err := lp.NewMessage("rocm_u_clock", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_v0_clock"] {
|
||||||
|
value := metrics.Average_vclk0_frequency
|
||||||
|
y, err := lp.NewMessage("rocm_v0_clock", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_v1_clock"] {
|
||||||
|
value := metrics.Average_vclk1_frequency
|
||||||
|
y, err := lp.NewMessage("rocm_v1_clock", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_d0_clock"] {
|
||||||
|
value := metrics.Average_dclk0_frequency
|
||||||
|
y, err := lp.NewMessage("rocm_d0_clock", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_d1_clock"] {
|
||||||
|
value := metrics.Average_dclk1_frequency
|
||||||
|
y, err := lp.NewMessage("rocm_d1_clock", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dev.excludeMetrics["rocm_temp_hbm"] {
|
||||||
|
for i := 0; i < rocm_smi.NUM_HBM_INSTANCES; i++ {
|
||||||
|
value := metrics.Temperature_hbm[i]
|
||||||
|
y, err := lp.NewMessage("rocm_temp_hbm", dev.tags, dev.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
y.AddTag("stype", "device")
|
||||||
|
y.AddTag("stype-id", fmt.Sprintf("%d", i))
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close metric collector: close network connection, close files, close libraries, ...
|
||||||
|
// Called once by the collector manager
|
||||||
|
func (m *RocmSmiCollector) Close() {
|
||||||
|
// Unset flag
|
||||||
|
ret := rocm_smi.Shutdown()
|
||||||
|
if ret != rocm_smi.STATUS_SUCCESS {
|
||||||
|
cclog.ComponentError(m.name, "Failed to shutdown ROCm SMI library")
|
||||||
|
}
|
||||||
|
m.init = false
|
||||||
|
}
|
||||||
47
collectors/rocmsmiMetric.md
Normal file
47
collectors/rocmsmiMetric.md
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
## `rocm_smi` collector
|
||||||
|
|
||||||
|
```json
|
||||||
|
"rocm_smi": {
|
||||||
|
"exclude_devices": [
|
||||||
|
"0","1", "0000000:ff:01.0"
|
||||||
|
],
|
||||||
|
"exclude_metrics": [
|
||||||
|
"rocm_mm_util",
|
||||||
|
"rocm_temp_vrsoc"
|
||||||
|
],
|
||||||
|
"use_pci_info_as_type_id": true,
|
||||||
|
"add_pci_info_tag": false,
|
||||||
|
"add_serial_meta": false,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `rocm_smi` collector can be configured to leave out specific devices with the `exclude_devices` option. It takes logical IDs in the list of available devices or the PCI address similar to NVML format (`%08X:%02X:%02X.0`). Metrics (listed below) that should not be sent to the MetricRouter can be excluded with the `exclude_metrics` option.
|
||||||
|
|
||||||
|
The metrics sent by the `rocm_smi` collector use `accelerator` as `type` tag. For the `type-id`, it uses the device handle index by default. With the `use_pci_info_as_type_id` option, the PCI ID is used instead. If both values should be added as tags, activate the `add_pci_info_tag` option. It uses the device handle index as `type-id` and adds the PCI ID as separate `pci_identifier` tag.
|
||||||
|
|
||||||
|
Optionally, it is possible to add the serial to the meta informations. They are not sent to the sinks (if not configured otherwise).
|
||||||
|
|
||||||
|
|
||||||
|
Metrics:
|
||||||
|
* `rocm_gfx_util`
|
||||||
|
* `rocm_umc_util`
|
||||||
|
* `rocm_mm_util`
|
||||||
|
* `rocm_avg_power`
|
||||||
|
* `rocm_temp_mem`
|
||||||
|
* `rocm_temp_hotspot`
|
||||||
|
* `rocm_temp_edge`
|
||||||
|
* `rocm_temp_vrgfx`
|
||||||
|
* `rocm_temp_vrsoc`
|
||||||
|
* `rocm_temp_vrmem`
|
||||||
|
* `rocm_gfx_clock`
|
||||||
|
* `rocm_soc_clock`
|
||||||
|
* `rocm_u_clock`
|
||||||
|
* `rocm_v0_clock`
|
||||||
|
* `rocm_v1_clock`
|
||||||
|
* `rocm_d0_clock`
|
||||||
|
* `rocm_d1_clock`
|
||||||
|
* `rocm_temp_hbm`
|
||||||
|
|
||||||
|
|
||||||
|
Some metrics add the additional sub type tag (`stype`) like the `rocm_temp_hbm` metrics set `stype=device,stype-id=<HBM_slice_number>`.
|
||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// These are the fields we read from the JSON configuration
|
// These are the fields we read from the JSON configuration
|
||||||
@@ -17,7 +17,7 @@ type SampleCollectorConfig struct {
|
|||||||
// defined by metricCollector (name, init, ...)
|
// defined by metricCollector (name, init, ...)
|
||||||
type SampleCollector struct {
|
type SampleCollector struct {
|
||||||
metricCollector
|
metricCollector
|
||||||
config SampleTimerCollectorConfig // the configuration structure
|
config SampleCollectorConfig // the configuration structure
|
||||||
meta map[string]string // default meta information
|
meta map[string]string // default meta information
|
||||||
tags map[string]string // default tags
|
tags map[string]string // default tags
|
||||||
}
|
}
|
||||||
@@ -32,17 +32,26 @@ type SampleCollector struct {
|
|||||||
func (m *SampleCollector) Init(config json.RawMessage) error {
|
func (m *SampleCollector) Init(config json.RawMessage) error {
|
||||||
var err error = nil
|
var err error = nil
|
||||||
// Always set the name early in Init() to use it in cclog.Component* functions
|
// Always set the name early in Init() to use it in cclog.Component* functions
|
||||||
m.name = "InternalCollector"
|
m.name = "SampleCollector"
|
||||||
// This is for later use, also call it early
|
// This is for later use, also call it early
|
||||||
m.setup()
|
m.setup()
|
||||||
|
// Tell whether the collector should be run in parallel with others (reading files, ...)
|
||||||
|
// or it should be run serially, mostly for collectors actually doing measurements
|
||||||
|
// because they should not measure the execution of the other collectors
|
||||||
|
m.parallel = true
|
||||||
// Define meta information sent with each metric
|
// Define meta information sent with each metric
|
||||||
// (Can also be dynamic or this is the basic set with extension through AddMeta())
|
// (Can also be dynamic or this is the basic set with extension through AddMeta())
|
||||||
m.meta = map[string]string{"source": m.name, "group": "SAMPLE"}
|
m.meta = map[string]string{"source": m.name, "group": "SAMPLE"}
|
||||||
// Define tags sent with each metric
|
// Define tags sent with each metric
|
||||||
// The 'type' tag is always needed, it defines the granulatity of the metric
|
// The 'type' tag is always needed, it defines the granularity of the metric
|
||||||
// node -> whole system
|
// node -> whole system
|
||||||
// socket -> CPU socket (requires socket ID as 'type-id' tag)
|
// socket -> CPU socket (requires socket ID as 'type-id' tag)
|
||||||
// cpu -> single CPU hardware thread (requires cpu ID as 'type-id' tag)
|
// die -> CPU die (requires CPU die ID as 'type-id' tag)
|
||||||
|
// memoryDomain -> NUMA domain (requires NUMA domain ID as 'type-id' tag)
|
||||||
|
// llc -> Last level cache (requires last level cache ID as 'type-id' tag)
|
||||||
|
// core -> single CPU core that may consist of multiple hardware threads (SMT) (requires core ID as 'type-id' tag)
|
||||||
|
// hwthtread -> single CPU hardware thread (requires hardware thread ID as 'type-id' tag)
|
||||||
|
// accelerator -> A accelerator device like GPU or FPGA (requires an accelerator ID as 'type-id' tag)
|
||||||
m.tags = map[string]string{"type": "node"}
|
m.tags = map[string]string{"type": "node"}
|
||||||
// Read in the JSON configuration
|
// Read in the JSON configuration
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
@@ -65,7 +74,7 @@ func (m *SampleCollector) Init(config json.RawMessage) error {
|
|||||||
|
|
||||||
// Read collects all metrics belonging to the sample collector
|
// Read collects all metrics belonging to the sample collector
|
||||||
// and sends them through the output channel to the collector manager
|
// and sends them through the output channel to the collector manager
|
||||||
func (m *SampleCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *SampleCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
// Create a sample metric
|
// Create a sample metric
|
||||||
timestamp := time.Now()
|
timestamp := time.Now()
|
||||||
|
|
||||||
@@ -76,7 +85,7 @@ func (m *SampleCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
// stop := readState()
|
// stop := readState()
|
||||||
// value = (stop - start) / interval.Seconds()
|
// value = (stop - start) / interval.Seconds()
|
||||||
|
|
||||||
y, err := lp.New("sample_metric", m.tags, m.meta, map[string]interface{}{"value": value}, timestamp)
|
y, err := lp.NewMessage("sample_metric", m.tags, m.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Send it to output channel
|
// Send it to output channel
|
||||||
output <- y
|
output <- y
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// These are the fields we read from the JSON configuration
|
// These are the fields we read from the JSON configuration
|
||||||
@@ -25,7 +25,7 @@ type SampleTimerCollector struct {
|
|||||||
config SampleTimerCollectorConfig // the configuration structure
|
config SampleTimerCollectorConfig // the configuration structure
|
||||||
interval time.Duration // the interval parsed from configuration
|
interval time.Duration // the interval parsed from configuration
|
||||||
ticker *time.Ticker // own timer
|
ticker *time.Ticker // own timer
|
||||||
output chan lp.CCMetric // own internal output channel
|
output chan lp.CCMessage // own internal output channel
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SampleTimerCollector) Init(name string, config json.RawMessage) error {
|
func (m *SampleTimerCollector) Init(name string, config json.RawMessage) error {
|
||||||
@@ -38,7 +38,7 @@ func (m *SampleTimerCollector) Init(name string, config json.RawMessage) error {
|
|||||||
// (Can also be dynamic or this is the basic set with extension through AddMeta())
|
// (Can also be dynamic or this is the basic set with extension through AddMeta())
|
||||||
m.meta = map[string]string{"source": m.name, "group": "SAMPLE"}
|
m.meta = map[string]string{"source": m.name, "group": "SAMPLE"}
|
||||||
// Define tags sent with each metric
|
// Define tags sent with each metric
|
||||||
// The 'type' tag is always needed, it defines the granulatity of the metric
|
// The 'type' tag is always needed, it defines the granularity of the metric
|
||||||
// node -> whole system
|
// node -> whole system
|
||||||
// socket -> CPU socket (requires socket ID as 'type-id' tag)
|
// socket -> CPU socket (requires socket ID as 'type-id' tag)
|
||||||
// cpu -> single CPU hardware thread (requires cpu ID as 'type-id' tag)
|
// cpu -> single CPU hardware thread (requires cpu ID as 'type-id' tag)
|
||||||
@@ -60,7 +60,7 @@ func (m *SampleTimerCollector) Init(name string, config json.RawMessage) error {
|
|||||||
|
|
||||||
// Storage for output channel
|
// Storage for output channel
|
||||||
m.output = nil
|
m.output = nil
|
||||||
// Mangement channel for the timer function.
|
// Management channel for the timer function.
|
||||||
m.done = make(chan bool)
|
m.done = make(chan bool)
|
||||||
// Create the own ticker
|
// Create the own ticker
|
||||||
m.ticker = time.NewTicker(m.interval)
|
m.ticker = time.NewTicker(m.interval)
|
||||||
@@ -94,20 +94,20 @@ func (m *SampleTimerCollector) ReadMetrics(timestamp time.Time) {
|
|||||||
|
|
||||||
value := 1.0
|
value := 1.0
|
||||||
|
|
||||||
// If you want to measure something for a specific amout of time, use interval
|
// If you want to measure something for a specific amount of time, use interval
|
||||||
// start := readState()
|
// start := readState()
|
||||||
// time.Sleep(interval)
|
// time.Sleep(interval)
|
||||||
// stop := readState()
|
// stop := readState()
|
||||||
// value = (stop - start) / interval.Seconds()
|
// value = (stop - start) / interval.Seconds()
|
||||||
|
|
||||||
y, err := lp.New("sample_metric", m.tags, m.meta, map[string]interface{}{"value": value}, timestamp)
|
y, err := lp.NewMessage("sample_metric", m.tags, m.meta, map[string]interface{}{"value": value}, timestamp)
|
||||||
if err == nil && m.output != nil {
|
if err == nil && m.output != nil {
|
||||||
// Send it to output channel if we have a valid channel
|
// Send it to output channel if we have a valid channel
|
||||||
m.output <- y
|
m.output <- y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SampleTimerCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *SampleTimerCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
// Capture output channel
|
// Capture output channel
|
||||||
m.output = output
|
m.output = output
|
||||||
}
|
}
|
||||||
|
|||||||
154
collectors/schedstatMetric.go
Normal file
154
collectors/schedstatMetric.go
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
package collectors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
)
|
||||||
|
|
||||||
|
const SCHEDSTATFILE = `/proc/schedstat`
|
||||||
|
|
||||||
|
// These are the fields we read from the JSON configuration
|
||||||
|
type SchedstatCollectorConfig struct {
|
||||||
|
ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// This contains all variables we need during execution and the variables
|
||||||
|
// defined by metricCollector (name, init, ...)
|
||||||
|
type SchedstatCollector struct {
|
||||||
|
metricCollector
|
||||||
|
config SchedstatCollectorConfig // the configuration structure
|
||||||
|
lastTimestamp time.Time // Store time stamp of last tick to derive values
|
||||||
|
meta map[string]string // default meta information
|
||||||
|
cputags map[string]map[string]string // default tags
|
||||||
|
olddata map[string]map[string]int64 // default tags
|
||||||
|
}
|
||||||
|
|
||||||
|
// Functions to implement MetricCollector interface
|
||||||
|
// Init(...), Read(...), Close()
|
||||||
|
// See: metricCollector.go
|
||||||
|
|
||||||
|
// Init initializes the sample collector
|
||||||
|
// Called once by the collector manager
|
||||||
|
// All tags, meta data tags and metrics that do not change over the runtime should be set here
|
||||||
|
func (m *SchedstatCollector) Init(config json.RawMessage) error {
|
||||||
|
var err error = nil
|
||||||
|
// Always set the name early in Init() to use it in cclog.Component* functions
|
||||||
|
m.name = "SchedstatCollector"
|
||||||
|
// This is for later use, also call it early
|
||||||
|
m.setup()
|
||||||
|
// Tell whether the collector should be run in parallel with others (reading files, ...)
|
||||||
|
// or it should be run serially, mostly for collectors acutally doing measurements
|
||||||
|
// because they should not measure the execution of the other collectors
|
||||||
|
m.parallel = true
|
||||||
|
// Define meta information sent with each metric
|
||||||
|
// (Can also be dynamic or this is the basic set with extension through AddMeta())
|
||||||
|
m.meta = map[string]string{"source": m.name, "group": "SCHEDSTAT"}
|
||||||
|
|
||||||
|
// Read in the JSON configuration
|
||||||
|
if len(config) > 0 {
|
||||||
|
err = json.Unmarshal(config, &m.config)
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(m.name, "Error reading config:", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check input file
|
||||||
|
file, err := os.Open(string(SCHEDSTATFILE))
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(m.name, err.Error())
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
// Pre-generate tags for all CPUs
|
||||||
|
num_cpus := 0
|
||||||
|
m.cputags = make(map[string]map[string]string)
|
||||||
|
m.olddata = make(map[string]map[string]int64)
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
linefields := strings.Fields(line)
|
||||||
|
if strings.HasPrefix(linefields[0], "cpu") && strings.Compare(linefields[0], "cpu") != 0 {
|
||||||
|
cpustr := strings.TrimLeft(linefields[0], "cpu")
|
||||||
|
cpu, _ := strconv.Atoi(cpustr)
|
||||||
|
running, _ := strconv.ParseInt(linefields[7], 10, 64)
|
||||||
|
waiting, _ := strconv.ParseInt(linefields[8], 10, 64)
|
||||||
|
m.cputags[linefields[0]] = map[string]string{"type": "hwthread", "type-id": fmt.Sprintf("%d", cpu)}
|
||||||
|
m.olddata[linefields[0]] = map[string]int64{"running": running, "waiting": waiting}
|
||||||
|
num_cpus++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save current timestamp
|
||||||
|
m.lastTimestamp = time.Now()
|
||||||
|
|
||||||
|
// Set this flag only if everything is initialized properly, all required files exist, ...
|
||||||
|
m.init = true
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SchedstatCollector) ParseProcLine(linefields []string, tags map[string]string, output chan lp.CCMessage, now time.Time, tsdelta time.Duration) {
|
||||||
|
running, _ := strconv.ParseInt(linefields[7], 10, 64)
|
||||||
|
waiting, _ := strconv.ParseInt(linefields[8], 10, 64)
|
||||||
|
diff_running := running - m.olddata[linefields[0]]["running"]
|
||||||
|
diff_waiting := waiting - m.olddata[linefields[0]]["waiting"]
|
||||||
|
|
||||||
|
var l_running float64 = float64(diff_running) / tsdelta.Seconds() / (math.Pow(1000, 3))
|
||||||
|
var l_waiting float64 = float64(diff_waiting) / tsdelta.Seconds() / (math.Pow(1000, 3))
|
||||||
|
|
||||||
|
m.olddata[linefields[0]]["running"] = running
|
||||||
|
m.olddata[linefields[0]]["waiting"] = waiting
|
||||||
|
value := l_running + l_waiting
|
||||||
|
|
||||||
|
y, err := lp.NewMessage("cpu_load_core", tags, m.meta, map[string]interface{}{"value": value}, now)
|
||||||
|
if err == nil {
|
||||||
|
// Send it to output channel
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read collects all metrics belonging to the sample collector
|
||||||
|
// and sends them through the output channel to the collector manager
|
||||||
|
func (m *SchedstatCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
|
if !m.init {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//timestamps
|
||||||
|
now := time.Now()
|
||||||
|
tsdelta := now.Sub(m.lastTimestamp)
|
||||||
|
|
||||||
|
file, err := os.Open(string(SCHEDSTATFILE))
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(m.name, err.Error())
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
linefields := strings.Fields(line)
|
||||||
|
if strings.HasPrefix(linefields[0], "cpu") {
|
||||||
|
m.ParseProcLine(linefields, m.cputags[linefields[0]], output, now, tsdelta)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.lastTimestamp = now
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close metric collector: close network connection, close files, close libraries, ...
|
||||||
|
// Called once by the collector manager
|
||||||
|
func (m *SchedstatCollector) Close() {
|
||||||
|
// Unset flag
|
||||||
|
m.init = false
|
||||||
|
}
|
||||||
11
collectors/schedstatMetric.md
Normal file
11
collectors/schedstatMetric.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
## `schedstat` collector
|
||||||
|
```json
|
||||||
|
"schedstat": {
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `schedstat` collector reads data from /proc/schedstat and calculates a load value, separated by hwthread. This might be useful to detect bad cpu pinning on shared nodes etc.
|
||||||
|
|
||||||
|
Metric:
|
||||||
|
* `cpu_load_core`
|
||||||
144
collectors/selfMetric.go
Normal file
144
collectors/selfMetric.go
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
package collectors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"runtime"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SelfCollectorConfig struct {
|
||||||
|
MemStats bool `json:"read_mem_stats"`
|
||||||
|
GoRoutines bool `json:"read_goroutines"`
|
||||||
|
CgoCalls bool `json:"read_cgo_calls"`
|
||||||
|
Rusage bool `json:"read_rusage"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SelfCollector struct {
|
||||||
|
metricCollector
|
||||||
|
config SelfCollectorConfig // the configuration structure
|
||||||
|
meta map[string]string // default meta information
|
||||||
|
tags map[string]string // default tags
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SelfCollector) Init(config json.RawMessage) error {
|
||||||
|
var err error = nil
|
||||||
|
m.name = "SelfCollector"
|
||||||
|
m.setup()
|
||||||
|
m.parallel = true
|
||||||
|
m.meta = map[string]string{"source": m.name, "group": "Self"}
|
||||||
|
m.tags = map[string]string{"type": "node"}
|
||||||
|
if len(config) > 0 {
|
||||||
|
err = json.Unmarshal(config, &m.config)
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(m.name, "Error reading config:", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.init = true
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SelfCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
|
timestamp := time.Now()
|
||||||
|
|
||||||
|
if m.config.MemStats {
|
||||||
|
var memstats runtime.MemStats
|
||||||
|
runtime.ReadMemStats(&memstats)
|
||||||
|
|
||||||
|
y, err := lp.NewMessage("total_alloc", m.tags, m.meta, map[string]interface{}{"value": memstats.TotalAlloc}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
y.AddMeta("unit", "Bytes")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
y, err = lp.NewMessage("heap_alloc", m.tags, m.meta, map[string]interface{}{"value": memstats.HeapAlloc}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
y.AddMeta("unit", "Bytes")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
y, err = lp.NewMessage("heap_sys", m.tags, m.meta, map[string]interface{}{"value": memstats.HeapSys}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
y.AddMeta("unit", "Bytes")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
y, err = lp.NewMessage("heap_idle", m.tags, m.meta, map[string]interface{}{"value": memstats.HeapIdle}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
y.AddMeta("unit", "Bytes")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
y, err = lp.NewMessage("heap_inuse", m.tags, m.meta, map[string]interface{}{"value": memstats.HeapInuse}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
y.AddMeta("unit", "Bytes")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
y, err = lp.NewMessage("heap_released", m.tags, m.meta, map[string]interface{}{"value": memstats.HeapReleased}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
y.AddMeta("unit", "Bytes")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
y, err = lp.NewMessage("heap_objects", m.tags, m.meta, map[string]interface{}{"value": memstats.HeapObjects}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if m.config.GoRoutines {
|
||||||
|
y, err := lp.NewMessage("num_goroutines", m.tags, m.meta, map[string]interface{}{"value": runtime.NumGoroutine()}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if m.config.CgoCalls {
|
||||||
|
y, err := lp.NewMessage("num_cgo_calls", m.tags, m.meta, map[string]interface{}{"value": runtime.NumCgoCall()}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if m.config.Rusage {
|
||||||
|
var rusage syscall.Rusage
|
||||||
|
err := syscall.Getrusage(syscall.RUSAGE_SELF, &rusage)
|
||||||
|
if err == nil {
|
||||||
|
sec, nsec := rusage.Utime.Unix()
|
||||||
|
t := float64(sec) + (float64(nsec) * 1e-9)
|
||||||
|
y, err := lp.NewMessage("rusage_user_time", m.tags, m.meta, map[string]interface{}{"value": t}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
y.AddMeta("unit", "seconds")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
sec, nsec = rusage.Stime.Unix()
|
||||||
|
t = float64(sec) + (float64(nsec) * 1e-9)
|
||||||
|
y, err = lp.NewMessage("rusage_system_time", m.tags, m.meta, map[string]interface{}{"value": t}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
y.AddMeta("unit", "seconds")
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
y, err = lp.NewMessage("rusage_vol_ctx_switch", m.tags, m.meta, map[string]interface{}{"value": rusage.Nvcsw}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
y, err = lp.NewMessage("rusage_invol_ctx_switch", m.tags, m.meta, map[string]interface{}{"value": rusage.Nivcsw}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
y, err = lp.NewMessage("rusage_signals", m.tags, m.meta, map[string]interface{}{"value": rusage.Nsignals}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
y, err = lp.NewMessage("rusage_major_pgfaults", m.tags, m.meta, map[string]interface{}{"value": rusage.Majflt}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
y, err = lp.NewMessage("rusage_minor_pgfaults", m.tags, m.meta, map[string]interface{}{"value": rusage.Minflt}, timestamp)
|
||||||
|
if err == nil {
|
||||||
|
output <- y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SelfCollector) Close() {
|
||||||
|
m.init = false
|
||||||
|
}
|
||||||
34
collectors/selfMetric.md
Normal file
34
collectors/selfMetric.md
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
## `self` collector
|
||||||
|
|
||||||
|
```json
|
||||||
|
"self": {
|
||||||
|
"read_mem_stats" : true,
|
||||||
|
"read_goroutines" : true,
|
||||||
|
"read_cgo_calls" : true,
|
||||||
|
"read_rusage" : true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `self` collector reads the data from the `runtime` and `syscall` packages, so monitors the execution of the cc-metric-collector itself.
|
||||||
|
|
||||||
|
Metrics:
|
||||||
|
* If `read_mem_stats == true`:
|
||||||
|
* `total_alloc`: The metric reports cumulative bytes allocated for heap objects.
|
||||||
|
* `heap_alloc`: The metric reports bytes of allocated heap objects.
|
||||||
|
* `heap_sys`: The metric reports bytes of heap memory obtained from the OS.
|
||||||
|
* `heap_idle`: The metric reports bytes in idle (unused) spans.
|
||||||
|
* `heap_inuse`: The metric reports bytes in in-use spans.
|
||||||
|
* `heap_released`: The metric reports bytes of physical memory returned to the OS.
|
||||||
|
* `heap_objects`: The metric reports the number of allocated heap objects.
|
||||||
|
* If `read_goroutines == true`:
|
||||||
|
* `num_goroutines`: The metric reports the number of goroutines that currently exist.
|
||||||
|
* If `read_cgo_calls == true`:
|
||||||
|
* `num_cgo_calls`: The metric reports the number of cgo calls made by the current process.
|
||||||
|
* If `read_rusage == true`:
|
||||||
|
* `rusage_user_time`: The metric reports the amount of time that this process has been scheduled in user mode.
|
||||||
|
* `rusage_system_time`: The metric reports the amount of time that this process has been scheduled in kernel mode.
|
||||||
|
* `rusage_vol_ctx_switch`: The metric reports the amount of voluntary context switches.
|
||||||
|
* `rusage_invol_ctx_switch`: The metric reports the amount of involuntary context switches.
|
||||||
|
* `rusage_signals`: The metric reports the number of signals received.
|
||||||
|
* `rusage_major_pgfaults`: The metric reports the number of major faults the process has made which have required loading a memory page from disk.
|
||||||
|
* `rusage_minor_pgfaults`: The metric reports the number of minor faults the process has made which have not required loading a memory page from disk.
|
||||||
@@ -3,14 +3,14 @@ package collectors
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
// See: https://www.kernel.org/doc/html/latest/hwmon/sysfs-interface.html
|
// See: https://www.kernel.org/doc/html/latest/hwmon/sysfs-interface.html
|
||||||
@@ -50,6 +50,7 @@ func (m *TempCollector) Init(config json.RawMessage) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.name = "TempCollector"
|
m.name = "TempCollector"
|
||||||
|
m.parallel = true
|
||||||
m.setup()
|
m.setup()
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err := json.Unmarshal(config, &m.config)
|
err := json.Unmarshal(config, &m.config)
|
||||||
@@ -70,10 +71,10 @@ func (m *TempCollector) Init(config json.RawMessage) error {
|
|||||||
globPattern := filepath.Join("/sys/class/hwmon", "*", "temp*_input")
|
globPattern := filepath.Join("/sys/class/hwmon", "*", "temp*_input")
|
||||||
inputFiles, err := filepath.Glob(globPattern)
|
inputFiles, err := filepath.Glob(globPattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to glob files with pattern '%s': %v", globPattern, err)
|
return fmt.Errorf("unable to glob files with pattern '%s': %v", globPattern, err)
|
||||||
}
|
}
|
||||||
if inputFiles == nil {
|
if inputFiles == nil {
|
||||||
return fmt.Errorf("Unable to find any files with pattern '%s'", globPattern)
|
return fmt.Errorf("unable to find any files with pattern '%s'", globPattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get sensor name for each temperature sensor file
|
// Get sensor name for each temperature sensor file
|
||||||
@@ -82,14 +83,14 @@ func (m *TempCollector) Init(config json.RawMessage) error {
|
|||||||
|
|
||||||
// sensor name
|
// sensor name
|
||||||
nameFile := filepath.Join(filepath.Dir(file), "name")
|
nameFile := filepath.Join(filepath.Dir(file), "name")
|
||||||
name, err := ioutil.ReadFile(nameFile)
|
name, err := os.ReadFile(nameFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
sensor.name = strings.TrimSpace(string(name))
|
sensor.name = strings.TrimSpace(string(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// sensor label
|
// sensor label
|
||||||
labelFile := strings.TrimSuffix(file, "_input") + "_label"
|
labelFile := strings.TrimSuffix(file, "_input") + "_label"
|
||||||
label, err := ioutil.ReadFile(labelFile)
|
label, err := os.ReadFile(labelFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
sensor.label = strings.TrimSpace(string(label))
|
sensor.label = strings.TrimSpace(string(label))
|
||||||
}
|
}
|
||||||
@@ -116,6 +117,10 @@ func (m *TempCollector) Init(config json.RawMessage) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sensor file
|
// Sensor file
|
||||||
|
_, err = os.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
sensor.file = file
|
sensor.file = file
|
||||||
|
|
||||||
// Sensor tags
|
// Sensor tags
|
||||||
@@ -134,7 +139,7 @@ func (m *TempCollector) Init(config json.RawMessage) error {
|
|||||||
// max temperature
|
// max temperature
|
||||||
if m.config.ReportMaxTemp {
|
if m.config.ReportMaxTemp {
|
||||||
maxTempFile := strings.TrimSuffix(file, "_input") + "_max"
|
maxTempFile := strings.TrimSuffix(file, "_input") + "_max"
|
||||||
if buffer, err := ioutil.ReadFile(maxTempFile); err == nil {
|
if buffer, err := os.ReadFile(maxTempFile); err == nil {
|
||||||
if x, err := strconv.ParseInt(strings.TrimSpace(string(buffer)), 10, 64); err == nil {
|
if x, err := strconv.ParseInt(strings.TrimSpace(string(buffer)), 10, 64); err == nil {
|
||||||
sensor.maxTempName = strings.Replace(sensor.metricName, "temp", "max_temp", 1)
|
sensor.maxTempName = strings.Replace(sensor.metricName, "temp", "max_temp", 1)
|
||||||
sensor.maxTemp = x / 1000
|
sensor.maxTemp = x / 1000
|
||||||
@@ -145,7 +150,7 @@ func (m *TempCollector) Init(config json.RawMessage) error {
|
|||||||
// critical temperature
|
// critical temperature
|
||||||
if m.config.ReportCriticalTemp {
|
if m.config.ReportCriticalTemp {
|
||||||
criticalTempFile := strings.TrimSuffix(file, "_input") + "_crit"
|
criticalTempFile := strings.TrimSuffix(file, "_input") + "_crit"
|
||||||
if buffer, err := ioutil.ReadFile(criticalTempFile); err == nil {
|
if buffer, err := os.ReadFile(criticalTempFile); err == nil {
|
||||||
if x, err := strconv.ParseInt(strings.TrimSpace(string(buffer)), 10, 64); err == nil {
|
if x, err := strconv.ParseInt(strings.TrimSpace(string(buffer)), 10, 64); err == nil {
|
||||||
sensor.critTempName = strings.Replace(sensor.metricName, "temp", "crit_temp", 1)
|
sensor.critTempName = strings.Replace(sensor.metricName, "temp", "crit_temp", 1)
|
||||||
sensor.critTemp = x / 1000
|
sensor.critTemp = x / 1000
|
||||||
@@ -158,7 +163,7 @@ func (m *TempCollector) Init(config json.RawMessage) error {
|
|||||||
|
|
||||||
// Empty sensors map
|
// Empty sensors map
|
||||||
if len(m.sensors) == 0 {
|
if len(m.sensors) == 0 {
|
||||||
return fmt.Errorf("No temperature sensors found")
|
return fmt.Errorf("no temperature sensors found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finished initialization
|
// Finished initialization
|
||||||
@@ -166,11 +171,11 @@ func (m *TempCollector) Init(config json.RawMessage) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *TempCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *TempCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
|
|
||||||
for _, sensor := range m.sensors {
|
for _, sensor := range m.sensors {
|
||||||
// Read sensor file
|
// Read sensor file
|
||||||
buffer, err := ioutil.ReadFile(sensor.file)
|
buffer, err := os.ReadFile(sensor.file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.ComponentError(
|
cclog.ComponentError(
|
||||||
m.name,
|
m.name,
|
||||||
@@ -185,7 +190,7 @@ func (m *TempCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
x /= 1000
|
x /= 1000
|
||||||
y, err := lp.New(
|
y, err := lp.NewMessage(
|
||||||
sensor.metricName,
|
sensor.metricName,
|
||||||
sensor.tags,
|
sensor.tags,
|
||||||
m.meta,
|
m.meta,
|
||||||
@@ -198,7 +203,7 @@ func (m *TempCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
|
|
||||||
// max temperature
|
// max temperature
|
||||||
if m.config.ReportMaxTemp && sensor.maxTemp != 0 {
|
if m.config.ReportMaxTemp && sensor.maxTemp != 0 {
|
||||||
y, err := lp.New(
|
y, err := lp.NewMessage(
|
||||||
sensor.maxTempName,
|
sensor.maxTempName,
|
||||||
sensor.tags,
|
sensor.tags,
|
||||||
m.meta,
|
m.meta,
|
||||||
@@ -212,7 +217,7 @@ func (m *TempCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
|
|
||||||
// critical temperature
|
// critical temperature
|
||||||
if m.config.ReportCriticalTemp && sensor.critTemp != 0 {
|
if m.config.ReportCriticalTemp && sensor.critTemp != 0 {
|
||||||
y, err := lp.New(
|
y, err := lp.NewMessage(
|
||||||
sensor.critTempName,
|
sensor.critTempName,
|
||||||
sensor.tags,
|
sensor.tags,
|
||||||
m.meta,
|
m.meta,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MAX_NUM_PROCS = 10
|
const MAX_NUM_PROCS = 10
|
||||||
@@ -28,6 +28,7 @@ type TopProcsCollector struct {
|
|||||||
func (m *TopProcsCollector) Init(config json.RawMessage) error {
|
func (m *TopProcsCollector) Init(config json.RawMessage) error {
|
||||||
var err error
|
var err error
|
||||||
m.name = "TopProcsCollector"
|
m.name = "TopProcsCollector"
|
||||||
|
m.parallel = true
|
||||||
m.tags = map[string]string{"type": "node"}
|
m.tags = map[string]string{"type": "node"}
|
||||||
m.meta = map[string]string{"source": m.name, "group": "TopProcs"}
|
m.meta = map[string]string{"source": m.name, "group": "TopProcs"}
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
@@ -39,20 +40,20 @@ func (m *TopProcsCollector) Init(config json.RawMessage) error {
|
|||||||
m.config.Num_procs = int(DEFAULT_NUM_PROCS)
|
m.config.Num_procs = int(DEFAULT_NUM_PROCS)
|
||||||
}
|
}
|
||||||
if m.config.Num_procs <= 0 || m.config.Num_procs > MAX_NUM_PROCS {
|
if m.config.Num_procs <= 0 || m.config.Num_procs > MAX_NUM_PROCS {
|
||||||
return errors.New(fmt.Sprintf("num_procs option must be set in 'topprocs' config (range: 1-%d)", MAX_NUM_PROCS))
|
return fmt.Errorf("num_procs option must be set in 'topprocs' config (range: 1-%d)", MAX_NUM_PROCS)
|
||||||
}
|
}
|
||||||
m.setup()
|
m.setup()
|
||||||
command := exec.Command("ps", "-Ao", "comm", "--sort=-pcpu")
|
command := exec.Command("ps", "-Ao", "comm", "--sort=-pcpu")
|
||||||
command.Wait()
|
command.Wait()
|
||||||
_, err = command.Output()
|
_, err = command.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("Failed to execute command")
|
return errors.New("failed to execute command")
|
||||||
}
|
}
|
||||||
m.init = true
|
m.init = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *TopProcsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
func (m *TopProcsCollector) Read(interval time.Duration, output chan lp.CCMessage) {
|
||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -67,7 +68,7 @@ func (m *TopProcsCollector) Read(interval time.Duration, output chan lp.CCMetric
|
|||||||
lines := strings.Split(string(stdout), "\n")
|
lines := strings.Split(string(stdout), "\n")
|
||||||
for i := 1; i < m.config.Num_procs+1; i++ {
|
for i := 1; i < m.config.Num_procs+1; i++ {
|
||||||
name := fmt.Sprintf("topproc%d", i)
|
name := fmt.Sprintf("topproc%d", i)
|
||||||
y, err := lp.New(name, m.tags, m.meta, map[string]interface{}{"value": string(lines[i])}, time.Now())
|
y, err := lp.NewMessage(name, m.tags, m.meta, map[string]interface{}{"value": string(lines[i])}, time.Now())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
|||||||
12
config.json
12
config.json
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"sinks": "sinks.json",
|
"sinks": "./sinks.json",
|
||||||
"collectors" : "collectors.json",
|
"collectors" : "./collectors.json",
|
||||||
"receivers" : "receivers.json",
|
"receivers" : "./receivers.json",
|
||||||
"router" : "router.json",
|
"router" : "./router.json",
|
||||||
"interval": 10,
|
"interval": "10s",
|
||||||
"duration": 1
|
"duration": "1s"
|
||||||
}
|
}
|
||||||
|
|||||||
74
docs/building.md
Normal file
74
docs/building.md
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
# Building the cc-metric-collector
|
||||||
|
|
||||||
|
In most cases, a simple `make` in the main folder is enough to get a `cc-metric-collector` binary. It is basically a `go build` but some collectors require additional tasks. There is currently no Golang interface to LIKWID, so it uses `cgo` to create bindings but `cgo` requires the LIKWID header files. Therefore, it checks whether LIKWID is installed and if not it downloads LIKWID and copies the headers.
|
||||||
|
|
||||||
|
## System integration
|
||||||
|
|
||||||
|
The main configuration settings for system integration are pre-defined in `scripts/cc-metric-collector.config`. The file contains the UNIX user and group used for execution, the PID file location and other settings. Adjust it accordingly and copy it to `/etc/default/cc-metric-collector`
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ install --mode 644 \
|
||||||
|
--owner $CC_USER \
|
||||||
|
--group $CC_GROUP \
|
||||||
|
scripts/cc-metric-collector.config /etc/default/cc-metric-collector
|
||||||
|
$ edit /etc/default/cc-metric-collector
|
||||||
|
```
|
||||||
|
|
||||||
|
### SysVinit and similar
|
||||||
|
|
||||||
|
If you are using a init system based in `/etc/init.d` daemons, you can use the sample `scripts/cc-metric-collector.init`. It reads the basic configuration from `/etc/default/cc-metric-collector`
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ install --mode 755 \
|
||||||
|
--owner $CC_USER \
|
||||||
|
--group $CC_GROUP \
|
||||||
|
scripts/cc-metric-collector.init /etc/init.d/cc-metric-collector
|
||||||
|
```
|
||||||
|
|
||||||
|
### Systemd
|
||||||
|
|
||||||
|
If you are using `systemd` as init system, you can use the sample systemd service file `scripts/cc-metric-collector.service`, the configuration file `scripts/cc-metric-collector.config`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ install --mode 644 \
|
||||||
|
--owner $CC_USER \
|
||||||
|
--group $CC_GROUP \
|
||||||
|
scripts/cc-metric-collector.service /etc/systemd/system/cc-metric-collector.service
|
||||||
|
$ systemctl enable cc-metric-collector
|
||||||
|
```
|
||||||
|
|
||||||
|
## Packaging
|
||||||
|
|
||||||
|
### RPM
|
||||||
|
|
||||||
|
In order to get a RPM packages for cc-metric-collector, just use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ make RPM
|
||||||
|
```
|
||||||
|
|
||||||
|
It uses the RPM SPEC file `scripts/cc-metric-collector.spec` and requires the RPM tools (`rpm` and `rpmspec`) and `git`.
|
||||||
|
|
||||||
|
### DEB
|
||||||
|
|
||||||
|
In order to get very simple Debian packages for cc-metric-collector, just use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ make DEB
|
||||||
|
```
|
||||||
|
|
||||||
|
It uses the DEB control file `scripts/cc-metric-collector.control` and requires `dpkg-deb`, `awk`, `sed` and `git`. It creates only a binary deb package.
|
||||||
|
|
||||||
|
_This option is not well tested and therefore experimental_
|
||||||
|
|
||||||
|
### Customizing RPMs or DEB packages
|
||||||
|
|
||||||
|
If you want to customize the RPMs or DEB packages for your local system, use the following workflow.
|
||||||
|
|
||||||
|
- (if there is already a fork in the private account, delete it and wait until Github realizes the deletion)
|
||||||
|
- Fork the cc-metric-collector repository (if Github hasn't realized it, it creates a fork named cc-metric-collector2)
|
||||||
|
- Go to private cc-metric-collector repository and enable Github Actions
|
||||||
|
- Do changes to the scripts, code, ... Commit and push your changes.
|
||||||
|
- Tag the new commit with `v0.x.y-<myversion>` (`git tag v0.x.y-<myversion>`)
|
||||||
|
- Push tags to repository (`git push --tags`)
|
||||||
|
- Wait until the Release action finishes. It creates fresh RPMs and DEBs in your private repository on the Releases page.
|
||||||
189
docs/configuration.md
Normal file
189
docs/configuration.md
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
# Configuring the CC metric collector
|
||||||
|
|
||||||
|
The configuration of the CC metric collector consists of five configuration files: one global file and four component related files.
|
||||||
|
|
||||||
|
## Global configuration
|
||||||
|
|
||||||
|
The global file contains the paths to the other four files and some global options.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"sinks": "sinks.json",
|
||||||
|
"collectors" : "collectors.json",
|
||||||
|
"receivers" : "receivers.json",
|
||||||
|
"router" : "router.json",
|
||||||
|
"interval": "10s",
|
||||||
|
"duration": "1s"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Be aware that the paths are relative to the execution folder of the cc-metric-collector binary, so it is recommended to use absolute paths.
|
||||||
|
|
||||||
|
## Component configuration
|
||||||
|
|
||||||
|
The others are mainly list of of subcomponents: the collectors, the receivers, the router and the sinks. Their role is best shown in a picture:
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart LR
|
||||||
|
|
||||||
|
subgraph col ["Collectors"]
|
||||||
|
direction TB
|
||||||
|
cpustat["cpustat"]
|
||||||
|
memstat["memstat"]
|
||||||
|
tempstat["tempstat"]
|
||||||
|
misc["..."]
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph Receivers ["Receivers"]
|
||||||
|
direction TB
|
||||||
|
nats["NATS"]
|
||||||
|
httprecv["HTTP"]
|
||||||
|
miscrecv[...]
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph calc["Aggregator"]
|
||||||
|
direction LR
|
||||||
|
cache["Cache"]
|
||||||
|
agg["Calculator"]
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph sinks ["Sinks"]
|
||||||
|
direction RL
|
||||||
|
influx["InfluxDB"]
|
||||||
|
ganglia["Ganglia"]
|
||||||
|
logger["Logfile"]
|
||||||
|
miscsink["..."]
|
||||||
|
end
|
||||||
|
|
||||||
|
cpustat --> CollectorManager["CollectorManager"]
|
||||||
|
memstat --> CollectorManager
|
||||||
|
tempstat --> CollectorManager
|
||||||
|
misc --> CollectorManager
|
||||||
|
|
||||||
|
nats --> ReceiverManager["ReceiverManager"]
|
||||||
|
httprecv --> ReceiverManager
|
||||||
|
miscrecv --> ReceiverManager
|
||||||
|
|
||||||
|
CollectorManager --> newrouter["Router"]
|
||||||
|
ReceiverManager -.-> newrouter
|
||||||
|
calc -.-> newrouter
|
||||||
|
newrouter --> SinkManager["SinkManager"]
|
||||||
|
newrouter -.-> calc
|
||||||
|
|
||||||
|
SinkManager --> influx
|
||||||
|
SinkManager --> ganglia
|
||||||
|
SinkManager --> logger
|
||||||
|
SinkManager --> miscsink
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
There are four parts:
|
||||||
|
- The collectors read data from files, execute commands and call dynamically loaded library function and send it to the router
|
||||||
|
- The router can process metrics by cacheing and evaluating functions and conditions on them
|
||||||
|
- The sinks send the metrics to storage backends
|
||||||
|
- The receivers can be used to receive metrics from other collectors and forward them to the router. They can be used to create a tree-like structure of collectors.
|
||||||
|
|
||||||
|
(A maybe better differentiation between collectors and receivers is that the collectors are called periodically while the receivers have their own logic and submit metrics at any time)
|
||||||
|
|
||||||
|
|
||||||
|
### Collectors configuration file
|
||||||
|
|
||||||
|
The collectors configuration file tells which metrics should be queried from the system. The metric gathering is logically grouped in so called 'Collectors'. So there are Collectors to read CPU, memory or filesystem statistics. The collectors configuration file is a list of these collectors with collector-specific configurations:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"cpustat" : {},
|
||||||
|
"diskstat": {
|
||||||
|
"exclude_metrics": [
|
||||||
|
"disk_total"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The first one is the CPU statistics collector without any collector-specific setting. The second one enables disk mount statistics but excludes the metric `disk_total`.
|
||||||
|
|
||||||
|
All names and possible collector-specific configuration options can be found [here](../collectors/README.md).
|
||||||
|
|
||||||
|
Some collectors might dynamically load shared libraries. In order to enable these collectors, make sure that the shared library path is part of the `LD_LIBRARY_PATH` environment variable.
|
||||||
|
|
||||||
|
### Sinks configuration file
|
||||||
|
|
||||||
|
The sinks define the output/sending of metrics. The metrics can be forwarded to multiple sinks, even to sinks of the same type. The sinks configuration file is a list of these sinks, each with an individual name.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"myinflux" : {
|
||||||
|
"type" : "influxasync",
|
||||||
|
"host": "localhost",
|
||||||
|
"port": "8086",
|
||||||
|
"organization" : "testorga",
|
||||||
|
"database" : "testbucket",
|
||||||
|
"password" : "<my secret JWT>"
|
||||||
|
},
|
||||||
|
"companyinflux" : {
|
||||||
|
"type" : "influxasync",
|
||||||
|
"host": "companyhost",
|
||||||
|
"port": "8086",
|
||||||
|
"organization" : "company",
|
||||||
|
"database" : "main",
|
||||||
|
"password" : "<company's secret JWT>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The above example configuration file defines two sink, both ot type `influxasync`. They are differentiated internally by the names: `myinflux` and `companyinflux`.
|
||||||
|
|
||||||
|
All types and possible sink-specific configuration options can be found [here](../sinks/README.md).
|
||||||
|
|
||||||
|
Some sinks might dynamically load shared libraries. In order to enable these sinks, make sure that the shared library path is part of the `LD_LIBRARY_PATH` environment variable.
|
||||||
|
|
||||||
|
### Router configuration file
|
||||||
|
|
||||||
|
The collectors and the sinks are connected through the router. The router forwards the metrics to the sinks but enables some data processing. A common example is to tag all passing metrics like adding `cluster=mycluster`. But also aggregations like "take the average of all 'ipc' metrics" (ipc -> Instructions Per Cycle). Since the configurations of these aggregations can be quite complicated, we refer to the router's [README](../internal/metricRouter/README.md).
|
||||||
|
|
||||||
|
A simple router configuration file to start with looks like this:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"add_tags" : [
|
||||||
|
{
|
||||||
|
"key" : "cluster",
|
||||||
|
"value" : "mycluster",
|
||||||
|
"if" : "*"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"interval_timestamp" : false,
|
||||||
|
"num_cache_intervals" : 0
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
With the `add_tags` section, we tell to attach the `cluster=mycluster` tag to each (`*` metric). The `interval_timestamp` tell the router to not touch the timestamp of metrics. It is possible to send all metrics within an interval with a common time stamp to avoid later alignment issues. The `num_cache_intervals` diables the cache completely. The cache is only required if you want to do complex metric aggregations.
|
||||||
|
|
||||||
|
All configuration options can be found [here](../internal/metricRouter/README.md).
|
||||||
|
|
||||||
|
### Receivers configuration file
|
||||||
|
|
||||||
|
The receivers are a special feature of the CC Metric Collector to enable simpler integration into exising setups. While collectors query data from the local system, the receivers commonly get data from other systems through some network technology like HTTP or NATS. The idea is keep the current setup but send it to a CC Metric Collector which forwards it to the the destination system (if a sink exists for it). For most setups, the receivers are not required and an the receiver config file should contain only an empty JSON map (`{}`).
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"nats_rack0": {
|
||||||
|
"type": "nats",
|
||||||
|
"address" : "nats-server.example.org",
|
||||||
|
"port" : "4222",
|
||||||
|
"subject" : "rack0",
|
||||||
|
},
|
||||||
|
"nats_rack1": {
|
||||||
|
"type": "nats",
|
||||||
|
"address" : "nats-server.example.org",
|
||||||
|
"port" : "4222",
|
||||||
|
"subject" : "rack1",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This example configuration creates two receivers with the names `nats_rack0` and `nats_rack1`. While one subscribes to metrics published with the `rack0` subject, the other one subscribes to the `rack0` subject. The NATS server is the same as it manages all subjects in a subnet. (As example, the router could add tags `rack=0` and `rack=1` respectively to the received metrics.)
|
||||||
|
|
||||||
|
All types and possible receiver-specific configuration options can be found [here](../receivers/README.md).
|
||||||
23
docs/introduction.md
Normal file
23
docs/introduction.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# The ClusterCockpit Project
|
||||||
|
|
||||||
|
The ClusterCockpit project is a joined project of computing centers in Europe to set up a cluster monitoring stack for small to mid-sized computing centers under the lead of NHR@FAU.
|
||||||
|
|
||||||
|
# The ClusterCockpit Stack
|
||||||
|
|
||||||
|
In cluster environment, there are commonly a lot of systems dedicated for computation, backend servers for file systems and frontend servers for the user interaction and cluster control. The ClusterCockpit Stack is mainly used for monitoring the compute systems with some interaction to the frontend servers. It consists of multiple components:
|
||||||
|
|
||||||
|
- cc-metric-collector: Monitor resource usage on the compute systems
|
||||||
|
- cc-metric-store: In-memory database
|
||||||
|
- cc-backend & cc-frontend: The web-based visualizer
|
||||||
|
|
||||||
|
# CC Metric Collector
|
||||||
|
|
||||||
|
The CC Metric Collector project was started to provide a useful set of metrics for HPC and data science related compute systems. It runs as a system daemon and gathers system data periodically to forward the metrics to one or more databases. One of the provided backends can be used for the cc-metric-store but many others exist like InfluxDB time-series databases, the Ganglia Monitoring System or the Prometheus Monitoring System.
|
||||||
|
|
||||||
|
The data is gathered by so-called "Collectors", forwarded to an internal router for on-the-fly manipulation (tagging, aggregation, ...) which pushes the metrics to the different metric writers called "Sinks". There is a forth component, the "Receivers", which receive data through some networking system like a HTTP server at any time.
|
||||||
|
|
||||||
|
# CC Metric Store
|
||||||
|
The CC Metric Store is a data management system with short-term in-memory and long-term file-base metric storage.
|
||||||
|
|
||||||
|
# CC Backend and CC Frontend
|
||||||
|
The CC Backend and Frontend form together the web interface for ClusterCockpit.
|
||||||
46
go.mod
46
go.mod
@@ -1,19 +1,45 @@
|
|||||||
module github.com/ClusterCockpit/cc-metric-collector
|
module github.com/ClusterCockpit/cc-metric-collector
|
||||||
|
|
||||||
go 1.16
|
go 1.21.1
|
||||||
|
|
||||||
|
toolchain go1.22.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/NVIDIA/go-nvml v0.11.1-0
|
github.com/ClusterCockpit/cc-energy-manager v0.0.0-20240709142550-dd446f7ab900
|
||||||
github.com/influxdata/influxdb-client-go/v2 v2.7.0
|
github.com/ClusterCockpit/cc-units v0.4.0
|
||||||
|
github.com/ClusterCockpit/go-rocm-smi v0.3.0
|
||||||
|
github.com/NVIDIA/go-nvml v0.12.0-2
|
||||||
|
github.com/PaesslerAG/gval v1.2.2
|
||||||
|
github.com/expr-lang/expr v1.16.9
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0
|
||||||
|
github.com/gorilla/mux v1.8.1
|
||||||
|
github.com/influxdata/influxdb-client-go/v2 v2.13.0
|
||||||
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf
|
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf
|
||||||
github.com/nats-io/nats.go v1.13.1-0.20211122170419-d7c1d78a50fc
|
github.com/influxdata/line-protocol/v2 v2.2.1
|
||||||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9
|
github.com/nats-io/nats.go v1.36.0
|
||||||
gopkg.in/Knetic/govaluate.v2 v2.3.0
|
github.com/prometheus/client_golang v1.19.0
|
||||||
|
github.com/stmcginnis/gofish v0.15.0
|
||||||
|
github.com/tklauser/go-sysconf v0.3.13
|
||||||
|
golang.design/x/thread v0.0.0-20210122121316-335e9adffdf1
|
||||||
|
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
|
||||||
|
golang.org/x/sys v0.18.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/PaesslerAG/gval v1.1.2
|
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
|
||||||
github.com/golang/protobuf v1.5.2 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/nats-io/nats-server/v2 v2.7.0 // indirect
|
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||||
google.golang.org/protobuf v1.27.1 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/klauspost/compress v1.17.7 // indirect
|
||||||
|
github.com/nats-io/nkeys v0.4.7 // indirect
|
||||||
|
github.com/nats-io/nuid v1.0.1 // indirect
|
||||||
|
github.com/oapi-codegen/runtime v1.1.1 // indirect
|
||||||
|
github.com/prometheus/client_model v0.6.0 // indirect
|
||||||
|
github.com/prometheus/common v0.49.0 // indirect
|
||||||
|
github.com/prometheus/procfs v0.12.0 // indirect
|
||||||
|
github.com/shopspring/decimal v1.3.1 // indirect
|
||||||
|
github.com/tklauser/numcpus v0.7.0 // indirect
|
||||||
|
golang.org/x/crypto v0.21.0 // indirect
|
||||||
|
golang.org/x/net v0.22.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.33.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
231
go.sum
231
go.sum
@@ -1,145 +1,120 @@
|
|||||||
github.com/NVIDIA/go-nvml v0.11.1-0 h1:XHSz3zZKC4NCP2ja1rI7++DXFhA+uDhdYa3MykCTGHY=
|
github.com/ClusterCockpit/cc-energy-manager v0.0.0-20240709142550-dd446f7ab900 h1:6+WNav16uWTEDC09hkZKEHfBhtc91p/ZcjgCtyntuIg=
|
||||||
github.com/NVIDIA/go-nvml v0.11.1-0/go.mod h1:hy7HYeQy335x6nEss0Ne3PYqleRa6Ct+VKD9RQ4nyFs=
|
github.com/ClusterCockpit/cc-energy-manager v0.0.0-20240709142550-dd446f7ab900/go.mod h1:EbYeC5t+Y0kW1Q1pP2n9zMqbeYEJITG8YGvAUihXVn4=
|
||||||
github.com/PaesslerAG/gval v1.1.2 h1:EROKxV4/fAKWb0Qoj7NOxmHZA7gcpjOV9XgiRZMRCUU=
|
github.com/ClusterCockpit/cc-units v0.4.0 h1:zP5DOu99GmErW0tCDf0gcLrlWt42RQ9dpoONEOh4cI0=
|
||||||
github.com/PaesslerAG/gval v1.1.2/go.mod h1:Fa8gfkCmUsELXgayr8sfL/sw+VzCVoa03dcOcR/if2w=
|
github.com/ClusterCockpit/cc-units v0.4.0/go.mod h1:3S3PAhAayS3pbgcT4q9Vn9VJw22Op51X0YimtG77zBw=
|
||||||
|
github.com/ClusterCockpit/go-rocm-smi v0.3.0 h1:1qZnSpG7/NyLtc7AjqnUL9Jb8xtqG1nMVgp69rJfaR8=
|
||||||
|
github.com/ClusterCockpit/go-rocm-smi v0.3.0/go.mod h1:+I3UMeX3OlizXDf1WpGD43W4KGZZGVSGmny6rTeOnWA=
|
||||||
|
github.com/NVIDIA/go-nvml v0.11.6-0/go.mod h1:hy7HYeQy335x6nEss0Ne3PYqleRa6Ct+VKD9RQ4nyFs=
|
||||||
|
github.com/NVIDIA/go-nvml v0.12.0-2 h1:Sg239yy7jmopu/cuvYauoMj9fOpcGMngxVxxS1EBXeY=
|
||||||
|
github.com/NVIDIA/go-nvml v0.12.0-2/go.mod h1:7ruy85eOM73muOc/I37euONSwEyFqZsv5ED9AogD4G0=
|
||||||
|
github.com/PaesslerAG/gval v1.2.2 h1:Y7iBzhgE09IGTt5QgGQ2IdaYYYOU134YGHBThD+wm9E=
|
||||||
|
github.com/PaesslerAG/gval v1.2.2/go.mod h1:XRFLwvmkTEdYziLdaCeCa5ImcGVrfQbeNUbVR+C6xac=
|
||||||
|
github.com/PaesslerAG/jsonpath v0.1.0 h1:gADYeifvlqK3R3i2cR5B4DGgxLXIPb3TRTH1mGi0jPI=
|
||||||
github.com/PaesslerAG/jsonpath v0.1.0/go.mod h1:4BzmtoM/PI8fPO4aQGIusjGxGir2BzcV0grWtFzq1Y8=
|
github.com/PaesslerAG/jsonpath v0.1.0/go.mod h1:4BzmtoM/PI8fPO4aQGIusjGxGir2BzcV0grWtFzq1Y8=
|
||||||
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
|
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
|
||||||
|
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
|
||||||
|
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
|
||||||
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
|
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
|
||||||
|
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||||
|
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/deepmap/oapi-codegen v1.8.2 h1:SegyeYGcdi0jLLrpbCMoJxnUUn8GBXHsvr4rbzjuhfU=
|
github.com/expr-lang/expr v1.16.9 h1:WUAzmR0JNI9JCiF0/ewwHB1gmcGw5wW7nWt8gc6PpCI=
|
||||||
github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRktEqrX88CvjIw=
|
github.com/expr-lang/expr v1.16.9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/frankban/quicktest v1.11.0/go.mod h1:K+q6oSqb0W0Ininfk863uOk1lMy69l/P6txr3mVT54s=
|
||||||
github.com/getkin/kin-openapi v0.61.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4=
|
github.com/frankban/quicktest v1.11.2/go.mod h1:K+q6oSqb0W0Ininfk863uOk1lMy69l/P6txr3mVT54s=
|
||||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
github.com/frankban/quicktest v1.13.0 h1:yNZif1OkDfNoDfb9zZa9aXIpejNR4F23Wely0c+Qdqk=
|
||||||
github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs=
|
github.com/frankban/quicktest v1.13.0/go.mod h1:qLE0fzW0VuyUAJgPU19zByoIr0HtCHN/r/VLSOOIySU=
|
||||||
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
|
||||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
|
||||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
|
||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
|
||||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
|
||||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
|
||||||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
|
||||||
github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219/go.mod h1:/X8TswGSh1pIozq4ZwCfxS0WA5JGXguxk94ar/4c87Y=
|
|
||||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
|
||||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
github.com/influxdata/influxdb-client-go/v2 v2.7.0 h1:QgP5mlBE9sGnzplpnf96pr+p7uqlIlL4W2GAP3n+XZg=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/influxdata/influxdb-client-go/v2 v2.7.0/go.mod h1:Y/0W1+TZir7ypoQZYd2IrnVOKB3Tq6oegAQeSVN/+EU=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
||||||
|
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
||||||
|
github.com/influxdata/influxdb-client-go/v2 v2.13.0 h1:ioBbLmR5NMbAjP4UVA5r9b5xGjpABD7j65pI8kFphDM=
|
||||||
|
github.com/influxdata/influxdb-client-go/v2 v2.13.0/go.mod h1:k+spCbt9hcvqvUiz0sr5D8LolXHqAAOfPw9v/RIRHl4=
|
||||||
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf h1:7JTmneyiNEwVBOHSjoMxiWAqB992atOeepeFYegn5RU=
|
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf h1:7JTmneyiNEwVBOHSjoMxiWAqB992atOeepeFYegn5RU=
|
||||||
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
|
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
|
||||||
github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s=
|
github.com/influxdata/line-protocol-corpus v0.0.0-20210519164801-ca6fa5da0184/go.mod h1:03nmhxzZ7Xk2pdG+lmMd7mHDfeVOYFyhOgwO61qWU98=
|
||||||
github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
|
github.com/influxdata/line-protocol-corpus v0.0.0-20210922080147-aa28ccfb8937 h1:MHJNQ+p99hFATQm6ORoLmpUCF7ovjwEFshs/NHzAbig=
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
github.com/influxdata/line-protocol-corpus v0.0.0-20210922080147-aa28ccfb8937/go.mod h1:BKR9c0uHSmRgM/se9JhFHtTT7JTO67X23MtKMHtZcpo=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/influxdata/line-protocol/v2 v2.0.0-20210312151457-c52fdecb625a/go.mod h1:6+9Xt5Sq1rWx+glMgxhcg2c0DUaehK+5TDcPZ76GypY=
|
||||||
|
github.com/influxdata/line-protocol/v2 v2.1.0/go.mod h1:QKw43hdUBg3GTk2iC3iyCxksNj7PX9aUSeYOYE/ceHY=
|
||||||
|
github.com/influxdata/line-protocol/v2 v2.2.1 h1:EAPkqJ9Km4uAxtMRgUubJyqAr6zgWM0dznKMLRauQRE=
|
||||||
|
github.com/influxdata/line-protocol/v2 v2.2.1/go.mod h1:DmB3Cnh+3oxmG6LOBIxce4oaL4CPj3OmMPgvauXh+tM=
|
||||||
|
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
|
||||||
|
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
|
||||||
|
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||||
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
github.com/nats-io/nats.go v1.36.0 h1:suEUPuWzTSse/XhESwqLxXGuj8vGRuPRoG7MoRN/qyU=
|
||||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
github.com/nats-io/nats.go v1.36.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8=
|
||||||
github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ=
|
github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
|
||||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
|
||||||
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
|
||||||
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
|
||||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
|
||||||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
|
||||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
|
||||||
github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0=
|
|
||||||
github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
|
|
||||||
github.com/nats-io/jwt/v2 v2.2.1-0.20220113022732-58e87895b296 h1:vU9tpM3apjYlLLeY23zRWJ9Zktr5jp+mloR942LEOpY=
|
|
||||||
github.com/nats-io/jwt/v2 v2.2.1-0.20220113022732-58e87895b296/go.mod h1:0tqz9Hlu6bCBFLWAASKhE5vUA4c24L9KPUUgvwumE/k=
|
|
||||||
github.com/nats-io/nats-server/v2 v2.7.0 h1:UpqcAM93FI7AHlCyI2FD5QcV3QuHNCauQF2LBVU0238=
|
|
||||||
github.com/nats-io/nats-server/v2 v2.7.0/go.mod h1:cjxtMhZsZovK1XS2iiapCduR8HuqB/YpFamL0qntIcw=
|
|
||||||
github.com/nats-io/nats.go v1.13.1-0.20211122170419-d7c1d78a50fc h1:SHr4MUUZJ/fAC0uSm2OzWOJYsHpapmR86mpw7q1qPXU=
|
|
||||||
github.com/nats-io/nats.go v1.13.1-0.20211122170419-d7c1d78a50fc/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
|
|
||||||
github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
|
|
||||||
github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
|
|
||||||
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
||||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
|
||||||
|
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
|
||||||
|
github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos=
|
||||||
|
github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8=
|
||||||
|
github.com/prometheus/common v0.49.0 h1:ToNTdK4zSnPVJmh698mGFkDor9wBI/iGaJy5dbH1EgI=
|
||||||
|
github.com/prometheus/common v0.49.0/go.mod h1:Kxm+EULxRbUkjGU6WFsQqo3ORzB4tyKvlWFOE9mB2sE=
|
||||||
|
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
|
||||||
|
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
|
||||||
|
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||||
|
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||||
|
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
|
||||||
|
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||||
|
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
|
||||||
|
github.com/stmcginnis/gofish v0.15.0 h1:8TG41+lvJk/0Nf8CIIYErxbMlQUy80W0JFRZP3Ld82A=
|
||||||
|
github.com/stmcginnis/gofish v0.15.0/go.mod h1:BLDSFTp8pDlf/xDbLZa+F7f7eW0E/CHCboggsu8CznI=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
github.com/tklauser/go-sysconf v0.3.13 h1:GBUpcahXSpR2xN01jhkNAbTLRk2Yzgggk8IM08lq3r4=
|
||||||
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
github.com/tklauser/go-sysconf v0.3.13/go.mod h1:zwleP4Q4OehZHGn4CYZDipCgg9usW5IJePewFCGVEa0=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
github.com/tklauser/numcpus v0.7.0 h1:yjuerZP127QG9m5Zh/mSO4wqurYil27tHrqwRoRjpr4=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
github.com/tklauser/numcpus v0.7.0/go.mod h1:bb6dMVcj8A42tSE7i32fsIUCbQNllK5iDguyOZRUzAY=
|
||||||
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.design/x/thread v0.0.0-20210122121316-335e9adffdf1 h1:P7S/GeHBAFEZIYp0ePPs2kHXoazz8q2KsyxHyQVGCJg=
|
||||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
golang.design/x/thread v0.0.0-20210122121316-335e9adffdf1/go.mod h1:9CWpnTUmlQkfdpdutA1nNf4iE5lAVt3QZOu0Z6hahBE=
|
||||||
golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
|
||||||
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce h1:Roh6XWxHFKrPgC/EQhVubSAGQ6Ozk6IdxHSzt1mR0EI=
|
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
||||||
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
|
||||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
||||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/sys v0.0.0-20210122093101-04d7465088b8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
|
||||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
|
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=
|
|
||||||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
|
||||||
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
|
||||||
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 h1:GZokNIeuVkl3aZHJchRrr13WCsols02MLUcz1U9is6M=
|
|
||||||
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
|
||||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
|
||||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
|
||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
|
||||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
|
||||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
|
||||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
|
||||||
gopkg.in/Knetic/govaluate.v2 v2.3.0 h1:naJVc9CZlWA8rC8f5mvECJD7jreTrn7FvGXjBthkHJQ=
|
|
||||||
gopkg.in/Knetic/govaluate.v2 v2.3.0/go.mod h1:NW0gr10J8s7aNghEg6uhdxiEaBvc0+8VgJjVViHUKp4=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
# ClusterCockpit metrics
|
|
||||||
|
|
||||||
As described in the [ClusterCockpit specifications](https://github.com/ClusterCockpit/cc-specifications), the whole ClusterCockpit stack uses metrics in the InfluxDB line protocol format. This is also the input and output format for the ClusterCockpit Metric Collector but internally it uses an extended format while processing, named CCMetric.
|
|
||||||
|
|
||||||
It is basically a copy of the [InfluxDB line protocol](https://github.com/influxdata/line-protocol) `MutableMetric` interface with one extension. Besides the tags and fields, it contains a list of meta information (re-using the `Tag` structure of the original protocol):
|
|
||||||
|
|
||||||
```golang
|
|
||||||
type ccMetric struct {
|
|
||||||
name string // same as
|
|
||||||
tags []*influx.Tag // original
|
|
||||||
fields []*influx.Field // Influx
|
|
||||||
tm time.Time // line-protocol
|
|
||||||
meta []*influx.Tag
|
|
||||||
}
|
|
||||||
|
|
||||||
type CCMetric interface {
|
|
||||||
influx.MutableMetric // the same functions as defined by influx.MutableMetric
|
|
||||||
RemoveTag(key string) // this is not published by the original influx.MutableMetric
|
|
||||||
Meta() map[string]string
|
|
||||||
MetaList() []*inlux.Tag
|
|
||||||
AddMeta(key, value string)
|
|
||||||
HasMeta(key string) bool
|
|
||||||
GetMeta(key string) (string, bool)
|
|
||||||
RemoveMeta(key string)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The `CCMetric` interface provides the same functions as the `MutableMetric` like `{Add, Remove, Has}{Tag, Field}` and additionally provides `{Add, Remove, Has}Meta`.
|
|
||||||
|
|
||||||
The InfluxDB protocol creates a new metric with `influx.New(name, tags, fields, time)` while CCMetric uses `ccMetric.New(name, tags, meta, fields, time)` where `tags` and `meta` are both of type `map[string]string`.
|
|
||||||
|
|
||||||
You can copy a CCMetric with `FromMetric(other CCMetric) CCMetric`. If you get an `influx.Metric` from a function, like the line protocol parser, you can use `FromInfluxMetric(other influx.Metric) CCMetric` to get a CCMetric out of it (see `NatsReceiver` for an example).
|
|
||||||
@@ -1,422 +0,0 @@
|
|||||||
package ccTopology
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
cclogger "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
|
||||||
)
|
|
||||||
|
|
||||||
const SYSFS_NUMABASE = `/sys/devices/system/node`
|
|
||||||
const SYSFS_CPUBASE = `/sys/devices/system/cpu`
|
|
||||||
const PROCFS_CPUINFO = `/proc/cpuinfo`
|
|
||||||
|
|
||||||
// intArrayContains scans an array of ints if the value str is present in the array
|
|
||||||
// If the specified value is found, the corresponding array index is returned.
|
|
||||||
// The bool value is used to signal success or failure
|
|
||||||
func intArrayContains(array []int, str int) (int, bool) {
|
|
||||||
for i, a := range array {
|
|
||||||
if a == str {
|
|
||||||
return i, true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1, false
|
|
||||||
}
|
|
||||||
|
|
||||||
func fileToInt(path string) int {
|
|
||||||
buffer, err := ioutil.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
cclogger.ComponentError("ccTopology", "Reading", path, ":", err.Error())
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
sbuffer := strings.Replace(string(buffer), "\n", "", -1)
|
|
||||||
var id int64
|
|
||||||
//_, err = fmt.Scanf("%d", sbuffer, &id)
|
|
||||||
id, err = strconv.ParseInt(sbuffer, 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
cclogger.ComponentError("ccTopology", "Parsing", path, ":", sbuffer, err.Error())
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
return int(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
func SocketList() []int {
|
|
||||||
buffer, err := ioutil.ReadFile(string(PROCFS_CPUINFO))
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
ll := strings.Split(string(buffer), "\n")
|
|
||||||
var packs []int
|
|
||||||
for _, line := range ll {
|
|
||||||
if strings.HasPrefix(line, "physical id") {
|
|
||||||
lv := strings.Fields(line)
|
|
||||||
id, err := strconv.ParseInt(lv[3], 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return packs
|
|
||||||
}
|
|
||||||
_, found := intArrayContains(packs, int(id))
|
|
||||||
if !found {
|
|
||||||
packs = append(packs, int(id))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return packs
|
|
||||||
}
|
|
||||||
|
|
||||||
func CpuList() []int {
|
|
||||||
buffer, err := ioutil.ReadFile(string(PROCFS_CPUINFO))
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
ll := strings.Split(string(buffer), "\n")
|
|
||||||
cpulist := make([]int, 0)
|
|
||||||
for _, line := range ll {
|
|
||||||
if strings.HasPrefix(line, "processor") {
|
|
||||||
lv := strings.Fields(line)
|
|
||||||
id, err := strconv.ParseInt(lv[2], 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return cpulist
|
|
||||||
}
|
|
||||||
_, found := intArrayContains(cpulist, int(id))
|
|
||||||
if !found {
|
|
||||||
cpulist = append(cpulist, int(id))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cpulist
|
|
||||||
}
|
|
||||||
|
|
||||||
func CoreList() []int {
|
|
||||||
buffer, err := ioutil.ReadFile(string(PROCFS_CPUINFO))
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
ll := strings.Split(string(buffer), "\n")
|
|
||||||
corelist := make([]int, 0)
|
|
||||||
for _, line := range ll {
|
|
||||||
if strings.HasPrefix(line, "core id") {
|
|
||||||
lv := strings.Fields(line)
|
|
||||||
id, err := strconv.ParseInt(lv[3], 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return corelist
|
|
||||||
}
|
|
||||||
_, found := intArrayContains(corelist, int(id))
|
|
||||||
if !found {
|
|
||||||
corelist = append(corelist, int(id))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return corelist
|
|
||||||
}
|
|
||||||
|
|
||||||
func NumaNodeList() []int {
|
|
||||||
numaList := make([]int, 0)
|
|
||||||
globPath := filepath.Join(string(SYSFS_NUMABASE), "node*")
|
|
||||||
regexPath := filepath.Join(string(SYSFS_NUMABASE), "node(\\d+)")
|
|
||||||
regex := regexp.MustCompile(regexPath)
|
|
||||||
files, err := filepath.Glob(globPath)
|
|
||||||
if err != nil {
|
|
||||||
cclogger.ComponentError("CCTopology", "NumaNodeList", err.Error())
|
|
||||||
}
|
|
||||||
for _, f := range files {
|
|
||||||
if !regex.MatchString(f) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
finfo, err := os.Lstat(f)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !finfo.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
matches := regex.FindStringSubmatch(f)
|
|
||||||
if len(matches) == 2 {
|
|
||||||
id, err := strconv.Atoi(matches[1])
|
|
||||||
if err == nil {
|
|
||||||
if _, found := intArrayContains(numaList, id); !found {
|
|
||||||
numaList = append(numaList, id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return numaList
|
|
||||||
}
|
|
||||||
|
|
||||||
func DieList() []int {
|
|
||||||
cpulist := CpuList()
|
|
||||||
dielist := make([]int, 0)
|
|
||||||
for _, c := range cpulist {
|
|
||||||
diepath := filepath.Join(string(SYSFS_CPUBASE), fmt.Sprintf("cpu%d", c), "topology/die_id")
|
|
||||||
dieid := fileToInt(diepath)
|
|
||||||
if dieid > 0 {
|
|
||||||
_, found := intArrayContains(dielist, int(dieid))
|
|
||||||
if !found {
|
|
||||||
dielist = append(dielist, int(dieid))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dielist
|
|
||||||
}
|
|
||||||
|
|
||||||
type CpuEntry struct {
|
|
||||||
Cpuid int
|
|
||||||
SMT int
|
|
||||||
Core int
|
|
||||||
Socket int
|
|
||||||
Numadomain int
|
|
||||||
Die int
|
|
||||||
}
|
|
||||||
|
|
||||||
func CpuData() []CpuEntry {
|
|
||||||
|
|
||||||
fileToInt := func(path string) int {
|
|
||||||
buffer, err := ioutil.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
//cclogger.ComponentError("ccTopology", "Reading", path, ":", err.Error())
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
sbuffer := strings.Replace(string(buffer), "\n", "", -1)
|
|
||||||
var id int64
|
|
||||||
//_, err = fmt.Scanf("%d", sbuffer, &id)
|
|
||||||
id, err = strconv.ParseInt(sbuffer, 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
cclogger.ComponentError("ccTopology", "Parsing", path, ":", sbuffer, err.Error())
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
return int(id)
|
|
||||||
}
|
|
||||||
getCore := func(basepath string) int {
|
|
||||||
return fileToInt(fmt.Sprintf("%s/core_id", basepath))
|
|
||||||
}
|
|
||||||
|
|
||||||
getSocket := func(basepath string) int {
|
|
||||||
return fileToInt(fmt.Sprintf("%s/physical_package_id", basepath))
|
|
||||||
}
|
|
||||||
|
|
||||||
getDie := func(basepath string) int {
|
|
||||||
return fileToInt(fmt.Sprintf("%s/die_id", basepath))
|
|
||||||
}
|
|
||||||
|
|
||||||
getSMT := func(cpuid int, basepath string) int {
|
|
||||||
buffer, err := ioutil.ReadFile(fmt.Sprintf("%s/thread_siblings_list", basepath))
|
|
||||||
if err != nil {
|
|
||||||
cclogger.ComponentError("CCTopology", "CpuData:getSMT", err.Error())
|
|
||||||
}
|
|
||||||
threadlist := make([]int, 0)
|
|
||||||
sbuffer := strings.Replace(string(buffer), "\n", "", -1)
|
|
||||||
for _, x := range strings.Split(sbuffer, ",") {
|
|
||||||
id, err := strconv.ParseInt(x, 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
cclogger.ComponentError("CCTopology", "CpuData:getSMT", err.Error())
|
|
||||||
}
|
|
||||||
threadlist = append(threadlist, int(id))
|
|
||||||
}
|
|
||||||
for i, x := range threadlist {
|
|
||||||
if x == cpuid {
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
getNumaDomain := func(basepath string) int {
|
|
||||||
globPath := filepath.Join(basepath, "node*")
|
|
||||||
regexPath := filepath.Join(basepath, "node(\\d+)")
|
|
||||||
regex := regexp.MustCompile(regexPath)
|
|
||||||
files, err := filepath.Glob(globPath)
|
|
||||||
if err != nil {
|
|
||||||
cclogger.ComponentError("CCTopology", "CpuData:getNumaDomain", err.Error())
|
|
||||||
}
|
|
||||||
for _, f := range files {
|
|
||||||
finfo, err := os.Lstat(f)
|
|
||||||
if err == nil && finfo.IsDir() {
|
|
||||||
matches := regex.FindStringSubmatch(f)
|
|
||||||
if len(matches) == 2 {
|
|
||||||
id, err := strconv.Atoi(matches[1])
|
|
||||||
if err == nil {
|
|
||||||
return id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
clist := make([]CpuEntry, 0)
|
|
||||||
for _, c := range CpuList() {
|
|
||||||
clist = append(clist, CpuEntry{Cpuid: c})
|
|
||||||
}
|
|
||||||
for _, centry := range clist {
|
|
||||||
centry.Socket = -1
|
|
||||||
centry.Numadomain = -1
|
|
||||||
centry.Die = -1
|
|
||||||
centry.Core = -1
|
|
||||||
// Set base directory for topology lookup
|
|
||||||
cpustr := fmt.Sprintf("cpu%d", centry.Cpuid)
|
|
||||||
base := filepath.Join("/sys/devices/system/cpu", cpustr)
|
|
||||||
topoBase := filepath.Join(base, "topology")
|
|
||||||
|
|
||||||
// Lookup CPU core id
|
|
||||||
centry.Core = getCore(topoBase)
|
|
||||||
|
|
||||||
// Lookup CPU socket id
|
|
||||||
centry.Socket = getSocket(topoBase)
|
|
||||||
|
|
||||||
// Lookup CPU die id
|
|
||||||
centry.Die = getDie(topoBase)
|
|
||||||
if centry.Die < 0 {
|
|
||||||
centry.Die = centry.Socket
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lookup SMT thread id
|
|
||||||
centry.SMT = getSMT(centry.Cpuid, topoBase)
|
|
||||||
|
|
||||||
// Lookup NUMA domain id
|
|
||||||
centry.Numadomain = getNumaDomain(base)
|
|
||||||
|
|
||||||
}
|
|
||||||
return clist
|
|
||||||
}
|
|
||||||
|
|
||||||
type CpuInformation struct {
|
|
||||||
NumHWthreads int
|
|
||||||
SMTWidth int
|
|
||||||
NumSockets int
|
|
||||||
NumDies int
|
|
||||||
NumCores int
|
|
||||||
NumNumaDomains int
|
|
||||||
}
|
|
||||||
|
|
||||||
func CpuInfo() CpuInformation {
|
|
||||||
var c CpuInformation
|
|
||||||
|
|
||||||
smtList := make([]int, 0)
|
|
||||||
numaList := make([]int, 0)
|
|
||||||
dieList := make([]int, 0)
|
|
||||||
socketList := make([]int, 0)
|
|
||||||
coreList := make([]int, 0)
|
|
||||||
cdata := CpuData()
|
|
||||||
for _, d := range cdata {
|
|
||||||
if _, ok := intArrayContains(smtList, d.SMT); !ok {
|
|
||||||
smtList = append(smtList, d.SMT)
|
|
||||||
}
|
|
||||||
if _, ok := intArrayContains(numaList, d.Numadomain); !ok {
|
|
||||||
numaList = append(numaList, d.Numadomain)
|
|
||||||
}
|
|
||||||
if _, ok := intArrayContains(dieList, d.Die); !ok {
|
|
||||||
dieList = append(dieList, d.Die)
|
|
||||||
}
|
|
||||||
if _, ok := intArrayContains(socketList, d.Socket); !ok {
|
|
||||||
socketList = append(socketList, d.Socket)
|
|
||||||
}
|
|
||||||
if _, ok := intArrayContains(coreList, d.Core); !ok {
|
|
||||||
coreList = append(coreList, d.Core)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.NumNumaDomains = len(numaList)
|
|
||||||
c.SMTWidth = len(smtList)
|
|
||||||
c.NumDies = len(dieList)
|
|
||||||
c.NumCores = len(coreList)
|
|
||||||
c.NumSockets = len(socketList)
|
|
||||||
c.NumHWthreads = len(cdata)
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCpuSocket(cpuid int) int {
|
|
||||||
cdata := CpuData()
|
|
||||||
for _, d := range cdata {
|
|
||||||
if d.Cpuid == cpuid {
|
|
||||||
return d.Socket
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCpuNumaDomain(cpuid int) int {
|
|
||||||
cdata := CpuData()
|
|
||||||
for _, d := range cdata {
|
|
||||||
if d.Cpuid == cpuid {
|
|
||||||
return d.Numadomain
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCpuDie(cpuid int) int {
|
|
||||||
cdata := CpuData()
|
|
||||||
for _, d := range cdata {
|
|
||||||
if d.Cpuid == cpuid {
|
|
||||||
return d.Die
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCpuCore(cpuid int) int {
|
|
||||||
cdata := CpuData()
|
|
||||||
for _, d := range cdata {
|
|
||||||
if d.Cpuid == cpuid {
|
|
||||||
return d.Core
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetSocketCpus(socket int) []int {
|
|
||||||
all := CpuData()
|
|
||||||
cpulist := make([]int, 0)
|
|
||||||
for _, d := range all {
|
|
||||||
if d.Socket == socket {
|
|
||||||
cpulist = append(cpulist, d.Cpuid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cpulist
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetNumaDomainCpus(domain int) []int {
|
|
||||||
all := CpuData()
|
|
||||||
cpulist := make([]int, 0)
|
|
||||||
for _, d := range all {
|
|
||||||
if d.Numadomain == domain {
|
|
||||||
cpulist = append(cpulist, d.Cpuid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cpulist
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetDieCpus(die int) []int {
|
|
||||||
all := CpuData()
|
|
||||||
cpulist := make([]int, 0)
|
|
||||||
for _, d := range all {
|
|
||||||
if d.Die == die {
|
|
||||||
cpulist = append(cpulist, d.Cpuid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cpulist
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCoreCpus(core int) []int {
|
|
||||||
all := CpuData()
|
|
||||||
cpulist := make([]int, 0)
|
|
||||||
for _, d := range all {
|
|
||||||
if d.Core == core {
|
|
||||||
cpulist = append(cpulist, d.Cpuid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cpulist
|
|
||||||
}
|
|
||||||
@@ -9,10 +9,10 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
topo "github.com/ClusterCockpit/cc-metric-collector/internal/ccTopology"
|
topo "github.com/ClusterCockpit/cc-metric-collector/pkg/ccTopology"
|
||||||
|
|
||||||
"github.com/PaesslerAG/gval"
|
"github.com/PaesslerAG/gval"
|
||||||
)
|
)
|
||||||
@@ -31,14 +31,14 @@ type metricAggregator struct {
|
|||||||
functions []*MetricAggregatorIntervalConfig
|
functions []*MetricAggregatorIntervalConfig
|
||||||
constants map[string]interface{}
|
constants map[string]interface{}
|
||||||
language gval.Language
|
language gval.Language
|
||||||
output chan lp.CCMetric
|
output chan lp.CCMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
type MetricAggregator interface {
|
type MetricAggregator interface {
|
||||||
AddAggregation(name, function, condition string, tags, meta map[string]string) error
|
AddAggregation(name, function, condition string, tags, meta map[string]string) error
|
||||||
DeleteAggregation(name string) error
|
DeleteAggregation(name string) error
|
||||||
Init(output chan lp.CCMetric) error
|
Init(output chan lp.CCMessage) error
|
||||||
Eval(starttime time.Time, endtime time.Time, metrics []lp.CCMetric)
|
Eval(starttime time.Time, endtime time.Time, metrics []lp.CCMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
var metricCacheLanguage = gval.NewLanguage(
|
var metricCacheLanguage = gval.NewLanguage(
|
||||||
@@ -74,7 +74,7 @@ var evaluables = struct {
|
|||||||
mapping: make(map[string]gval.Evaluable),
|
mapping: make(map[string]gval.Evaluable),
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *metricAggregator) Init(output chan lp.CCMetric) error {
|
func (c *metricAggregator) Init(output chan lp.CCMessage) error {
|
||||||
c.output = output
|
c.output = output
|
||||||
c.functions = make([]*MetricAggregatorIntervalConfig, 0)
|
c.functions = make([]*MetricAggregatorIntervalConfig, 0)
|
||||||
c.constants = make(map[string]interface{})
|
c.constants = make(map[string]interface{})
|
||||||
@@ -112,7 +112,7 @@ func (c *metricAggregator) Init(output chan lp.CCMetric) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *metricAggregator) Eval(starttime time.Time, endtime time.Time, metrics []lp.CCMetric) {
|
func (c *metricAggregator) Eval(starttime time.Time, endtime time.Time, metrics []lp.CCMessage) {
|
||||||
vars := make(map[string]interface{})
|
vars := make(map[string]interface{})
|
||||||
for k, v := range c.constants {
|
for k, v := range c.constants {
|
||||||
vars[k] = v
|
vars[k] = v
|
||||||
@@ -121,8 +121,13 @@ func (c *metricAggregator) Eval(starttime time.Time, endtime time.Time, metrics
|
|||||||
vars["endtime"] = endtime
|
vars["endtime"] = endtime
|
||||||
for _, f := range c.functions {
|
for _, f := range c.functions {
|
||||||
cclog.ComponentDebug("MetricCache", "COLLECT", f.Name, "COND", f.Condition)
|
cclog.ComponentDebug("MetricCache", "COLLECT", f.Name, "COND", f.Condition)
|
||||||
values := make([]float64, 0)
|
var valuesFloat64 []float64
|
||||||
matches := make([]lp.CCMetric, 0)
|
var valuesFloat32 []float32
|
||||||
|
var valuesInt []int
|
||||||
|
var valuesInt32 []int32
|
||||||
|
var valuesInt64 []int64
|
||||||
|
var valuesBool []bool
|
||||||
|
matches := make([]lp.CCMessage, 0)
|
||||||
for _, m := range metrics {
|
for _, m := range metrics {
|
||||||
vars["metric"] = m
|
vars["metric"] = m
|
||||||
//value, err := gval.Evaluate(f.Condition, vars, c.language)
|
//value, err := gval.Evaluate(f.Condition, vars, c.language)
|
||||||
@@ -136,17 +141,17 @@ func (c *metricAggregator) Eval(starttime time.Time, endtime time.Time, metrics
|
|||||||
if valid {
|
if valid {
|
||||||
switch x := v.(type) {
|
switch x := v.(type) {
|
||||||
case float64:
|
case float64:
|
||||||
values = append(values, x)
|
valuesFloat64 = append(valuesFloat64, x)
|
||||||
case float32:
|
case float32:
|
||||||
|
valuesFloat32 = append(valuesFloat32, x)
|
||||||
case int:
|
case int:
|
||||||
|
valuesInt = append(valuesInt, x)
|
||||||
|
case int32:
|
||||||
|
valuesInt32 = append(valuesInt32, x)
|
||||||
case int64:
|
case int64:
|
||||||
values = append(values, float64(x))
|
valuesInt64 = append(valuesInt64, x)
|
||||||
case bool:
|
case bool:
|
||||||
if x {
|
valuesBool = append(valuesBool, x)
|
||||||
values = append(values, float64(1.0))
|
|
||||||
} else {
|
|
||||||
values = append(values, float64(0.0))
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
cclog.ComponentError("MetricCache", "COLLECT ADD VALUE", v, "FAILED")
|
cclog.ComponentError("MetricCache", "COLLECT ADD VALUE", v, "FAILED")
|
||||||
}
|
}
|
||||||
@@ -155,17 +160,63 @@ func (c *metricAggregator) Eval(starttime time.Time, endtime time.Time, metrics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete(vars, "metric")
|
delete(vars, "metric")
|
||||||
cclog.ComponentDebug("MetricCache", "EVALUATE", f.Name, "METRICS", len(values), "CALC", f.Function)
|
|
||||||
vars["values"] = values
|
// Check, that only values of one type were collected
|
||||||
|
countValueTypes := 0
|
||||||
|
if len(valuesFloat64) > 0 {
|
||||||
|
countValueTypes += 1
|
||||||
|
}
|
||||||
|
if len(valuesFloat32) > 0 {
|
||||||
|
countValueTypes += 1
|
||||||
|
}
|
||||||
|
if len(valuesInt) > 0 {
|
||||||
|
countValueTypes += 1
|
||||||
|
}
|
||||||
|
if len(valuesInt32) > 0 {
|
||||||
|
countValueTypes += 1
|
||||||
|
}
|
||||||
|
if len(valuesInt64) > 0 {
|
||||||
|
countValueTypes += 1
|
||||||
|
}
|
||||||
|
if len(valuesBool) > 0 {
|
||||||
|
countValueTypes += 1
|
||||||
|
}
|
||||||
|
if countValueTypes > 1 {
|
||||||
|
cclog.ComponentError("MetricCache", "Collected values of different types")
|
||||||
|
}
|
||||||
|
|
||||||
|
var len_values int
|
||||||
|
switch {
|
||||||
|
case len(valuesFloat64) > 0:
|
||||||
|
vars["values"] = valuesFloat64
|
||||||
|
len_values = len(valuesFloat64)
|
||||||
|
case len(valuesFloat32) > 0:
|
||||||
|
vars["values"] = valuesFloat32
|
||||||
|
len_values = len(valuesFloat32)
|
||||||
|
case len(valuesInt) > 0:
|
||||||
|
vars["values"] = valuesInt
|
||||||
|
len_values = len(valuesInt)
|
||||||
|
case len(valuesInt32) > 0:
|
||||||
|
vars["values"] = valuesInt32
|
||||||
|
len_values = len(valuesInt32)
|
||||||
|
case len(valuesInt64) > 0:
|
||||||
|
vars["values"] = valuesInt64
|
||||||
|
len_values = len(valuesInt64)
|
||||||
|
case len(valuesBool) > 0:
|
||||||
|
vars["values"] = valuesBool
|
||||||
|
len_values = len(valuesBool)
|
||||||
|
}
|
||||||
|
cclog.ComponentDebug("MetricCache", "EVALUATE", f.Name, "METRICS", len_values, "CALC", f.Function)
|
||||||
|
|
||||||
vars["metrics"] = matches
|
vars["metrics"] = matches
|
||||||
if len(values) > 0 {
|
if len_values > 0 {
|
||||||
value, err := gval.Evaluate(f.Function, vars, c.language)
|
value, err := gval.Evaluate(f.Function, vars, c.language)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.ComponentError("MetricCache", "EVALUATE", f.Name, "METRICS", len(values), "CALC", f.Function, ":", err.Error())
|
cclog.ComponentError("MetricCache", "EVALUATE", f.Name, "METRICS", len_values, "CALC", f.Function, ":", err.Error())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_tags := func(tags map[string]string, metrics []lp.CCMetric) map[string]string {
|
copy_tags := func(tags map[string]string, metrics []lp.CCMessage) map[string]string {
|
||||||
out := make(map[string]string)
|
out := make(map[string]string)
|
||||||
for key, value := range tags {
|
for key, value := range tags {
|
||||||
switch value {
|
switch value {
|
||||||
@@ -182,7 +233,7 @@ func (c *metricAggregator) Eval(starttime time.Time, endtime time.Time, metrics
|
|||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
copy_meta := func(meta map[string]string, metrics []lp.CCMetric) map[string]string {
|
copy_meta := func(meta map[string]string, metrics []lp.CCMessage) map[string]string {
|
||||||
out := make(map[string]string)
|
out := make(map[string]string)
|
||||||
for key, value := range meta {
|
for key, value := range meta {
|
||||||
switch value {
|
switch value {
|
||||||
@@ -202,18 +253,18 @@ func (c *metricAggregator) Eval(starttime time.Time, endtime time.Time, metrics
|
|||||||
tags := copy_tags(f.Tags, matches)
|
tags := copy_tags(f.Tags, matches)
|
||||||
meta := copy_meta(f.Meta, matches)
|
meta := copy_meta(f.Meta, matches)
|
||||||
|
|
||||||
var m lp.CCMetric
|
var m lp.CCMessage
|
||||||
switch t := value.(type) {
|
switch t := value.(type) {
|
||||||
case float64:
|
case float64:
|
||||||
m, err = lp.New(f.Name, tags, meta, map[string]interface{}{"value": t}, starttime)
|
m, err = lp.NewMessage(f.Name, tags, meta, map[string]interface{}{"value": t}, starttime)
|
||||||
case float32:
|
case float32:
|
||||||
m, err = lp.New(f.Name, tags, meta, map[string]interface{}{"value": t}, starttime)
|
m, err = lp.NewMessage(f.Name, tags, meta, map[string]interface{}{"value": t}, starttime)
|
||||||
case int:
|
case int:
|
||||||
m, err = lp.New(f.Name, tags, meta, map[string]interface{}{"value": t}, starttime)
|
m, err = lp.NewMessage(f.Name, tags, meta, map[string]interface{}{"value": t}, starttime)
|
||||||
case int64:
|
case int64:
|
||||||
m, err = lp.New(f.Name, tags, meta, map[string]interface{}{"value": t}, starttime)
|
m, err = lp.NewMessage(f.Name, tags, meta, map[string]interface{}{"value": t}, starttime)
|
||||||
case string:
|
case string:
|
||||||
m, err = lp.New(f.Name, tags, meta, map[string]interface{}{"value": t}, starttime)
|
m, err = lp.NewMessage(f.Name, tags, meta, map[string]interface{}{"value": t}, starttime)
|
||||||
default:
|
default:
|
||||||
cclog.ComponentError("MetricCache", "Gval returned invalid type", t, "skipping metric", f.Name)
|
cclog.ComponentError("MetricCache", "Gval returned invalid type", t, "skipping metric", f.Name)
|
||||||
}
|
}
|
||||||
@@ -316,7 +367,7 @@ func EvalBoolCondition(condition string, params map[string]interface{}) (bool, e
|
|||||||
return value, err
|
return value, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func EvalFloat64Condition(condition string, params map[string]interface{}) (float64, error) {
|
func EvalFloat64Condition(condition string, params map[string]float64) (float64, error) {
|
||||||
evaluables.mutex.Lock()
|
evaluables.mutex.Lock()
|
||||||
evaluable, ok := evaluables.mapping[condition]
|
evaluable, ok := evaluables.mapping[condition]
|
||||||
evaluables.mutex.Unlock()
|
evaluables.mutex.Unlock()
|
||||||
@@ -338,7 +389,7 @@ func EvalFloat64Condition(condition string, params map[string]interface{}) (floa
|
|||||||
return value, err
|
return value, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAggregator(output chan lp.CCMetric) (MetricAggregator, error) {
|
func NewAggregator(output chan lp.CCMessage) (MetricAggregator, error) {
|
||||||
a := new(metricAggregator)
|
a := new(metricAggregator)
|
||||||
err := a.Init(output)
|
err := a.Init(output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -3,162 +3,167 @@ package metricAggregator
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
"golang.org/x/exp/slices"
|
||||||
topo "github.com/ClusterCockpit/cc-metric-collector/internal/ccTopology"
|
|
||||||
|
topo "github.com/ClusterCockpit/cc-metric-collector/pkg/ccTopology"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Arithmetic functions on value arrays
|
* Arithmetic functions on value arrays
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Sum up values
|
func sumAnyType[T float64 | float32 | int | int32 | int64](values []T) (T, error) {
|
||||||
func sumfunc(args ...interface{}) (interface{}, error) {
|
if len(values) == 0 {
|
||||||
s := 0.0
|
return 0.0, errors.New("sum function requires at least one argument")
|
||||||
values, ok := args[0].([]float64)
|
|
||||||
if ok {
|
|
||||||
cclog.ComponentDebug("MetricCache", "SUM FUNC START")
|
|
||||||
for _, x := range values {
|
|
||||||
s += x
|
|
||||||
}
|
}
|
||||||
cclog.ComponentDebug("MetricCache", "SUM FUNC END", s)
|
var sum T
|
||||||
} else {
|
for _, value := range values {
|
||||||
cclog.ComponentDebug("MetricCache", "SUM FUNC CAST FAILED")
|
sum += value
|
||||||
}
|
}
|
||||||
return s, nil
|
return sum, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the minimum value
|
// Sum up values
|
||||||
func minfunc(args ...interface{}) (interface{}, error) {
|
func sumfunc(args interface{}) (interface{}, error) {
|
||||||
var err error = nil
|
|
||||||
switch values := args[0].(type) {
|
var err error
|
||||||
|
switch values := args.(type) {
|
||||||
case []float64:
|
case []float64:
|
||||||
var s float64 = math.MaxFloat64
|
return sumAnyType(values)
|
||||||
for _, x := range values {
|
|
||||||
if x < s {
|
|
||||||
s = x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s, nil
|
|
||||||
case []float32:
|
case []float32:
|
||||||
var s float32 = math.MaxFloat32
|
return sumAnyType(values)
|
||||||
for _, x := range values {
|
|
||||||
if x < s {
|
|
||||||
s = x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s, nil
|
|
||||||
case []int:
|
case []int:
|
||||||
var s int = int(math.MaxInt32)
|
return sumAnyType(values)
|
||||||
for _, x := range values {
|
|
||||||
if x < s {
|
|
||||||
s = x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s, nil
|
|
||||||
case []int64:
|
case []int64:
|
||||||
var s int64 = math.MaxInt64
|
return sumAnyType(values)
|
||||||
for _, x := range values {
|
|
||||||
if x < s {
|
|
||||||
s = x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s, nil
|
|
||||||
case []int32:
|
case []int32:
|
||||||
var s int32 = math.MaxInt32
|
return sumAnyType(values)
|
||||||
for _, x := range values {
|
|
||||||
if x < s {
|
|
||||||
s = x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s, nil
|
|
||||||
default:
|
default:
|
||||||
err = errors.New("function 'min' only on list of values (float64, float32, int, int32, int64)")
|
err = errors.New("function 'sum' only on list of values (float64, float32, int, int32, int64)")
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0.0, err
|
return 0.0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the average or mean value
|
func minAnyType[T float64 | float32 | int | int32 | int64](values []T) (T, error) {
|
||||||
func avgfunc(args ...interface{}) (interface{}, error) {
|
if len(values) == 0 {
|
||||||
switch values := args[0].(type) {
|
return 0.0, errors.New("min function requires at least one argument")
|
||||||
|
}
|
||||||
|
return slices.Min(values), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the minimum value
|
||||||
|
func minfunc(args interface{}) (interface{}, error) {
|
||||||
|
switch values := args.(type) {
|
||||||
case []float64:
|
case []float64:
|
||||||
var s float64 = 0
|
return minAnyType(values)
|
||||||
for _, x := range values {
|
|
||||||
s += x
|
|
||||||
}
|
|
||||||
return s / float64(len(values)), nil
|
|
||||||
case []float32:
|
case []float32:
|
||||||
var s float32 = 0
|
return minAnyType(values)
|
||||||
for _, x := range values {
|
|
||||||
s += x
|
|
||||||
}
|
|
||||||
return s / float32(len(values)), nil
|
|
||||||
case []int:
|
case []int:
|
||||||
var s int = 0
|
return minAnyType(values)
|
||||||
for _, x := range values {
|
|
||||||
s += x
|
|
||||||
}
|
|
||||||
return s / len(values), nil
|
|
||||||
case []int64:
|
case []int64:
|
||||||
var s int64 = 0
|
return minAnyType(values)
|
||||||
for _, x := range values {
|
case []int32:
|
||||||
s += x
|
return minAnyType(values)
|
||||||
|
default:
|
||||||
|
return 0.0, errors.New("function 'min' only on list of values (float64, float32, int, int32, int64)")
|
||||||
}
|
}
|
||||||
return s / int64(len(values)), nil
|
}
|
||||||
|
|
||||||
|
func avgAnyType[T float64 | float32 | int | int32 | int64](values []T) (float64, error) {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return 0.0, errors.New("average function requires at least one argument")
|
||||||
}
|
}
|
||||||
return 0.0, nil
|
sum, err := sumAnyType[T](values)
|
||||||
|
return float64(sum) / float64(len(values)), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the average or mean value
|
||||||
|
func avgfunc(args interface{}) (interface{}, error) {
|
||||||
|
switch values := args.(type) {
|
||||||
|
case []float64:
|
||||||
|
return avgAnyType(values)
|
||||||
|
case []float32:
|
||||||
|
return avgAnyType(values)
|
||||||
|
case []int:
|
||||||
|
return avgAnyType(values)
|
||||||
|
case []int64:
|
||||||
|
return avgAnyType(values)
|
||||||
|
case []int32:
|
||||||
|
return avgAnyType(values)
|
||||||
|
default:
|
||||||
|
return 0.0, errors.New("function 'average' only on list of values (float64, float32, int, int32, int64)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func maxAnyType[T float64 | float32 | int | int32 | int64](values []T) (T, error) {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return 0.0, errors.New("max function requires at least one argument")
|
||||||
|
}
|
||||||
|
return slices.Max(values), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the maximum value
|
// Get the maximum value
|
||||||
func maxfunc(args ...interface{}) (interface{}, error) {
|
func maxfunc(args interface{}) (interface{}, error) {
|
||||||
s := 0.0
|
switch values := args.(type) {
|
||||||
values, ok := args[0].([]float64)
|
case []float64:
|
||||||
if ok {
|
return maxAnyType(values)
|
||||||
for _, x := range values {
|
case []float32:
|
||||||
if x > s {
|
return maxAnyType(values)
|
||||||
s = x
|
case []int:
|
||||||
|
return maxAnyType(values)
|
||||||
|
case []int64:
|
||||||
|
return maxAnyType(values)
|
||||||
|
case []int32:
|
||||||
|
return maxAnyType(values)
|
||||||
|
default:
|
||||||
|
return 0.0, errors.New("function 'max' only on list of values (float64, float32, int, int32, int64)")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func medianAnyType[T float64 | float32 | int | int32 | int64](values []T) (T, error) {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return 0.0, errors.New("median function requires at least one argument")
|
||||||
}
|
}
|
||||||
|
slices.Sort(values)
|
||||||
|
var median T
|
||||||
|
if midPoint := len(values) % 2; midPoint == 0 {
|
||||||
|
median = (values[midPoint-1] + values[midPoint]) / 2
|
||||||
|
} else {
|
||||||
|
median = values[midPoint]
|
||||||
}
|
}
|
||||||
return s, nil
|
return median, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the median value
|
// Get the median value
|
||||||
func medianfunc(args ...interface{}) (interface{}, error) {
|
func medianfunc(args interface{}) (interface{}, error) {
|
||||||
switch values := args[0].(type) {
|
switch values := args.(type) {
|
||||||
case []float64:
|
case []float64:
|
||||||
sort.Float64s(values)
|
return medianAnyType(values)
|
||||||
return values[len(values)/2], nil
|
case []float32:
|
||||||
// case []float32:
|
return medianAnyType(values)
|
||||||
// sort.Float64s(values)
|
|
||||||
// return values[len(values)/2], nil
|
|
||||||
case []int:
|
case []int:
|
||||||
sort.Ints(values)
|
return medianAnyType(values)
|
||||||
return values[len(values)/2], nil
|
case []int64:
|
||||||
|
return medianAnyType(values)
|
||||||
// case []int64:
|
case []int32:
|
||||||
// sort.Ints(values)
|
return medianAnyType(values)
|
||||||
// return values[len(values)/2], nil
|
default:
|
||||||
// case []int32:
|
return 0.0, errors.New("function 'median' only on list of values (float64, float32, int, int32, int64)")
|
||||||
// sort.Ints(values)
|
|
||||||
// return values[len(values)/2], nil
|
|
||||||
}
|
}
|
||||||
return 0.0, errors.New("function 'median()' only on lists of type float64 and int")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get number of values in list. Returns always an int
|
* Get number of values in list. Returns always an int
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func lenfunc(args ...interface{}) (interface{}, error) {
|
func lenfunc(args interface{}) (interface{}, error) {
|
||||||
var err error = nil
|
var err error = nil
|
||||||
var length int = 0
|
var length int = 0
|
||||||
switch values := args[0].(type) {
|
switch values := args.(type) {
|
||||||
case []float64:
|
case []float64:
|
||||||
length = len(values)
|
length = len(values)
|
||||||
case []float32:
|
case []float32:
|
||||||
@@ -243,49 +248,49 @@ func matchfunc(args ...interface{}) (interface{}, error) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// for a given cpuid, it returns the core id
|
// for a given cpuid, it returns the core id
|
||||||
func getCpuCoreFunc(args ...interface{}) (interface{}, error) {
|
func getCpuCoreFunc(args interface{}) (interface{}, error) {
|
||||||
switch cpuid := args[0].(type) {
|
switch cpuid := args.(type) {
|
||||||
case int:
|
case int:
|
||||||
return topo.GetCpuCore(cpuid), nil
|
return topo.GetHwthreadCore(cpuid), nil
|
||||||
}
|
}
|
||||||
return -1, errors.New("function 'getCpuCore' accepts only an 'int' cpuid")
|
return -1, errors.New("function 'getCpuCore' accepts only an 'int' cpuid")
|
||||||
}
|
}
|
||||||
|
|
||||||
// for a given cpuid, it returns the socket id
|
// for a given cpuid, it returns the socket id
|
||||||
func getCpuSocketFunc(args ...interface{}) (interface{}, error) {
|
func getCpuSocketFunc(args interface{}) (interface{}, error) {
|
||||||
switch cpuid := args[0].(type) {
|
switch cpuid := args.(type) {
|
||||||
case int:
|
case int:
|
||||||
return topo.GetCpuSocket(cpuid), nil
|
return topo.GetHwthreadSocket(cpuid), nil
|
||||||
}
|
}
|
||||||
return -1, errors.New("function 'getCpuCore' accepts only an 'int' cpuid")
|
return -1, errors.New("function 'getCpuCore' accepts only an 'int' cpuid")
|
||||||
}
|
}
|
||||||
|
|
||||||
// for a given cpuid, it returns the id of the NUMA node
|
// for a given cpuid, it returns the id of the NUMA node
|
||||||
func getCpuNumaDomainFunc(args ...interface{}) (interface{}, error) {
|
func getCpuNumaDomainFunc(args interface{}) (interface{}, error) {
|
||||||
switch cpuid := args[0].(type) {
|
switch cpuid := args.(type) {
|
||||||
case int:
|
case int:
|
||||||
return topo.GetCpuNumaDomain(cpuid), nil
|
return topo.GetHwthreadNumaDomain(cpuid), nil
|
||||||
}
|
}
|
||||||
return -1, errors.New("function 'getCpuNuma' accepts only an 'int' cpuid")
|
return -1, errors.New("function 'getCpuNuma' accepts only an 'int' cpuid")
|
||||||
}
|
}
|
||||||
|
|
||||||
// for a given cpuid, it returns the id of the CPU die
|
// for a given cpuid, it returns the id of the CPU die
|
||||||
func getCpuDieFunc(args ...interface{}) (interface{}, error) {
|
func getCpuDieFunc(args interface{}) (interface{}, error) {
|
||||||
switch cpuid := args[0].(type) {
|
switch cpuid := args.(type) {
|
||||||
case int:
|
case int:
|
||||||
return topo.GetCpuDie(cpuid), nil
|
return topo.GetHwthreadDie(cpuid), nil
|
||||||
}
|
}
|
||||||
return -1, errors.New("function 'getCpuDie' accepts only an 'int' cpuid")
|
return -1, errors.New("function 'getCpuDie' accepts only an 'int' cpuid")
|
||||||
}
|
}
|
||||||
|
|
||||||
// for a given core id, it returns the list of cpuids
|
// for a given core id, it returns the list of cpuids
|
||||||
func getCpuListOfCoreFunc(args ...interface{}) (interface{}, error) {
|
func getCpuListOfCoreFunc(args interface{}) (interface{}, error) {
|
||||||
cpulist := make([]int, 0)
|
cpulist := make([]int, 0)
|
||||||
switch in := args[0].(type) {
|
switch in := args.(type) {
|
||||||
case int:
|
case int:
|
||||||
for _, c := range topo.CpuData() {
|
for _, c := range topo.CpuData() {
|
||||||
if c.Core == in {
|
if c.Core == in {
|
||||||
cpulist = append(cpulist, c.Cpuid)
|
cpulist = append(cpulist, c.CpuID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -293,13 +298,13 @@ func getCpuListOfCoreFunc(args ...interface{}) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// for a given socket id, it returns the list of cpuids
|
// for a given socket id, it returns the list of cpuids
|
||||||
func getCpuListOfSocketFunc(args ...interface{}) (interface{}, error) {
|
func getCpuListOfSocketFunc(args interface{}) (interface{}, error) {
|
||||||
cpulist := make([]int, 0)
|
cpulist := make([]int, 0)
|
||||||
switch in := args[0].(type) {
|
switch in := args.(type) {
|
||||||
case int:
|
case int:
|
||||||
for _, c := range topo.CpuData() {
|
for _, c := range topo.CpuData() {
|
||||||
if c.Socket == in {
|
if c.Socket == in {
|
||||||
cpulist = append(cpulist, c.Cpuid)
|
cpulist = append(cpulist, c.CpuID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -307,13 +312,13 @@ func getCpuListOfSocketFunc(args ...interface{}) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// for a given id of a NUMA domain, it returns the list of cpuids
|
// for a given id of a NUMA domain, it returns the list of cpuids
|
||||||
func getCpuListOfNumaDomainFunc(args ...interface{}) (interface{}, error) {
|
func getCpuListOfNumaDomainFunc(args interface{}) (interface{}, error) {
|
||||||
cpulist := make([]int, 0)
|
cpulist := make([]int, 0)
|
||||||
switch in := args[0].(type) {
|
switch in := args.(type) {
|
||||||
case int:
|
case int:
|
||||||
for _, c := range topo.CpuData() {
|
for _, c := range topo.CpuData() {
|
||||||
if c.Numadomain == in {
|
if c.NumaDomain == in {
|
||||||
cpulist = append(cpulist, c.Cpuid)
|
cpulist = append(cpulist, c.CpuID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -321,13 +326,13 @@ func getCpuListOfNumaDomainFunc(args ...interface{}) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// for a given CPU die id, it returns the list of cpuids
|
// for a given CPU die id, it returns the list of cpuids
|
||||||
func getCpuListOfDieFunc(args ...interface{}) (interface{}, error) {
|
func getCpuListOfDieFunc(args interface{}) (interface{}, error) {
|
||||||
cpulist := make([]int, 0)
|
cpulist := make([]int, 0)
|
||||||
switch in := args[0].(type) {
|
switch in := args.(type) {
|
||||||
case int:
|
case int:
|
||||||
for _, c := range topo.CpuData() {
|
for _, c := range topo.CpuData() {
|
||||||
if c.Die == in {
|
if c.Die == in {
|
||||||
cpulist = append(cpulist, c.Cpuid)
|
cpulist = append(cpulist, c.CpuID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,8 +340,8 @@ func getCpuListOfDieFunc(args ...interface{}) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// wrapper function to get a list of all cpuids of the node
|
// wrapper function to get a list of all cpuids of the node
|
||||||
func getCpuListOfNode(args ...interface{}) (interface{}, error) {
|
func getCpuListOfNode() (interface{}, error) {
|
||||||
return topo.CpuList(), nil
|
return topo.HwthreadList(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to get the cpuid list for a CCMetric type tag set (type and type-id)
|
// helper function to get the cpuid list for a CCMetric type tag set (type and type-id)
|
||||||
@@ -348,14 +353,14 @@ func getCpuListOfType(args ...interface{}) (interface{}, error) {
|
|||||||
case string:
|
case string:
|
||||||
switch typ {
|
switch typ {
|
||||||
case "node":
|
case "node":
|
||||||
return topo.CpuList(), nil
|
return topo.HwthreadList(), nil
|
||||||
case "socket":
|
case "socket":
|
||||||
return getCpuListOfSocketFunc(args[1])
|
return getCpuListOfSocketFunc(args[1])
|
||||||
case "numadomain":
|
case "numadomain":
|
||||||
return getCpuListOfNumaDomainFunc(args[1])
|
return getCpuListOfNumaDomainFunc(args[1])
|
||||||
case "core":
|
case "core":
|
||||||
return getCpuListOfCoreFunc(args[1])
|
return getCpuListOfCoreFunc(args[1])
|
||||||
case "cpu":
|
case "hwthread":
|
||||||
var cpu int
|
var cpu int
|
||||||
|
|
||||||
switch id := args[1].(type) {
|
switch id := args[1].(type) {
|
||||||
|
|||||||
@@ -1,13 +1,21 @@
|
|||||||
# CC Metric Router
|
# CC Metric Router
|
||||||
|
|
||||||
The CCMetric router sits in between the collectors and the sinks and can be used to add and remove tags to/from traversing [CCMetrics](../ccMetric/README.md).
|
The CCMetric router sits in between the collectors and the sinks and can be used to add and remove tags to/from traversing [CCMessages](https://pkg.go.dev/github.com/ClusterCockpit/cc-energy-manager@v0.0.0-20240919152819-92a17f2da4f7/pkg/cc-message.
|
||||||
|
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
|
|
||||||
|
**Note**: Use the [message processor configuration](../../pkg/messageProcessor/README.md) with option `process_messages`.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"num_cache_intervals" : 1,
|
"num_cache_intervals" : 1,
|
||||||
"interval_timestamp" : true,
|
"interval_timestamp" : true,
|
||||||
|
"hostname_tag" : "hostname",
|
||||||
|
"max_forward" : 50,
|
||||||
|
"process_messages": {
|
||||||
|
"see": "pkg/messageProcessor/README.md"
|
||||||
|
},
|
||||||
"add_tags" : [
|
"add_tags" : [
|
||||||
{
|
{
|
||||||
"key" : "cluster",
|
"key" : "cluster",
|
||||||
@@ -50,11 +58,32 @@ The CCMetric router sits in between the collectors and the sinks and can be used
|
|||||||
],
|
],
|
||||||
"rename_metrics" : {
|
"rename_metrics" : {
|
||||||
"metric_12345" : "mymetric"
|
"metric_12345" : "mymetric"
|
||||||
|
},
|
||||||
|
"normalize_units" : true,
|
||||||
|
"change_unit_prefix" : {
|
||||||
|
"mem_used" : "G",
|
||||||
|
"mem_total" : "G"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
There are three main options `add_tags`, `delete_tags` and `interval_timestamp`. `add_tags` and `delete_tags` are lists consisting of dicts with `key`, `value` and `if`. The `value` can be omitted in the `delete_tags` part as it only uses the `key` for removal. The `interval_timestamp` setting means that a unique timestamp is applied to all metrics traversing the router during an interval.
|
There are three main options `add_tags`, `delete_tags` and `interval_timestamp`. `add_tags` and `delete_tags` are lists consisting of dicts with `key`, `value` and `if`. The `value` can be omitted in the `delete_tags` part as it only uses the `key` for removal. The `interval_timestamp` setting means that a unique timestamp is applied to all metrics traversing the router during an interval.
|
||||||
|
|
||||||
|
**Note**: Use the [message processor configuration](../../pkg/messageProcessor/README.md) (option `process_messages`) instead of `add_tags`, `delete_tags`, `drop_metrics`, `drop_metrics_if`, `rename_metrics`, `normalize_units` and `change_unit_prefix`. These options are deprecated and will be removed in future versions. Until then, they are added to the message processor.
|
||||||
|
|
||||||
|
# Processing order in the router
|
||||||
|
|
||||||
|
- Add the `hostname_tag` tag (if sent by collectors or cache)
|
||||||
|
- If `interval_timestamp == true`, change time of metrics
|
||||||
|
- Check if metric should be dropped (`drop_metrics` and `drop_metrics_if`)
|
||||||
|
- Add tags from `add_tags`
|
||||||
|
- Delete tags from `del_tags`
|
||||||
|
- Rename metric based on `rename_metrics` and store old name as `oldname` in meta information
|
||||||
|
- Add tags from `add_tags` (if you used the new name in the `if` condition)
|
||||||
|
- Delete tags from `del_tags` (if you used the new name in the `if` condition)
|
||||||
|
- Send to sinks
|
||||||
|
- Move to cache (if `num_cache_intervals > 0`)
|
||||||
|
|
||||||
# The `interval_timestamp` option
|
# The `interval_timestamp` option
|
||||||
|
|
||||||
The collectors' `Read()` functions are not called simultaneously and therefore the metrics gathered in an interval can have different timestamps. If you want to avoid that and have a common timestamp (the beginning of the interval), set this option to `true` and the MetricRouter sets the time.
|
The collectors' `Read()` functions are not called simultaneously and therefore the metrics gathered in an interval can have different timestamps. If you want to avoid that and have a common timestamp (the beginning of the interval), set this option to `true` and the MetricRouter sets the time.
|
||||||
@@ -65,8 +94,18 @@ If the MetricRouter should buffer metrics of intervals in a MetricCache, this op
|
|||||||
|
|
||||||
A `num_cache_intervals > 0` is required to use the `interval_aggregates` option.
|
A `num_cache_intervals > 0` is required to use the `interval_aggregates` option.
|
||||||
|
|
||||||
|
# The `hostname_tag` option
|
||||||
|
|
||||||
|
By default, the router tags metrics with the hostname for all locally created metrics. The default tag name is `hostname`, but it can be changed if your organization wants anything else
|
||||||
|
|
||||||
|
# The `max_forward` option
|
||||||
|
|
||||||
|
Every time the router receives a metric through any of the channels, it tries to directly read up to `max_forward` metrics from the same channel. This was done as the router thread would go to sleep and wake up with every arriving metric. The default are `50` metrics at once and `max_forward` needs to greater than `1`.
|
||||||
|
|
||||||
# The `rename_metrics` option
|
# The `rename_metrics` option
|
||||||
|
|
||||||
|
__deprecated__
|
||||||
|
|
||||||
In the ClusterCockpit world we specified a set of standard metrics. Since some collectors determine the metric names based on files, execuables and libraries, they might change from system to system (or installation to installtion, OS to OS, ...). In order to get the common names, you can rename incoming metrics before sending them to the sink. If the metric name matches the `oldname`, it is changed to `newname`
|
In the ClusterCockpit world we specified a set of standard metrics. Since some collectors determine the metric names based on files, execuables and libraries, they might change from system to system (or installation to installtion, OS to OS, ...). In order to get the common names, you can rename incoming metrics before sending them to the sink. If the metric name matches the `oldname`, it is changed to `newname`
|
||||||
|
|
||||||
```json
|
```json
|
||||||
@@ -78,6 +117,8 @@ In the ClusterCockpit world we specified a set of standard metrics. Since some c
|
|||||||
|
|
||||||
# Conditional manipulation of tags (`add_tags` and `del_tags`)
|
# Conditional manipulation of tags (`add_tags` and `del_tags`)
|
||||||
|
|
||||||
|
__deprecated__
|
||||||
|
|
||||||
Common config format:
|
Common config format:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@@ -89,6 +130,8 @@ Common config format:
|
|||||||
|
|
||||||
## The `del_tags` option
|
## The `del_tags` option
|
||||||
|
|
||||||
|
__deprecated__
|
||||||
|
|
||||||
The collectors are free to add whatever `key=value` pair to the metric tags (although the usage of tags should be minimized). If you want to delete a tag afterwards, you can do that. When the `if` condition matches on a metric, the `key` is removed from the metric's tags.
|
The collectors are free to add whatever `key=value` pair to the metric tags (although the usage of tags should be minimized). If you want to delete a tag afterwards, you can do that. When the `if` condition matches on a metric, the `key` is removed from the metric's tags.
|
||||||
|
|
||||||
If you want to remove a tag for all metrics, use the condition wildcard `*`. The `value` field can be omitted in the `del_tags` case.
|
If you want to remove a tag for all metrics, use the condition wildcard `*`. The `value` field can be omitted in the `del_tags` case.
|
||||||
@@ -100,6 +143,8 @@ Never delete tags:
|
|||||||
|
|
||||||
## The `add_tags` option
|
## The `add_tags` option
|
||||||
|
|
||||||
|
__deprecated__
|
||||||
|
|
||||||
In some cases, metrics should be tagged or an existing tag changed based on some condition. This can be done in the `add_tags` section. When the `if` condition evaluates to `true`, the tag `key` is added or gets changed to the new `value`.
|
In some cases, metrics should be tagged or an existing tag changed based on some condition. This can be done in the `add_tags` section. When the `if` condition evaluates to `true`, the tag `key` is added or gets changed to the new `value`.
|
||||||
|
|
||||||
If the CCMetric name is equal to `temp_package_id_0`, it adds an additional tag `test=testing` to the metric.
|
If the CCMetric name is equal to `temp_package_id_0`, it adds an additional tag `test=testing` to the metric.
|
||||||
@@ -141,6 +186,8 @@ In some cases, you want to drop a metric and don't get it forwarded to the sinks
|
|||||||
|
|
||||||
## The `drop_metrics` section
|
## The `drop_metrics` section
|
||||||
|
|
||||||
|
__deprecated__
|
||||||
|
|
||||||
The argument is a list of metric names. No futher checks are performed, only a comparison of the metric name
|
The argument is a list of metric names. No futher checks are performed, only a comparison of the metric name
|
||||||
|
|
||||||
```json
|
```json
|
||||||
@@ -156,6 +203,8 @@ The example drops all metrics with the name `drop_metric_1` and `drop_metric_2`.
|
|||||||
|
|
||||||
## The `drop_metrics_if` section
|
## The `drop_metrics_if` section
|
||||||
|
|
||||||
|
__deprecated__
|
||||||
|
|
||||||
This option takes a list of evaluable conditions and performs them one after the other on **all** metrics incoming from the collectors and the metric cache (aka `interval_aggregates`).
|
This option takes a list of evaluable conditions and performs them one after the other on **all** metrics incoming from the collectors and the metric cache (aka `interval_aggregates`).
|
||||||
|
|
||||||
```json
|
```json
|
||||||
@@ -168,10 +217,25 @@ This option takes a list of evaluable conditions and performs them one after the
|
|||||||
```
|
```
|
||||||
The first line is comparable with the example in `drop_metrics`, it drops all metrics starting with `drop_metric_` and ending with a number. The second line drops all metrics of the first hardware thread (**not** recommended)
|
The first line is comparable with the example in `drop_metrics`, it drops all metrics starting with `drop_metric_` and ending with a number. The second line drops all metrics of the first hardware thread (**not** recommended)
|
||||||
|
|
||||||
|
# Manipulating the metric units
|
||||||
|
|
||||||
|
## The `normalize_units` option
|
||||||
|
|
||||||
|
__deprecated__
|
||||||
|
|
||||||
|
|
||||||
|
The cc-metric-collector tries to read the data from the system as it is reported. If available, it tries to read the metric unit from the system as well (e.g. from `/proc/meminfo`). The problem is that, depending on the source, the metric units are named differently. Just think about `byte`, `Byte`, `B`, `bytes`, ...
|
||||||
|
The [cc-units](https://github.com/ClusterCockpit/cc-units) package provides us a normalization option to use the same metric unit name for all metrics. It this option is set to true, all `unit` meta tags are normalized.
|
||||||
|
|
||||||
|
## The `change_unit_prefix` section
|
||||||
|
|
||||||
|
__deprecated__
|
||||||
|
|
||||||
|
It is often the case that metrics are reported by the system using a rather outdated unit prefix (like `/proc/meminfo` still uses kByte despite current memory sizes are in the GByte range). If you want to change the prefix of a unit, you can do that with the help of [cc-units](https://github.com/ClusterCockpit/cc-units). The setting works on the metric name and requires the new prefix for the metric. The cc-units package determines the scaling factor.
|
||||||
|
|
||||||
# Aggregate metric values of the current interval with the `interval_aggregates` option
|
# Aggregate metric values of the current interval with the `interval_aggregates` option
|
||||||
|
|
||||||
**Note:** `interval_aggregates` works only if `num_cache_intervals` > 0
|
**Note:** `interval_aggregates` works only if `num_cache_intervals` > 0 and is **experimental**
|
||||||
|
|
||||||
In some cases, you need to derive new metrics based on the metrics arriving during an interval. This can be done in the `interval_aggregates` section. The logic is similar to the other metric manipulation and filtering options. A cache stores all metrics that arrive during an interval. At the beginning of the *next* interval, the list of metrics is submitted to the MetricAggregator. It derives new metrics and submits them back to the MetricRouter, so they are sent in the next interval but have the timestamp of the previous interval beginning.
|
In some cases, you need to derive new metrics based on the metrics arriving during an interval. This can be done in the `interval_aggregates` section. The logic is similar to the other metric manipulation and filtering options. A cache stores all metrics that arrive during an interval. At the beginning of the *next* interval, the list of metrics is submitted to the MetricAggregator. It derives new metrics and submits them back to the MetricRouter, so they are sent in the next interval but have the timestamp of the previous interval beginning.
|
||||||
|
|
||||||
@@ -215,3 +279,22 @@ Use cases for `interval_aggregates`:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Order of operations
|
||||||
|
|
||||||
|
The router performs the above mentioned options in a specific order. In order to get the logic you want for a specific metric, it is crucial to know the processing order:
|
||||||
|
|
||||||
|
- Add the `hostname` tag (c)
|
||||||
|
- Manipulate the timestamp to the interval timestamp (c,r)
|
||||||
|
- Drop metrics based on `drop_metrics` and `drop_metrics_if` (c,r)
|
||||||
|
- Add tags based on `add_tags` (c,r)
|
||||||
|
- Delete tags based on `del_tags` (c,r)
|
||||||
|
- Rename metric based on `rename_metric` (c,r)
|
||||||
|
- Add tags based on `add_tags` to still work if the configuration uses the new name (c,r)
|
||||||
|
- Delete tags based on `del_tags` to still work if the configuration uses the new name (c,r)
|
||||||
|
- Normalize units when `normalize_units` is set (c,r)
|
||||||
|
- Convert unit prefix based on `change_unit_prefix` (c,r)
|
||||||
|
|
||||||
|
Legend:
|
||||||
|
- 'c' if metric is coming from a collector
|
||||||
|
- 'r' if metric is coming from a receiver
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
|
||||||
agg "github.com/ClusterCockpit/cc-metric-collector/internal/metricAggregator"
|
agg "github.com/ClusterCockpit/cc-metric-collector/internal/metricAggregator"
|
||||||
mct "github.com/ClusterCockpit/cc-metric-collector/internal/multiChanTicker"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
mct "github.com/ClusterCockpit/cc-metric-collector/pkg/multiChanTicker"
|
||||||
)
|
)
|
||||||
|
|
||||||
type metricCachePeriod struct {
|
type metricCachePeriod struct {
|
||||||
@@ -16,7 +16,7 @@ type metricCachePeriod struct {
|
|||||||
stopstamp time.Time
|
stopstamp time.Time
|
||||||
numMetrics int
|
numMetrics int
|
||||||
sizeMetrics int
|
sizeMetrics int
|
||||||
metrics []lp.CCMetric
|
metrics []lp.CCMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metric cache data structure
|
// Metric cache data structure
|
||||||
@@ -29,21 +29,21 @@ type metricCache struct {
|
|||||||
ticker mct.MultiChanTicker
|
ticker mct.MultiChanTicker
|
||||||
tickchan chan time.Time
|
tickchan chan time.Time
|
||||||
done chan bool
|
done chan bool
|
||||||
output chan lp.CCMetric
|
output chan lp.CCMessage
|
||||||
aggEngine agg.MetricAggregator
|
aggEngine agg.MetricAggregator
|
||||||
}
|
}
|
||||||
|
|
||||||
type MetricCache interface {
|
type MetricCache interface {
|
||||||
Init(output chan lp.CCMetric, ticker mct.MultiChanTicker, wg *sync.WaitGroup, numPeriods int) error
|
Init(output chan lp.CCMessage, ticker mct.MultiChanTicker, wg *sync.WaitGroup, numPeriods int) error
|
||||||
Start()
|
Start()
|
||||||
Add(metric lp.CCMetric)
|
Add(metric lp.CCMessage)
|
||||||
GetPeriod(index int) (time.Time, time.Time, []lp.CCMetric)
|
GetPeriod(index int) (time.Time, time.Time, []lp.CCMessage)
|
||||||
AddAggregation(name, function, condition string, tags, meta map[string]string) error
|
AddAggregation(name, function, condition string, tags, meta map[string]string) error
|
||||||
DeleteAggregation(name string) error
|
DeleteAggregation(name string) error
|
||||||
Close()
|
Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *metricCache) Init(output chan lp.CCMetric, ticker mct.MultiChanTicker, wg *sync.WaitGroup, numPeriods int) error {
|
func (c *metricCache) Init(output chan lp.CCMessage, ticker mct.MultiChanTicker, wg *sync.WaitGroup, numPeriods int) error {
|
||||||
var err error = nil
|
var err error = nil
|
||||||
c.done = make(chan bool)
|
c.done = make(chan bool)
|
||||||
c.wg = wg
|
c.wg = wg
|
||||||
@@ -55,7 +55,7 @@ func (c *metricCache) Init(output chan lp.CCMetric, ticker mct.MultiChanTicker,
|
|||||||
p := new(metricCachePeriod)
|
p := new(metricCachePeriod)
|
||||||
p.numMetrics = 0
|
p.numMetrics = 0
|
||||||
p.sizeMetrics = 0
|
p.sizeMetrics = 0
|
||||||
p.metrics = make([]lp.CCMetric, 0)
|
p.metrics = make([]lp.CCMessage, 0)
|
||||||
c.intervals = append(c.intervals, p)
|
c.intervals = append(c.intervals, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ func (c *metricCache) Start() {
|
|||||||
// Add a metric to the cache. The interval is defined by the global timer (rotate() in Start())
|
// Add a metric to the cache. The interval is defined by the global timer (rotate() in Start())
|
||||||
// The intervals list is used as round-robin buffer and the metric list grows dynamically and
|
// The intervals list is used as round-robin buffer and the metric list grows dynamically and
|
||||||
// to avoid reallocations
|
// to avoid reallocations
|
||||||
func (c *metricCache) Add(metric lp.CCMetric) {
|
func (c *metricCache) Add(metric lp.CCMessage) {
|
||||||
if c.curPeriod >= 0 && c.curPeriod < c.numPeriods {
|
if c.curPeriod >= 0 && c.curPeriod < c.numPeriods {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
p := c.intervals[c.curPeriod]
|
p := c.intervals[c.curPeriod]
|
||||||
@@ -153,10 +153,10 @@ func (c *metricCache) DeleteAggregation(name string) error {
|
|||||||
// Get all metrics of a interval. The index is the difference to the current interval, so index=0
|
// Get all metrics of a interval. The index is the difference to the current interval, so index=0
|
||||||
// is the current one, index=1 the last interval and so on. Returns and empty array if a wrong index
|
// is the current one, index=1 the last interval and so on. Returns and empty array if a wrong index
|
||||||
// is given (negative index, index larger than configured number of total intervals, ...)
|
// is given (negative index, index larger than configured number of total intervals, ...)
|
||||||
func (c *metricCache) GetPeriod(index int) (time.Time, time.Time, []lp.CCMetric) {
|
func (c *metricCache) GetPeriod(index int) (time.Time, time.Time, []lp.CCMessage) {
|
||||||
var start time.Time = time.Now()
|
var start time.Time = time.Now()
|
||||||
var stop time.Time = time.Now()
|
var stop time.Time = time.Now()
|
||||||
var metrics []lp.CCMetric
|
var metrics []lp.CCMessage
|
||||||
if index >= 0 && index < c.numPeriods {
|
if index >= 0 && index < c.numPeriods {
|
||||||
pindex := c.curPeriod - index
|
pindex := c.curPeriod - index
|
||||||
if pindex < 0 {
|
if pindex < 0 {
|
||||||
@@ -168,10 +168,10 @@ func (c *metricCache) GetPeriod(index int) (time.Time, time.Time, []lp.CCMetric)
|
|||||||
metrics = c.intervals[pindex].metrics
|
metrics = c.intervals[pindex].metrics
|
||||||
//return c.intervals[pindex].startstamp, c.intervals[pindex].stopstamp, c.intervals[pindex].metrics
|
//return c.intervals[pindex].startstamp, c.intervals[pindex].stopstamp, c.intervals[pindex].metrics
|
||||||
} else {
|
} else {
|
||||||
metrics = make([]lp.CCMetric, 0)
|
metrics = make([]lp.CCMessage, 0)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
metrics = make([]lp.CCMetric, 0)
|
metrics = make([]lp.CCMessage, 0)
|
||||||
}
|
}
|
||||||
return start, stop, metrics
|
return start, stop, metrics
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ func (c *metricCache) Close() {
|
|||||||
c.done <- true
|
c.done <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCache(output chan lp.CCMetric, ticker mct.MultiChanTicker, wg *sync.WaitGroup, numPeriods int) (MetricCache, error) {
|
func NewCache(output chan lp.CCMessage, ticker mct.MultiChanTicker, wg *sync.WaitGroup, numPeriods int) (MetricCache, error) {
|
||||||
c := new(metricCache)
|
c := new(metricCache)
|
||||||
err := c.Init(output, ticker, wg, numPeriods)
|
err := c.Init(output, ticker, wg, numPeriods)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -2,16 +2,18 @@ package metricRouter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
agg "github.com/ClusterCockpit/cc-metric-collector/internal/metricAggregator"
|
agg "github.com/ClusterCockpit/cc-metric-collector/internal/metricAggregator"
|
||||||
mct "github.com/ClusterCockpit/cc-metric-collector/internal/multiChanTicker"
|
mp "github.com/ClusterCockpit/cc-metric-collector/pkg/messageProcessor"
|
||||||
|
mct "github.com/ClusterCockpit/cc-metric-collector/pkg/multiChanTicker"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ROUTER_MAX_FORWARD = 50
|
const ROUTER_MAX_FORWARD = 50
|
||||||
@@ -25,6 +27,7 @@ type metricRouterTagConfig struct {
|
|||||||
|
|
||||||
// Metric router configuration
|
// Metric router configuration
|
||||||
type metricRouterConfig struct {
|
type metricRouterConfig struct {
|
||||||
|
HostnameTagName string `json:"hostname_tag"` // Key name used when adding the hostname to a metric (default 'hostname')
|
||||||
AddTags []metricRouterTagConfig `json:"add_tags"` // List of tags that are added when the condition is met
|
AddTags []metricRouterTagConfig `json:"add_tags"` // List of tags that are added when the condition is met
|
||||||
DelTags []metricRouterTagConfig `json:"delete_tags"` // List of tags that are removed when the condition is met
|
DelTags []metricRouterTagConfig `json:"delete_tags"` // List of tags that are removed when the condition is met
|
||||||
IntervalAgg []agg.MetricAggregatorIntervalConfig `json:"interval_aggregates"` // List of aggregation function processed at the end of an interval
|
IntervalAgg []agg.MetricAggregatorIntervalConfig `json:"interval_aggregates"` // List of aggregation function processed at the end of an interval
|
||||||
@@ -33,33 +36,37 @@ type metricRouterConfig struct {
|
|||||||
RenameMetrics map[string]string `json:"rename_metrics"` // Map to rename metric name from key to value
|
RenameMetrics map[string]string `json:"rename_metrics"` // Map to rename metric name from key to value
|
||||||
IntervalStamp bool `json:"interval_timestamp"` // Update timestamp periodically by ticker each interval?
|
IntervalStamp bool `json:"interval_timestamp"` // Update timestamp periodically by ticker each interval?
|
||||||
NumCacheIntervals int `json:"num_cache_intervals"` // Number of intervals of cached metrics for evaluation
|
NumCacheIntervals int `json:"num_cache_intervals"` // Number of intervals of cached metrics for evaluation
|
||||||
dropMetrics map[string]bool // Internal map for O(1) lookup
|
MaxForward int `json:"max_forward"` // Number of maximal forwarded metrics at one select
|
||||||
|
NormalizeUnits bool `json:"normalize_units"` // Check unit meta flag and normalize it using cc-units
|
||||||
|
ChangeUnitPrefix map[string]string `json:"change_unit_prefix"` // Add prefix that should be applied to the metrics
|
||||||
|
// dropMetrics map[string]bool // Internal map for O(1) lookup
|
||||||
|
MessageProcessor json.RawMessage `json:"process_message,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metric router data structure
|
// Metric router data structure
|
||||||
type metricRouter struct {
|
type metricRouter struct {
|
||||||
hostname string // Hostname used in tags
|
hostname string // Hostname used in tags
|
||||||
coll_input chan lp.CCMetric // Input channel from CollectorManager
|
coll_input chan lp.CCMessage // Input channel from CollectorManager
|
||||||
recv_input chan lp.CCMetric // Input channel from ReceiveManager
|
recv_input chan lp.CCMessage // Input channel from ReceiveManager
|
||||||
cache_input chan lp.CCMetric // Input channel from MetricCache
|
cache_input chan lp.CCMessage // Input channel from MetricCache
|
||||||
outputs []chan lp.CCMetric // List of all output channels
|
outputs []chan lp.CCMessage // List of all output channels
|
||||||
done chan bool // channel to finish / stop metric router
|
done chan bool // channel to finish / stop metric router
|
||||||
wg *sync.WaitGroup // wait group for all goroutines in cc-metric-collector
|
wg *sync.WaitGroup // wait group for all goroutines in cc-metric-collector
|
||||||
timestamp time.Time // timestamp periodically updated by ticker each interval
|
timestamp time.Time // timestamp periodically updated by ticker each interval
|
||||||
timerdone chan bool // channel to finish / stop timestamp updater
|
|
||||||
ticker mct.MultiChanTicker // periodically ticking once each interval
|
ticker mct.MultiChanTicker // periodically ticking once each interval
|
||||||
config metricRouterConfig // json encoded config for metric router
|
config metricRouterConfig // json encoded config for metric router
|
||||||
cache MetricCache // pointer to MetricCache
|
cache MetricCache // pointer to MetricCache
|
||||||
cachewg sync.WaitGroup // wait group for MetricCache
|
cachewg sync.WaitGroup // wait group for MetricCache
|
||||||
maxForward int // number of metrics to forward maximally in one iteration
|
maxForward int // number of metrics to forward maximally in one iteration
|
||||||
|
mp mp.MessageProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
// MetricRouter access functions
|
// MetricRouter access functions
|
||||||
type MetricRouter interface {
|
type MetricRouter interface {
|
||||||
Init(ticker mct.MultiChanTicker, wg *sync.WaitGroup, routerConfigFile string) error
|
Init(ticker mct.MultiChanTicker, wg *sync.WaitGroup, routerConfigFile string) error
|
||||||
AddCollectorInput(input chan lp.CCMetric)
|
AddCollectorInput(input chan lp.CCMessage)
|
||||||
AddReceiverInput(input chan lp.CCMetric)
|
AddReceiverInput(input chan lp.CCMessage)
|
||||||
AddOutput(output chan lp.CCMetric)
|
AddOutput(output chan lp.CCMessage)
|
||||||
Start()
|
Start()
|
||||||
Close()
|
Close()
|
||||||
}
|
}
|
||||||
@@ -71,12 +78,13 @@ type MetricRouter interface {
|
|||||||
// * ticker (from variable ticker)
|
// * ticker (from variable ticker)
|
||||||
// * configuration (read from config file in variable routerConfigFile)
|
// * configuration (read from config file in variable routerConfigFile)
|
||||||
func (r *metricRouter) Init(ticker mct.MultiChanTicker, wg *sync.WaitGroup, routerConfigFile string) error {
|
func (r *metricRouter) Init(ticker mct.MultiChanTicker, wg *sync.WaitGroup, routerConfigFile string) error {
|
||||||
r.outputs = make([]chan lp.CCMetric, 0)
|
r.outputs = make([]chan lp.CCMessage, 0)
|
||||||
r.done = make(chan bool)
|
r.done = make(chan bool)
|
||||||
r.cache_input = make(chan lp.CCMetric)
|
r.cache_input = make(chan lp.CCMessage)
|
||||||
r.wg = wg
|
r.wg = wg
|
||||||
r.ticker = ticker
|
r.ticker = ticker
|
||||||
r.maxForward = ROUTER_MAX_FORWARD
|
r.config.MaxForward = ROUTER_MAX_FORWARD
|
||||||
|
r.config.HostnameTagName = "hostname"
|
||||||
|
|
||||||
// Set hostname
|
// Set hostname
|
||||||
hostname, err := os.Hostname()
|
hostname, err := os.Hostname()
|
||||||
@@ -100,6 +108,10 @@ func (r *metricRouter) Init(ticker mct.MultiChanTicker, wg *sync.WaitGroup, rout
|
|||||||
cclog.ComponentError("MetricRouter", err.Error())
|
cclog.ComponentError("MetricRouter", err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
r.maxForward = 1
|
||||||
|
if r.config.MaxForward > r.maxForward {
|
||||||
|
r.maxForward = r.config.MaxForward
|
||||||
|
}
|
||||||
if r.config.NumCacheIntervals > 0 {
|
if r.config.NumCacheIntervals > 0 {
|
||||||
r.cache, err = NewCache(r.cache_input, r.ticker, &r.cachewg, r.config.NumCacheIntervals)
|
r.cache, err = NewCache(r.cache_input, r.ticker, &r.cachewg, r.config.NumCacheIntervals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -110,37 +122,56 @@ func (r *metricRouter) Init(ticker mct.MultiChanTicker, wg *sync.WaitGroup, rout
|
|||||||
r.cache.AddAggregation(agg.Name, agg.Function, agg.Condition, agg.Tags, agg.Meta)
|
r.cache.AddAggregation(agg.Name, agg.Function, agg.Condition, agg.Tags, agg.Meta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r.config.dropMetrics = make(map[string]bool)
|
p, err := mp.NewMessageProcessor()
|
||||||
for _, mname := range r.config.DropMetrics {
|
if err != nil {
|
||||||
r.config.dropMetrics[mname] = true
|
return fmt.Errorf("initialization of message processor failed: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
r.mp = p
|
||||||
|
|
||||||
|
if len(r.config.MessageProcessor) > 0 {
|
||||||
|
err = r.mp.FromConfigJSON(r.config.MessageProcessor)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed parsing JSON for message processor: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, mname := range r.config.DropMetrics {
|
||||||
|
r.mp.AddDropMessagesByName(mname)
|
||||||
|
}
|
||||||
|
for _, cond := range r.config.DropMetricsIf {
|
||||||
|
r.mp.AddDropMessagesByCondition(cond)
|
||||||
|
}
|
||||||
|
for _, data := range r.config.AddTags {
|
||||||
|
cond := data.Condition
|
||||||
|
if cond == "*" {
|
||||||
|
cond = "true"
|
||||||
|
}
|
||||||
|
r.mp.AddAddTagsByCondition(cond, data.Key, data.Value)
|
||||||
|
}
|
||||||
|
for _, data := range r.config.DelTags {
|
||||||
|
cond := data.Condition
|
||||||
|
if cond == "*" {
|
||||||
|
cond = "true"
|
||||||
|
}
|
||||||
|
r.mp.AddDeleteTagsByCondition(cond, data.Key, data.Value)
|
||||||
|
}
|
||||||
|
for oldname, newname := range r.config.RenameMetrics {
|
||||||
|
r.mp.AddRenameMetricByName(oldname, newname)
|
||||||
|
}
|
||||||
|
for metricName, prefix := range r.config.ChangeUnitPrefix {
|
||||||
|
r.mp.AddChangeUnitPrefix(fmt.Sprintf("name == '%s'", metricName), prefix)
|
||||||
|
}
|
||||||
|
r.mp.SetNormalizeUnits(r.config.NormalizeUnits)
|
||||||
|
|
||||||
|
r.mp.AddAddTagsByCondition("true", r.config.HostnameTagName, r.hostname)
|
||||||
|
|
||||||
|
// r.config.dropMetrics = make(map[string]bool)
|
||||||
|
// for _, mname := range r.config.DropMetrics {
|
||||||
|
// r.config.dropMetrics[mname] = true
|
||||||
|
// }
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartTimer starts a timer which updates timestamp periodically
|
func getParamMap(point lp.CCMessage) map[string]interface{} {
|
||||||
func (r *metricRouter) StartTimer() {
|
|
||||||
m := make(chan time.Time)
|
|
||||||
r.ticker.AddChannel(m)
|
|
||||||
r.timerdone = make(chan bool)
|
|
||||||
|
|
||||||
r.wg.Add(1)
|
|
||||||
go func() {
|
|
||||||
defer r.wg.Done()
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-r.timerdone:
|
|
||||||
close(r.timerdone)
|
|
||||||
cclog.ComponentDebug("MetricRouter", "TIMER DONE")
|
|
||||||
return
|
|
||||||
case t := <-m:
|
|
||||||
r.timestamp = t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
cclog.ComponentDebug("MetricRouter", "TIMER START")
|
|
||||||
}
|
|
||||||
|
|
||||||
func getParamMap(point lp.CCMetric) map[string]interface{} {
|
|
||||||
params := make(map[string]interface{})
|
params := make(map[string]interface{})
|
||||||
params["metric"] = point
|
params["metric"] = point
|
||||||
params["name"] = point.Name()
|
params["name"] = point.Name()
|
||||||
@@ -158,7 +189,7 @@ func getParamMap(point lp.CCMetric) map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DoAddTags adds a tag when condition is fullfiled
|
// DoAddTags adds a tag when condition is fullfiled
|
||||||
func (r *metricRouter) DoAddTags(point lp.CCMetric) {
|
func (r *metricRouter) DoAddTags(point lp.CCMessage) {
|
||||||
var conditionMatches bool
|
var conditionMatches bool
|
||||||
for _, m := range r.config.AddTags {
|
for _, m := range r.config.AddTags {
|
||||||
if m.Condition == "*" {
|
if m.Condition == "*" {
|
||||||
@@ -180,56 +211,89 @@ func (r *metricRouter) DoAddTags(point lp.CCMetric) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DoDelTags removes a tag when condition is fullfiled
|
// DoDelTags removes a tag when condition is fullfiled
|
||||||
func (r *metricRouter) DoDelTags(point lp.CCMetric) {
|
// func (r *metricRouter) DoDelTags(point lp.CCMessage) {
|
||||||
var conditionMatches bool
|
// var conditionMatches bool
|
||||||
for _, m := range r.config.DelTags {
|
// for _, m := range r.config.DelTags {
|
||||||
if m.Condition == "*" {
|
// if m.Condition == "*" {
|
||||||
// Condition is always matched
|
// // Condition is always matched
|
||||||
conditionMatches = true
|
// conditionMatches = true
|
||||||
} else {
|
// } else {
|
||||||
// Evaluate condition
|
// // Evaluate condition
|
||||||
var err error
|
// var err error
|
||||||
conditionMatches, err = agg.EvalBoolCondition(m.Condition, getParamMap(point))
|
// conditionMatches, err = agg.EvalBoolCondition(m.Condition, getParamMap(point))
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
cclog.ComponentError("MetricRouter", err.Error())
|
// cclog.ComponentError("MetricRouter", err.Error())
|
||||||
conditionMatches = false
|
// conditionMatches = false
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if conditionMatches {
|
// if conditionMatches {
|
||||||
point.RemoveTag(m.Key)
|
// point.RemoveTag(m.Key)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Conditional test whether a metric should be dropped
|
// Conditional test whether a metric should be dropped
|
||||||
func (r *metricRouter) dropMetric(point lp.CCMetric) bool {
|
// func (r *metricRouter) dropMetric(point lp.CCMessage) bool {
|
||||||
// Simple drop check
|
// // Simple drop check
|
||||||
if conditionMatches, ok := r.config.dropMetrics[point.Name()]; ok {
|
// if conditionMatches, ok := r.config.dropMetrics[point.Name()]; ok {
|
||||||
return conditionMatches
|
// return conditionMatches
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Checking the dropping conditions
|
// // Checking the dropping conditions
|
||||||
for _, m := range r.config.DropMetricsIf {
|
// for _, m := range r.config.DropMetricsIf {
|
||||||
conditionMatches, err := agg.EvalBoolCondition(m, getParamMap(point))
|
// conditionMatches, err := agg.EvalBoolCondition(m, getParamMap(point))
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
cclog.ComponentError("MetricRouter", err.Error())
|
// cclog.ComponentError("MetricRouter", err.Error())
|
||||||
conditionMatches = false
|
// conditionMatches = false
|
||||||
}
|
// }
|
||||||
if conditionMatches {
|
// if conditionMatches {
|
||||||
return conditionMatches
|
// return conditionMatches
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// No dropping condition met
|
// // No dropping condition met
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// func (r *metricRouter) prepareUnit(point lp.CCMessage) bool {
|
||||||
|
// if r.config.NormalizeUnits {
|
||||||
|
// if in_unit, ok := point.GetMeta("unit"); ok {
|
||||||
|
// u := units.NewUnit(in_unit)
|
||||||
|
// if u.Valid() {
|
||||||
|
// point.AddMeta("unit", u.Short())
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if newP, ok := r.config.ChangeUnitPrefix[point.Name()]; ok {
|
||||||
|
|
||||||
|
// newPrefix := units.NewPrefix(newP)
|
||||||
|
|
||||||
|
// if in_unit, ok := point.GetMeta("unit"); ok && newPrefix != units.InvalidPrefix {
|
||||||
|
// u := units.NewUnit(in_unit)
|
||||||
|
// if u.Valid() {
|
||||||
|
// cclog.ComponentDebug("MetricRouter", "Change prefix to", newP, "for metric", point.Name())
|
||||||
|
// conv, out_unit := units.GetUnitPrefixFactor(u, newPrefix)
|
||||||
|
// if conv != nil && out_unit.Valid() {
|
||||||
|
// if val, ok := point.GetField("value"); ok {
|
||||||
|
// point.AddField("value", conv(val))
|
||||||
|
// point.AddMeta("unit", out_unit.Short())
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return true
|
||||||
|
// }
|
||||||
|
|
||||||
// Start starts the metric router
|
// Start starts the metric router
|
||||||
func (r *metricRouter) Start() {
|
func (r *metricRouter) Start() {
|
||||||
// start timer if configured
|
// start timer if configured
|
||||||
r.timestamp = time.Now()
|
r.timestamp = time.Now()
|
||||||
|
timeChan := make(chan time.Time)
|
||||||
if r.config.IntervalStamp {
|
if r.config.IntervalStamp {
|
||||||
r.StartTimer()
|
r.ticker.AddChannel(timeChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Router manager is done
|
// Router manager is done
|
||||||
@@ -240,55 +304,75 @@ func (r *metricRouter) Start() {
|
|||||||
|
|
||||||
// Forward takes a received metric, adds or deletes tags
|
// Forward takes a received metric, adds or deletes tags
|
||||||
// and forwards it to the output channels
|
// and forwards it to the output channels
|
||||||
forward := func(point lp.CCMetric) {
|
// forward := func(point lp.CCMessage) {
|
||||||
cclog.ComponentDebug("MetricRouter", "FORWARD", point)
|
// cclog.ComponentDebug("MetricRouter", "FORWARD", point)
|
||||||
r.DoAddTags(point)
|
// r.DoAddTags(point)
|
||||||
r.DoDelTags(point)
|
// r.DoDelTags(point)
|
||||||
if new, ok := r.config.RenameMetrics[point.Name()]; ok {
|
// name := point.Name()
|
||||||
point.SetName(new)
|
// if new, ok := r.config.RenameMetrics[name]; ok {
|
||||||
}
|
// point.SetName(new)
|
||||||
r.DoAddTags(point)
|
// point.AddMeta("oldname", name)
|
||||||
r.DoDelTags(point)
|
// r.DoAddTags(point)
|
||||||
|
// r.DoDelTags(point)
|
||||||
|
// }
|
||||||
|
|
||||||
for _, o := range r.outputs {
|
// r.prepareUnit(point)
|
||||||
o <- point
|
|
||||||
}
|
// for _, o := range r.outputs {
|
||||||
}
|
// o <- point
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// Foward message received from collector channel
|
// Foward message received from collector channel
|
||||||
coll_forward := func(p lp.CCMetric) {
|
coll_forward := func(p lp.CCMessage) {
|
||||||
// receive from metric collector
|
// receive from metric collector
|
||||||
p.AddTag("hostname", r.hostname)
|
//p.AddTag(r.config.HostnameTagName, r.hostname)
|
||||||
if r.config.IntervalStamp {
|
if r.config.IntervalStamp {
|
||||||
p.SetTime(r.timestamp)
|
p.SetTime(r.timestamp)
|
||||||
}
|
}
|
||||||
if !r.dropMetric(p) {
|
m, err := r.mp.ProcessMessage(p)
|
||||||
forward(p)
|
if err == nil && m != nil {
|
||||||
|
for _, o := range r.outputs {
|
||||||
|
o <- m
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// if !r.dropMetric(p) {
|
||||||
|
// for _, o := range r.outputs {
|
||||||
|
// o <- point
|
||||||
|
// }
|
||||||
|
// }
|
||||||
// even if the metric is dropped, it is stored in the cache for
|
// even if the metric is dropped, it is stored in the cache for
|
||||||
// aggregations
|
// aggregations
|
||||||
if r.config.NumCacheIntervals > 0 {
|
if r.config.NumCacheIntervals > 0 {
|
||||||
r.cache.Add(p)
|
r.cache.Add(m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Forward message received from receivers channel
|
// Forward message received from receivers channel
|
||||||
recv_forward := func(p lp.CCMetric) {
|
recv_forward := func(p lp.CCMessage) {
|
||||||
// receive from receive manager
|
// receive from receive manager
|
||||||
if r.config.IntervalStamp {
|
if r.config.IntervalStamp {
|
||||||
p.SetTime(r.timestamp)
|
p.SetTime(r.timestamp)
|
||||||
}
|
}
|
||||||
if !r.dropMetric(p) {
|
m, err := r.mp.ProcessMessage(p)
|
||||||
forward(p)
|
if err == nil && m != nil {
|
||||||
|
for _, o := range r.outputs {
|
||||||
|
o <- m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if !r.dropMetric(p) {
|
||||||
|
// forward(p)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
// Forward message received from cache channel
|
// Forward message received from cache channel
|
||||||
cache_forward := func(p lp.CCMetric) {
|
cache_forward := func(p lp.CCMessage) {
|
||||||
// receive from metric collector
|
// receive from metric collector
|
||||||
if !r.dropMetric(p) {
|
m, err := r.mp.ProcessMessage(p)
|
||||||
p.AddTag("hostname", r.hostname)
|
if err == nil && m != nil {
|
||||||
forward(p)
|
for _, o := range r.outputs {
|
||||||
|
o <- m
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,21 +391,25 @@ func (r *metricRouter) Start() {
|
|||||||
done()
|
done()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
case timestamp := <-timeChan:
|
||||||
|
r.timestamp = timestamp
|
||||||
|
cclog.ComponentDebug("MetricRouter", "Update timestamp", r.timestamp.UnixNano())
|
||||||
|
|
||||||
case p := <-r.coll_input:
|
case p := <-r.coll_input:
|
||||||
coll_forward(p)
|
coll_forward(p)
|
||||||
for i := 0; len(r.coll_input) > 0 && i < r.maxForward; i++ {
|
for i := 0; len(r.coll_input) > 0 && i < (r.maxForward-1); i++ {
|
||||||
coll_forward(<-r.coll_input)
|
coll_forward(<-r.coll_input)
|
||||||
}
|
}
|
||||||
|
|
||||||
case p := <-r.recv_input:
|
case p := <-r.recv_input:
|
||||||
recv_forward(p)
|
recv_forward(p)
|
||||||
for i := 0; len(r.recv_input) > 0 && i < r.maxForward; i++ {
|
for i := 0; len(r.recv_input) > 0 && i < (r.maxForward-1); i++ {
|
||||||
recv_forward(<-r.recv_input)
|
recv_forward(<-r.recv_input)
|
||||||
}
|
}
|
||||||
|
|
||||||
case p := <-r.cache_input:
|
case p := <-r.cache_input:
|
||||||
cache_forward(p)
|
cache_forward(p)
|
||||||
for i := 0; len(r.cache_input) > 0 && i < r.maxForward; i++ {
|
for i := 0; len(r.cache_input) > 0 && i < (r.maxForward-1); i++ {
|
||||||
cache_forward(<-r.cache_input)
|
cache_forward(<-r.cache_input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,17 +419,17 @@ func (r *metricRouter) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddCollectorInput adds a channel between metric collector and metric router
|
// AddCollectorInput adds a channel between metric collector and metric router
|
||||||
func (r *metricRouter) AddCollectorInput(input chan lp.CCMetric) {
|
func (r *metricRouter) AddCollectorInput(input chan lp.CCMessage) {
|
||||||
r.coll_input = input
|
r.coll_input = input
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddReceiverInput adds a channel between metric receiver and metric router
|
// AddReceiverInput adds a channel between metric receiver and metric router
|
||||||
func (r *metricRouter) AddReceiverInput(input chan lp.CCMetric) {
|
func (r *metricRouter) AddReceiverInput(input chan lp.CCMessage) {
|
||||||
r.recv_input = input
|
r.recv_input = input
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddOutput adds a output channel to the metric router
|
// AddOutput adds a output channel to the metric router
|
||||||
func (r *metricRouter) AddOutput(output chan lp.CCMetric) {
|
func (r *metricRouter) AddOutput(output chan lp.CCMessage) {
|
||||||
r.outputs = append(r.outputs, output)
|
r.outputs = append(r.outputs, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,14 +440,6 @@ func (r *metricRouter) Close() {
|
|||||||
// wait for close of channel r.done
|
// wait for close of channel r.done
|
||||||
<-r.done
|
<-r.done
|
||||||
|
|
||||||
// stop timer
|
|
||||||
if r.config.IntervalStamp {
|
|
||||||
cclog.ComponentDebug("MetricRouter", "TIMER CLOSE")
|
|
||||||
r.timerdone <- true
|
|
||||||
// wait for close of channel r.timerdone
|
|
||||||
<-r.timerdone
|
|
||||||
}
|
|
||||||
|
|
||||||
// stop metric cache
|
// stop metric cache
|
||||||
if r.config.NumCacheIntervals > 0 {
|
if r.config.NumCacheIntervals > 0 {
|
||||||
cclog.ComponentDebug("MetricRouter", "CACHE CLOSE")
|
cclog.ComponentDebug("MetricRouter", "CACHE CLOSE")
|
||||||
|
|||||||
57
pkg/ccMetric/README.md
Normal file
57
pkg/ccMetric/README.md
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
# ClusterCockpit metrics
|
||||||
|
|
||||||
|
As described in the [ClusterCockpit specifications](https://github.com/ClusterCockpit/cc-specifications), the whole ClusterCockpit stack uses metrics in the InfluxDB line protocol format. This is also the input and output format for the ClusterCockpit Metric Collector but internally it uses an extended format while processing, named CCMetric.
|
||||||
|
|
||||||
|
It is basically a copy of the [InfluxDB line protocol](https://github.com/influxdata/line-protocol) `MutableMetric` interface with one extension. Besides the tags and fields, it contains a list of meta information (re-using the `Tag` structure of the original protocol):
|
||||||
|
|
||||||
|
```golang
|
||||||
|
type ccMetric struct {
|
||||||
|
name string // Measurement name
|
||||||
|
meta map[string]string // map of meta data tags
|
||||||
|
tags map[string]string // map of of tags
|
||||||
|
fields map[string]interface{} // map of of fields
|
||||||
|
tm time.Time // timestamp
|
||||||
|
}
|
||||||
|
|
||||||
|
type CCMetric interface {
|
||||||
|
ToPoint(metaAsTags map[string]bool) *write.Point // Generate influxDB point for data type ccMetric
|
||||||
|
ToLineProtocol(metaAsTags map[string]bool) string // Generate influxDB line protocol for data type ccMetric
|
||||||
|
String() string // Return line-protocol like string
|
||||||
|
|
||||||
|
Name() string // Get metric name
|
||||||
|
SetName(name string) // Set metric name
|
||||||
|
|
||||||
|
Time() time.Time // Get timestamp
|
||||||
|
SetTime(t time.Time) // Set timestamp
|
||||||
|
|
||||||
|
Tags() map[string]string // Map of tags
|
||||||
|
AddTag(key, value string) // Add a tag
|
||||||
|
GetTag(key string) (value string, ok bool) // Get a tag by its key
|
||||||
|
HasTag(key string) (ok bool) // Check if a tag key is present
|
||||||
|
RemoveTag(key string) // Remove a tag by its key
|
||||||
|
|
||||||
|
Meta() map[string]string // Map of meta data tags
|
||||||
|
AddMeta(key, value string) // Add a meta data tag
|
||||||
|
GetMeta(key string) (value string, ok bool) // Get a meta data tab addressed by its key
|
||||||
|
HasMeta(key string) (ok bool) // Check if a meta data key is present
|
||||||
|
RemoveMeta(key string) // Remove a meta data tag by its key
|
||||||
|
|
||||||
|
Fields() map[string]interface{} // Map of fields
|
||||||
|
AddField(key string, value interface{}) // Add a field
|
||||||
|
GetField(key string) (value interface{}, ok bool) // Get a field addressed by its key
|
||||||
|
HasField(key string) (ok bool) // Check if a field key is present
|
||||||
|
RemoveField(key string) // Remove a field addressed by its key
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(name string, tags map[string]string, meta map[string]string, fields map[string]interface{}, tm time.Time) (CCMetric, error)
|
||||||
|
func FromMetric(other CCMetric) CCMetric
|
||||||
|
func FromInfluxMetric(other lp.Metric) CCMetric
|
||||||
|
```
|
||||||
|
|
||||||
|
The `CCMetric` interface provides the same functions as the `MutableMetric` like `{Add, Get, Remove, Has}{Tag, Field}` and additionally provides `{Add, Get, Remove, Has}Meta`.
|
||||||
|
|
||||||
|
The InfluxDB protocol creates a new metric with `influx.New(name, tags, fields, time)` while CCMetric uses `ccMetric.New(name, tags, meta, fields, time)` where `tags` and `meta` are both of type `map[string]string`.
|
||||||
|
|
||||||
|
You can copy a CCMetric with `FromMetric(other CCMetric) CCMetric`. If you get an `influx.Metric` from a function, like the line protocol parser, you can use `FromInfluxMetric(other influx.Metric) CCMetric` to get a CCMetric out of it (see `NatsReceiver` for an example).
|
||||||
|
|
||||||
|
Although the [cc-specifications](https://github.com/ClusterCockpit/cc-specifications/blob/master/interfaces/lineprotocol/README.md) defines that there is only a `value` field for the metric value, the CCMetric still can have multiple values similar to the InfluxDB line protocol.
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
|
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
|
||||||
write "github.com/influxdata/influxdb-client-go/v2/api/write"
|
write "github.com/influxdata/influxdb-client-go/v2/api/write"
|
||||||
lp "github.com/influxdata/line-protocol" // MIT license
|
lp "github.com/influxdata/line-protocol" // MIT license
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Most functions are derived from github.com/influxdata/line-protocol/metric.go
|
// Most functions are derived from github.com/influxdata/line-protocol/metric.go
|
||||||
@@ -24,8 +25,8 @@ type ccMetric struct {
|
|||||||
|
|
||||||
// ccMetric access functions
|
// ccMetric access functions
|
||||||
type CCMetric interface {
|
type CCMetric interface {
|
||||||
ToPoint(metaAsTags bool) *write.Point // Generate influxDB point for data type ccMetric
|
ToPoint(metaAsTags map[string]bool) *write.Point // Generate influxDB point for data type ccMetric
|
||||||
ToLineProtocol(metaAsTags bool) string // Generate influxDB line protocol for data type ccMetric
|
ToLineProtocol(metaAsTags map[string]bool) string // Generate influxDB line protocol for data type ccMetric
|
||||||
|
|
||||||
Name() string // Get metric name
|
Name() string // Get metric name
|
||||||
SetName(name string) // Set metric name
|
SetName(name string) // Set metric name
|
||||||
@@ -50,6 +51,7 @@ type CCMetric interface {
|
|||||||
GetField(key string) (value interface{}, ok bool) // Get a field addressed by its key
|
GetField(key string) (value interface{}, ok bool) // Get a field addressed by its key
|
||||||
HasField(key string) (ok bool) // Check if a field key is present
|
HasField(key string) (ok bool) // Check if a field key is present
|
||||||
RemoveField(key string) // Remove a field addressed by its key
|
RemoveField(key string) // Remove a field addressed by its key
|
||||||
|
String() string // Return line-protocol like string
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements the stringer interface for data type ccMetric
|
// String implements the stringer interface for data type ccMetric
|
||||||
@@ -61,25 +63,20 @@ func (m *ccMetric) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToLineProtocol generates influxDB line protocol for data type ccMetric
|
// ToLineProtocol generates influxDB line protocol for data type ccMetric
|
||||||
func (m *ccMetric) ToPoint(metaAsTags bool) (p *write.Point) {
|
func (m *ccMetric) ToPoint(metaAsTags map[string]bool) (p *write.Point) {
|
||||||
|
|
||||||
if !metaAsTags {
|
|
||||||
p = influxdb2.NewPoint(m.name, m.tags, m.fields, m.tm)
|
p = influxdb2.NewPoint(m.name, m.tags, m.fields, m.tm)
|
||||||
} else {
|
for key, use_as_tag := range metaAsTags {
|
||||||
tags := make(map[string]string, len(m.tags)+len(m.meta))
|
if use_as_tag {
|
||||||
for key, value := range m.tags {
|
if value, ok := m.GetMeta(key); ok {
|
||||||
tags[key] = value
|
p.AddTag(key, value)
|
||||||
}
|
}
|
||||||
for key, value := range m.meta {
|
|
||||||
tags[key] = value
|
|
||||||
}
|
}
|
||||||
p = influxdb2.NewPoint(m.name, tags, m.fields, m.tm)
|
|
||||||
}
|
}
|
||||||
return
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToLineProtocol generates influxDB line protocol for data type ccMetric
|
// ToLineProtocol generates influxDB line protocol for data type ccMetric
|
||||||
func (m *ccMetric) ToLineProtocol(metaAsTags bool) string {
|
func (m *ccMetric) ToLineProtocol(metaAsTags map[string]bool) string {
|
||||||
|
|
||||||
return write.PointToLineProtocol(
|
return write.PointToLineProtocol(
|
||||||
m.ToPoint(metaAsTags),
|
m.ToPoint(metaAsTags),
|
||||||
@@ -199,19 +196,13 @@ func New(
|
|||||||
) (CCMetric, error) {
|
) (CCMetric, error) {
|
||||||
m := &ccMetric{
|
m := &ccMetric{
|
||||||
name: name,
|
name: name,
|
||||||
tags: make(map[string]string, len(tags)),
|
tags: maps.Clone(tags),
|
||||||
meta: make(map[string]string, len(meta)),
|
meta: maps.Clone(meta),
|
||||||
fields: make(map[string]interface{}, len(fields)),
|
fields: make(map[string]interface{}, len(fields)),
|
||||||
tm: tm,
|
tm: tm,
|
||||||
}
|
}
|
||||||
|
|
||||||
// deep copy tags, meta data tags and fields
|
// deep copy fields
|
||||||
for k, v := range tags {
|
|
||||||
m.tags[k] = v
|
|
||||||
}
|
|
||||||
for k, v := range meta {
|
|
||||||
m.meta[k] = v
|
|
||||||
}
|
|
||||||
for k, v := range fields {
|
for k, v := range fields {
|
||||||
v := convertField(v)
|
v := convertField(v)
|
||||||
if v == nil {
|
if v == nil {
|
||||||
@@ -224,26 +215,15 @@ func New(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FromMetric copies the metric <other>
|
// FromMetric copies the metric <other>
|
||||||
func FromMetric(other ccMetric) CCMetric {
|
func FromMetric(other CCMetric) CCMetric {
|
||||||
m := &ccMetric{
|
|
||||||
|
return &ccMetric{
|
||||||
name: other.Name(),
|
name: other.Name(),
|
||||||
tags: make(map[string]string, len(other.tags)),
|
tags: maps.Clone(other.Tags()),
|
||||||
meta: make(map[string]string, len(other.meta)),
|
meta: maps.Clone(other.Meta()),
|
||||||
fields: make(map[string]interface{}, len(other.fields)),
|
fields: maps.Clone(other.Fields()),
|
||||||
tm: other.Time(),
|
tm: other.Time(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// deep copy tags, meta data tags and fields
|
|
||||||
for key, value := range other.tags {
|
|
||||||
m.tags[key] = value
|
|
||||||
}
|
|
||||||
for key, value := range other.meta {
|
|
||||||
m.meta[key] = value
|
|
||||||
}
|
|
||||||
for key, value := range other.fields {
|
|
||||||
m.fields[key] = value
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromInfluxMetric copies the influxDB line protocol metric <other>
|
// FromInfluxMetric copies the influxDB line protocol metric <other>
|
||||||
@@ -267,8 +247,10 @@ func FromInfluxMetric(other lp.Metric) CCMetric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// convertField converts data types of fields by the following schemata:
|
// convertField converts data types of fields by the following schemata:
|
||||||
|
//
|
||||||
// *float32, *float64, float32, float64 -> float64
|
// *float32, *float64, float32, float64 -> float64
|
||||||
// *int, *int8, *int16, *int32, *int64, int, int8, int16, int32, int64 -> int64
|
// *int, *int8, *int16, *int32, *int64, int, int8, int16, int32, int64 -> int64
|
||||||
|
//
|
||||||
// *uint, *uint8, *uint16, *uint32, *uint64, uint, uint8, uint16, uint32, uint64 -> uint64
|
// *uint, *uint8, *uint16, *uint32, *uint64, uint, uint8, uint16, uint32, uint64 -> uint64
|
||||||
// *[]byte, *string, []byte, string -> string
|
// *[]byte, *string, []byte, string -> string
|
||||||
// *bool, bool -> bool
|
// *bool, bool -> bool
|
||||||
463
pkg/ccTopology/ccTopology.go
Normal file
463
pkg/ccTopology/ccTopology.go
Normal file
@@ -0,0 +1,463 @@
|
|||||||
|
package ccTopology
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
cclogger "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
)
|
||||||
|
|
||||||
|
const SYSFS_CPUBASE = `/sys/devices/system/cpu`
|
||||||
|
|
||||||
|
// Structure holding all information about a hardware thread
|
||||||
|
// See https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-devices-system-cpu
|
||||||
|
type HwthreadEntry struct {
|
||||||
|
// for each CPUx:
|
||||||
|
CpuID int // CPU / hardware thread ID
|
||||||
|
SMT int // Simultaneous Multithreading ID
|
||||||
|
CoreCPUsList []int // CPUs within the same core
|
||||||
|
Core int // Socket local core ID
|
||||||
|
Socket int // Sockets (physical) ID
|
||||||
|
Die int // Die ID
|
||||||
|
NumaDomain int // NUMA Domain
|
||||||
|
}
|
||||||
|
|
||||||
|
var cache struct {
|
||||||
|
HwthreadList []int // List of CPU hardware threads
|
||||||
|
SMTList []int // List of symmetric hyper threading IDs
|
||||||
|
CoreList []int // List of CPU core IDs
|
||||||
|
SocketList []int // List of CPU sockets (physical) IDs
|
||||||
|
DieList []int // List of CPU Die IDs
|
||||||
|
NumaDomainList []int // List of NUMA Domains
|
||||||
|
|
||||||
|
CpuData []HwthreadEntry
|
||||||
|
}
|
||||||
|
|
||||||
|
// fileToInt reads an integer value from a sysfs file
|
||||||
|
// In case of an error -1 is returned
|
||||||
|
func fileToInt(path string) int {
|
||||||
|
buffer, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
cclogger.ComponentError("ccTopology", "fileToInt", "Reading", path, ":", err.Error())
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
stringBuffer := strings.TrimSpace(string(buffer))
|
||||||
|
id, err := strconv.Atoi(stringBuffer)
|
||||||
|
if err != nil {
|
||||||
|
cclogger.ComponentError("ccTopology", "fileToInt", "Parsing", path, ":", stringBuffer, err.Error())
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// fileToList reads a list from a sysfs file
|
||||||
|
// A list consists of value ranges separated by colon
|
||||||
|
// A range can be a single value or a range of values given by a startValue-endValue
|
||||||
|
// In case of an error nil is returned
|
||||||
|
func fileToList(path string) []int {
|
||||||
|
// Read list
|
||||||
|
buffer, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
cclogger.ComponentError("ccTopology", "fileToList", "Reading", path, ":", err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create list
|
||||||
|
list := make([]int, 0)
|
||||||
|
stringBuffer := strings.TrimSpace(string(buffer))
|
||||||
|
for _, valueRangeString := range strings.Split(stringBuffer, ",") {
|
||||||
|
valueRange := strings.Split(valueRangeString, "-")
|
||||||
|
switch len(valueRange) {
|
||||||
|
case 1:
|
||||||
|
singleValue, err := strconv.Atoi(valueRange[0])
|
||||||
|
if err != nil {
|
||||||
|
cclogger.ComponentError("CCTopology", "fileToList", "Parsing", valueRange[0], ":", err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
list = append(list, singleValue)
|
||||||
|
case 2:
|
||||||
|
startValue, err := strconv.Atoi(valueRange[0])
|
||||||
|
if err != nil {
|
||||||
|
cclogger.ComponentError("CCTopology", "fileToList", "Parsing", valueRange[0], ":", err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
endValue, err := strconv.Atoi(valueRange[1])
|
||||||
|
if err != nil {
|
||||||
|
cclogger.ComponentError("CCTopology", "fileToList", "Parsing", valueRange[1], ":", err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for value := startValue; value <= endValue; value++ {
|
||||||
|
list = append(list, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
// init initializes the cache structure
|
||||||
|
func init() {
|
||||||
|
|
||||||
|
getHWThreads :=
|
||||||
|
func() []int {
|
||||||
|
globPath := filepath.Join(SYSFS_CPUBASE, "cpu[0-9]*")
|
||||||
|
regexPath := filepath.Join(SYSFS_CPUBASE, "cpu([[:digit:]]+)")
|
||||||
|
regex := regexp.MustCompile(regexPath)
|
||||||
|
|
||||||
|
// File globbing for hardware threads
|
||||||
|
files, err := filepath.Glob(globPath)
|
||||||
|
if err != nil {
|
||||||
|
cclogger.ComponentError("CCTopology", "init:getHWThreads", err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
hwThreadIDs := make([]int, len(files))
|
||||||
|
for i, file := range files {
|
||||||
|
// Extract hardware thread ID
|
||||||
|
matches := regex.FindStringSubmatch(file)
|
||||||
|
if len(matches) != 2 {
|
||||||
|
cclogger.ComponentError("CCTopology", "init:getHWThreads: Failed to extract hardware thread ID from ", file)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert hardware thread ID to int
|
||||||
|
id, err := strconv.Atoi(matches[1])
|
||||||
|
if err != nil {
|
||||||
|
cclogger.ComponentError("CCTopology", "init:getHWThreads: Failed to convert to int hardware thread ID ", matches[1])
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
hwThreadIDs[i] = id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort hardware thread IDs
|
||||||
|
slices.Sort(hwThreadIDs)
|
||||||
|
return hwThreadIDs
|
||||||
|
}
|
||||||
|
|
||||||
|
getNumaDomain :=
|
||||||
|
func(basePath string) int {
|
||||||
|
globPath := filepath.Join(basePath, "node*")
|
||||||
|
regexPath := filepath.Join(basePath, "node([[:digit:]]+)")
|
||||||
|
regex := regexp.MustCompile(regexPath)
|
||||||
|
|
||||||
|
// File globbing for NUMA node
|
||||||
|
files, err := filepath.Glob(globPath)
|
||||||
|
if err != nil {
|
||||||
|
cclogger.ComponentError("CCTopology", "init:getNumaDomain", err.Error())
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check, that exactly one NUMA domain was found
|
||||||
|
if len(files) != 1 {
|
||||||
|
cclogger.ComponentError("CCTopology", "init:getNumaDomain", "Number of NUMA domains != 1: ", len(files))
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract NUMA node ID
|
||||||
|
matches := regex.FindStringSubmatch(files[0])
|
||||||
|
if len(matches) != 2 {
|
||||||
|
cclogger.ComponentError("CCTopology", "init:getNumaDomain", "Failed to extract NUMA node ID from: ", files[0])
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := strconv.Atoi(matches[1])
|
||||||
|
if err != nil {
|
||||||
|
cclogger.ComponentError("CCTopology", "init:getNumaDomain", "Failed to parse NUMA node ID from: ", matches[1])
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
cache.HwthreadList = getHWThreads()
|
||||||
|
cache.CoreList = make([]int, len(cache.HwthreadList))
|
||||||
|
cache.SocketList = make([]int, len(cache.HwthreadList))
|
||||||
|
cache.DieList = make([]int, len(cache.HwthreadList))
|
||||||
|
cache.SMTList = make([]int, len(cache.HwthreadList))
|
||||||
|
cache.NumaDomainList = make([]int, len(cache.HwthreadList))
|
||||||
|
cache.CpuData = make([]HwthreadEntry, len(cache.HwthreadList))
|
||||||
|
for i, c := range cache.HwthreadList {
|
||||||
|
// Set cpuBase directory for topology lookup
|
||||||
|
cpuBase := filepath.Join(SYSFS_CPUBASE, fmt.Sprintf("cpu%d", c))
|
||||||
|
topoBase := filepath.Join(cpuBase, "topology")
|
||||||
|
|
||||||
|
// Lookup Core ID
|
||||||
|
cache.CoreList[i] = fileToInt(filepath.Join(topoBase, "core_id"))
|
||||||
|
|
||||||
|
// Lookup socket / physical package ID
|
||||||
|
cache.SocketList[i] = fileToInt(filepath.Join(topoBase, "physical_package_id"))
|
||||||
|
|
||||||
|
// Lookup CPU die id
|
||||||
|
cache.DieList[i] = fileToInt(filepath.Join(topoBase, "die_id"))
|
||||||
|
if cache.DieList[i] < 0 {
|
||||||
|
cache.DieList[i] = cache.SocketList[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lookup List of CPUs within the same core
|
||||||
|
coreCPUsList := fileToList(filepath.Join(topoBase, "core_cpus_list"))
|
||||||
|
|
||||||
|
// Find index of CPU ID in List of CPUs within the same core
|
||||||
|
// if not found return -1
|
||||||
|
cache.SMTList[i] = slices.Index(coreCPUsList, c)
|
||||||
|
|
||||||
|
// Lookup NUMA domain id
|
||||||
|
cache.NumaDomainList[i] = getNumaDomain(cpuBase)
|
||||||
|
|
||||||
|
cache.CpuData[i] =
|
||||||
|
HwthreadEntry{
|
||||||
|
CpuID: cache.HwthreadList[i],
|
||||||
|
SMT: cache.SMTList[i],
|
||||||
|
CoreCPUsList: coreCPUsList,
|
||||||
|
Socket: cache.SocketList[i],
|
||||||
|
NumaDomain: cache.NumaDomainList[i],
|
||||||
|
Die: cache.DieList[i],
|
||||||
|
Core: cache.CoreList[i],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
slices.Sort(cache.HwthreadList)
|
||||||
|
cache.HwthreadList = slices.Compact(cache.HwthreadList)
|
||||||
|
|
||||||
|
slices.Sort(cache.SMTList)
|
||||||
|
cache.SMTList = slices.Compact(cache.SMTList)
|
||||||
|
|
||||||
|
slices.Sort(cache.CoreList)
|
||||||
|
cache.CoreList = slices.Compact(cache.CoreList)
|
||||||
|
|
||||||
|
slices.Sort(cache.SocketList)
|
||||||
|
cache.SocketList = slices.Compact(cache.SocketList)
|
||||||
|
|
||||||
|
slices.Sort(cache.DieList)
|
||||||
|
cache.DieList = slices.Compact(cache.DieList)
|
||||||
|
|
||||||
|
slices.Sort(cache.NumaDomainList)
|
||||||
|
cache.NumaDomainList = slices.Compact(cache.NumaDomainList)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SocketList gets the list of CPU socket IDs
|
||||||
|
func SocketList() []int {
|
||||||
|
return slices.Clone(cache.SocketList)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HwthreadList gets the list of hardware thread IDs in the order of listing in /proc/cpuinfo
|
||||||
|
func HwthreadList() []int {
|
||||||
|
return slices.Clone(cache.HwthreadList)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get list of hardware thread IDs in the order of listing in /proc/cpuinfo
|
||||||
|
// Deprecated! Use HwthreadList()
|
||||||
|
func CpuList() []int {
|
||||||
|
return HwthreadList()
|
||||||
|
}
|
||||||
|
|
||||||
|
// CoreList gets the list of CPU core IDs in the order of listing in /proc/cpuinfo
|
||||||
|
func CoreList() []int {
|
||||||
|
return slices.Clone(cache.CoreList)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get list of NUMA node IDs
|
||||||
|
func NumaNodeList() []int {
|
||||||
|
return slices.Clone(cache.NumaDomainList)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DieList gets the list of CPU die IDs
|
||||||
|
func DieList() []int {
|
||||||
|
if len(cache.DieList) > 0 {
|
||||||
|
return slices.Clone(cache.DieList)
|
||||||
|
}
|
||||||
|
return SocketList()
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTypeList gets the list of specified type using the naming format inside ClusterCockpit
|
||||||
|
func GetTypeList(topology_type string) []int {
|
||||||
|
switch topology_type {
|
||||||
|
case "node":
|
||||||
|
return []int{0}
|
||||||
|
case "socket":
|
||||||
|
return SocketList()
|
||||||
|
case "die":
|
||||||
|
return DieList()
|
||||||
|
case "memoryDomain":
|
||||||
|
return NumaNodeList()
|
||||||
|
case "core":
|
||||||
|
return CoreList()
|
||||||
|
case "hwthread":
|
||||||
|
return HwthreadList()
|
||||||
|
}
|
||||||
|
return []int{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTypeId(hwt HwthreadEntry, topology_type string) (int, error) {
|
||||||
|
var err error = nil
|
||||||
|
switch topology_type {
|
||||||
|
case "node":
|
||||||
|
return 0, err
|
||||||
|
case "socket":
|
||||||
|
return hwt.Socket, err
|
||||||
|
case "die":
|
||||||
|
return hwt.Die, err
|
||||||
|
case "memoryDomain":
|
||||||
|
return hwt.NumaDomain, err
|
||||||
|
case "core":
|
||||||
|
return hwt.Core, err
|
||||||
|
case "hwthread":
|
||||||
|
return hwt.CpuID, err
|
||||||
|
}
|
||||||
|
return -1, fmt.Errorf("unknown topology type '%s'", topology_type)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpuData returns CPU data for each hardware thread
|
||||||
|
func CpuData() []HwthreadEntry {
|
||||||
|
// return a deep copy to protect cache data
|
||||||
|
c := slices.Clone(cache.CpuData)
|
||||||
|
for i := range c {
|
||||||
|
c[i].CoreCPUsList = slices.Clone(cache.CpuData[i].CoreCPUsList)
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// Structure holding basic information about a CPU
|
||||||
|
type CpuInformation struct {
|
||||||
|
NumHWthreads int
|
||||||
|
SMTWidth int
|
||||||
|
NumSockets int
|
||||||
|
NumDies int
|
||||||
|
NumCores int
|
||||||
|
NumNumaDomains int
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpuInformation reports basic information about the CPU
|
||||||
|
func CpuInfo() CpuInformation {
|
||||||
|
return CpuInformation{
|
||||||
|
NumNumaDomains: len(cache.NumaDomainList),
|
||||||
|
SMTWidth: len(cache.SMTList),
|
||||||
|
NumDies: len(cache.DieList),
|
||||||
|
NumCores: len(cache.CoreList),
|
||||||
|
NumSockets: len(cache.SocketList),
|
||||||
|
NumHWthreads: len(cache.HwthreadList),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHwthreadSocket gets the CPU socket ID for a given hardware thread ID
|
||||||
|
// In case hardware thread ID is not found -1 is returned
|
||||||
|
func GetHwthreadSocket(cpuID int) int {
|
||||||
|
for i := range cache.CpuData {
|
||||||
|
d := &cache.CpuData[i]
|
||||||
|
if d.CpuID == cpuID {
|
||||||
|
return d.Socket
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHwthreadNumaDomain gets the NUMA domain ID for a given hardware thread ID
|
||||||
|
// In case hardware thread ID is not found -1 is returned
|
||||||
|
func GetHwthreadNumaDomain(cpuID int) int {
|
||||||
|
for i := range cache.CpuData {
|
||||||
|
d := &cache.CpuData[i]
|
||||||
|
if d.CpuID == cpuID {
|
||||||
|
return d.NumaDomain
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHwthreadDie gets the CPU die ID for a given hardware thread ID
|
||||||
|
// In case hardware thread ID is not found -1 is returned
|
||||||
|
func GetHwthreadDie(cpuID int) int {
|
||||||
|
for i := range cache.CpuData {
|
||||||
|
d := &cache.CpuData[i]
|
||||||
|
if d.CpuID == cpuID {
|
||||||
|
return d.Die
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHwthreadCore gets the CPU core ID for a given hardware thread ID
|
||||||
|
// In case hardware thread ID is not found -1 is returned
|
||||||
|
func GetHwthreadCore(cpuID int) int {
|
||||||
|
for i := range cache.CpuData {
|
||||||
|
d := &cache.CpuData[i]
|
||||||
|
if d.CpuID == cpuID {
|
||||||
|
return d.Core
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSocketHwthreads gets all hardware thread IDs associated with a CPU socket
|
||||||
|
func GetSocketHwthreads(socket int) []int {
|
||||||
|
cpuList := make([]int, 0)
|
||||||
|
for i := range cache.CpuData {
|
||||||
|
d := &cache.CpuData[i]
|
||||||
|
if d.Socket == socket {
|
||||||
|
cpuList = append(cpuList, d.CpuID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cpuList
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetNumaDomainHwthreads gets the all hardware thread IDs associated with a NUMA domain
|
||||||
|
func GetNumaDomainHwthreads(numaDomain int) []int {
|
||||||
|
cpuList := make([]int, 0)
|
||||||
|
for i := range cache.CpuData {
|
||||||
|
d := &cache.CpuData[i]
|
||||||
|
if d.NumaDomain == numaDomain {
|
||||||
|
cpuList = append(cpuList, d.CpuID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cpuList
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDieHwthreads gets all hardware thread IDs associated with a CPU die
|
||||||
|
func GetDieHwthreads(die int) []int {
|
||||||
|
cpuList := make([]int, 0)
|
||||||
|
for i := range cache.CpuData {
|
||||||
|
d := &cache.CpuData[i]
|
||||||
|
if d.Die == die {
|
||||||
|
cpuList = append(cpuList, d.CpuID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cpuList
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCoreHwthreads get all hardware thread IDs associated with a CPU core
|
||||||
|
func GetCoreHwthreads(core int) []int {
|
||||||
|
cpuList := make([]int, 0)
|
||||||
|
for i := range cache.CpuData {
|
||||||
|
d := &cache.CpuData[i]
|
||||||
|
if d.Core == core {
|
||||||
|
cpuList = append(cpuList, d.CpuID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cpuList
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTypeList gets the list of specified type using the naming format inside ClusterCockpit
|
||||||
|
func GetTypeHwthreads(topology_type string, id int) []int {
|
||||||
|
switch topology_type {
|
||||||
|
case "node":
|
||||||
|
return HwthreadList()
|
||||||
|
case "socket":
|
||||||
|
return GetSocketHwthreads(id)
|
||||||
|
case "die":
|
||||||
|
return GetDieHwthreads(id)
|
||||||
|
case "memoryDomain":
|
||||||
|
return GetNumaDomainHwthreads(id)
|
||||||
|
case "core":
|
||||||
|
return GetCoreHwthreads(id)
|
||||||
|
case "hwthread":
|
||||||
|
return []int{id}
|
||||||
|
}
|
||||||
|
return []int{}
|
||||||
|
}
|
||||||
125
pkg/hostlist/hostlist.go
Normal file
125
pkg/hostlist/hostlist.go
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
package hostlist
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Expand(in string) (result []string, err error) {
|
||||||
|
|
||||||
|
// Create ranges regular expression
|
||||||
|
reStNumber := "[[:digit:]]+"
|
||||||
|
reStRange := reStNumber + "-" + reStNumber
|
||||||
|
reStOptionalNumberOrRange := "(" + reStNumber + ",|" + reStRange + ",)*"
|
||||||
|
reStNumberOrRange := "(" + reStNumber + "|" + reStRange + ")"
|
||||||
|
reStBraceLeft := "[[]"
|
||||||
|
reStBraceRight := "[]]"
|
||||||
|
reStRanges := reStBraceLeft +
|
||||||
|
reStOptionalNumberOrRange +
|
||||||
|
reStNumberOrRange +
|
||||||
|
reStBraceRight
|
||||||
|
reRanges := regexp.MustCompile(reStRanges)
|
||||||
|
|
||||||
|
// Create host list regular expression
|
||||||
|
reStDNSChars := "[a-zA-Z0-9-]+"
|
||||||
|
reStPrefix := "^(" + reStDNSChars + ")"
|
||||||
|
reStOptionalSuffix := "(" + reStDNSChars + ")?"
|
||||||
|
re := regexp.MustCompile(reStPrefix + "([[][0-9,-]+[]])?" + reStOptionalSuffix)
|
||||||
|
|
||||||
|
// Remove all delimiters from the input
|
||||||
|
in = strings.TrimLeft(in, ", ")
|
||||||
|
|
||||||
|
for len(in) > 0 {
|
||||||
|
if v := re.FindStringSubmatch(in); v != nil {
|
||||||
|
|
||||||
|
// Remove matched part from the input
|
||||||
|
lenPrefix := len(v[0])
|
||||||
|
in = in[lenPrefix:]
|
||||||
|
|
||||||
|
// Remove all delimiters from the input
|
||||||
|
in = strings.TrimLeft(in, ", ")
|
||||||
|
|
||||||
|
// matched prefix, range and suffix
|
||||||
|
hlPrefix := v[1]
|
||||||
|
hlRanges := v[2]
|
||||||
|
hlSuffix := v[3]
|
||||||
|
|
||||||
|
// Single node without ranges
|
||||||
|
if hlRanges == "" {
|
||||||
|
result = append(result, hlPrefix)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Node with ranges
|
||||||
|
if v := reRanges.FindStringSubmatch(hlRanges); v != nil {
|
||||||
|
|
||||||
|
// Remove braces
|
||||||
|
hlRanges = hlRanges[1 : len(hlRanges)-1]
|
||||||
|
|
||||||
|
// Split host ranges at ,
|
||||||
|
for _, hlRange := range strings.Split(hlRanges, ",") {
|
||||||
|
|
||||||
|
// Split host range at -
|
||||||
|
RangeStartEnd := strings.Split(hlRange, "-")
|
||||||
|
|
||||||
|
// Range is only a single number
|
||||||
|
if len(RangeStartEnd) == 1 {
|
||||||
|
result = append(result, hlPrefix+RangeStartEnd[0]+hlSuffix)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Range has a start and an end
|
||||||
|
widthRangeStart := len(RangeStartEnd[0])
|
||||||
|
widthRangeEnd := len(RangeStartEnd[1])
|
||||||
|
iStart, _ := strconv.ParseUint(RangeStartEnd[0], 10, 64)
|
||||||
|
iEnd, _ := strconv.ParseUint(RangeStartEnd[1], 10, 64)
|
||||||
|
if iStart > iEnd {
|
||||||
|
return nil, fmt.Errorf("single range start is greater than end: %s", hlRange)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create print format string for range numbers
|
||||||
|
doPadding := widthRangeStart == widthRangeEnd
|
||||||
|
widthPadding := widthRangeStart
|
||||||
|
var formatString string
|
||||||
|
if doPadding {
|
||||||
|
formatString = "%0" + fmt.Sprint(widthPadding) + "d"
|
||||||
|
} else {
|
||||||
|
formatString = "%d"
|
||||||
|
}
|
||||||
|
formatString = hlPrefix + formatString + hlSuffix
|
||||||
|
|
||||||
|
// Add nodes from this range
|
||||||
|
for i := iStart; i <= iEnd; i++ {
|
||||||
|
result = append(result, fmt.Sprintf(formatString, i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("not at hostlist range: %s", hlRanges)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("not a hostlist: %s", in)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if result != nil {
|
||||||
|
// sort
|
||||||
|
sort.Strings(result)
|
||||||
|
|
||||||
|
// uniq
|
||||||
|
previous := 1
|
||||||
|
for current := 1; current < len(result); current++ {
|
||||||
|
if result[current-1] != result[current] {
|
||||||
|
if previous != current {
|
||||||
|
result[previous] = result[current]
|
||||||
|
}
|
||||||
|
previous++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = result[:previous]
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
126
pkg/hostlist/hostlist_test.go
Normal file
126
pkg/hostlist/hostlist_test.go
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
package hostlist
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestExpand(t *testing.T) {
|
||||||
|
|
||||||
|
// Compare two slices of strings
|
||||||
|
equal := func(a, b []string) bool {
|
||||||
|
if len(a) != len(b) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i, v := range a {
|
||||||
|
if v != b[i] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
type testDefinition struct {
|
||||||
|
input string
|
||||||
|
resultExpected []string
|
||||||
|
errorExpected bool
|
||||||
|
}
|
||||||
|
|
||||||
|
expandTests := []testDefinition{
|
||||||
|
{
|
||||||
|
// Single node
|
||||||
|
input: "n1",
|
||||||
|
resultExpected: []string{"n1"},
|
||||||
|
errorExpected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Single node, duplicated
|
||||||
|
input: "n1,n1",
|
||||||
|
resultExpected: []string{"n1"},
|
||||||
|
errorExpected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Single node with padding
|
||||||
|
input: "n[01]",
|
||||||
|
resultExpected: []string{"n01"},
|
||||||
|
errorExpected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Single node with suffix
|
||||||
|
input: "n[01]-p",
|
||||||
|
resultExpected: []string{"n01-p"},
|
||||||
|
errorExpected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Multiple nodes with a single range
|
||||||
|
input: "n[1-2]",
|
||||||
|
resultExpected: []string{"n1", "n2"},
|
||||||
|
errorExpected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Multiple nodes with a single range and a single index
|
||||||
|
input: "n[1-2,3]",
|
||||||
|
resultExpected: []string{"n1", "n2", "n3"},
|
||||||
|
errorExpected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Multiple nodes with different prefixes
|
||||||
|
input: "n[1-2],m[1,2]",
|
||||||
|
resultExpected: []string{"m1", "m2", "n1", "n2"},
|
||||||
|
errorExpected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Multiple nodes with different suffixes
|
||||||
|
input: "n[1-2]-p,n[1,2]-q",
|
||||||
|
resultExpected: []string{"n1-p", "n1-q", "n2-p", "n2-q"},
|
||||||
|
errorExpected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Multiple nodes with and without node ranges
|
||||||
|
input: " n09, n[01-04,06-07,09] , , n10,n04",
|
||||||
|
resultExpected: []string{"n01", "n02", "n03", "n04", "n06", "n07", "n09", "n10"},
|
||||||
|
errorExpected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Forbidden DNS character
|
||||||
|
input: "n@",
|
||||||
|
resultExpected: []string{},
|
||||||
|
errorExpected: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Forbidden range
|
||||||
|
input: "n[1-2-2,3]",
|
||||||
|
resultExpected: []string{},
|
||||||
|
errorExpected: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Forbidden range limits
|
||||||
|
input: "n[2-1]",
|
||||||
|
resultExpected: []string{},
|
||||||
|
errorExpected: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, expandTest := range expandTests {
|
||||||
|
result, err := Expand(expandTest.input)
|
||||||
|
|
||||||
|
hasError := err != nil
|
||||||
|
if hasError != expandTest.errorExpected && hasError {
|
||||||
|
t.Errorf("Expand('%s') failed: unexpected error '%v'",
|
||||||
|
expandTest.input, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if hasError != expandTest.errorExpected && !hasError {
|
||||||
|
t.Errorf("Expand('%s') did not fail as expected: got result '%+v'",
|
||||||
|
expandTest.input, result)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !hasError && !equal(result, expandTest.resultExpected) {
|
||||||
|
t.Errorf("Expand('%s') failed: got result '%+v', expected result '%v'",
|
||||||
|
expandTest.input, result, expandTest.resultExpected)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("Checked hostlist.Expand('%s'): result = '%+v', err = '%v'",
|
||||||
|
expandTest.input, result, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
266
pkg/messageProcessor/README.md
Normal file
266
pkg/messageProcessor/README.md
Normal file
@@ -0,0 +1,266 @@
|
|||||||
|
# Message Processor Component
|
||||||
|
|
||||||
|
Multiple parts of in the ClusterCockit ecosystem require the processing of CCMessages.
|
||||||
|
The main CC application using it is `cc-metric-collector`. The processing part there was originally in the metric router, the central
|
||||||
|
hub connecting collectors (reading local data), receivers (receiving remote data) and sinks (sending data). Already in early stages, the
|
||||||
|
lack of flexibility caused some trouble:
|
||||||
|
|
||||||
|
> The sysadmins wanted to keep operating their Ganglia based monitoring infrastructure while we developed the CC stack. Ganglia wants the core metrics with
|
||||||
|
> a specific name and resolution (right unit prefix) but there was no conversion of the data in the CC stack, so CC frontend developers wanted a different
|
||||||
|
> resolution for some metrics. The issue was basically the `mem_used` metric showing the currently used memory of the node. Ganglia wants it in `kByte` as provided
|
||||||
|
> by the Linux operating system but CC wanted it in `GByte`.
|
||||||
|
|
||||||
|
With the message processor, the Ganglia sinks can apply the unit prefix changes individually and name the metrics as required by Ganglia.
|
||||||
|
|
||||||
|
## For developers
|
||||||
|
|
||||||
|
Whenever you receive or are about to send a message out, you should provide some processing.
|
||||||
|
|
||||||
|
### Configuration of component
|
||||||
|
|
||||||
|
New operations can be added to the message processor at runtime. Of course, they can also be removed again. For the initial setup, having a configuration file
|
||||||
|
or some fields in a configuration file for the processing.
|
||||||
|
|
||||||
|
The message processor uses the following configuration
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"drop_messages": [
|
||||||
|
"name_of_message_to_drop"
|
||||||
|
],
|
||||||
|
"drop_messages_if": [
|
||||||
|
"condition_when_to_drop_message",
|
||||||
|
"name == 'drop_this'",
|
||||||
|
"tag.hostname == 'this_host'",
|
||||||
|
"meta.unit != 'MB'"
|
||||||
|
],
|
||||||
|
"rename_messages" : {
|
||||||
|
"old_message_name" : "new_message_name"
|
||||||
|
},
|
||||||
|
"rename_messages_if": {
|
||||||
|
"condition_when_to_rename_message" : "new_name"
|
||||||
|
},
|
||||||
|
"add_tags_if": [
|
||||||
|
{
|
||||||
|
"if" : "condition_when_to_add_tag",
|
||||||
|
"key": "name_for_new_tag",
|
||||||
|
"value": "new_tag_value"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"delete_tags_if": [
|
||||||
|
{
|
||||||
|
"if" : "condition_when_to_delete_tag",
|
||||||
|
"key": "name_of_tag"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"add_meta_if": [
|
||||||
|
{
|
||||||
|
"if" : "condition_when_to_add_meta_info",
|
||||||
|
"key": "name_for_new_meta_info",
|
||||||
|
"value": "new_meta_info_value"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"delete_meta_if": [
|
||||||
|
{
|
||||||
|
"if" : "condition_when_to_delete_meta_info",
|
||||||
|
"key": "name_of_meta_info"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"add_field_if": [
|
||||||
|
{
|
||||||
|
"if" : "condition_when_to_add_field",
|
||||||
|
"key": "name_for_new_field",
|
||||||
|
"value": "new_field_value_but_only_string_at_the_moment"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"delete_field_if": [
|
||||||
|
{
|
||||||
|
"if" : "condition_when_to_delete_field",
|
||||||
|
"key": "name_of_field"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"move_tag_to_meta_if": [
|
||||||
|
{
|
||||||
|
"if" : "condition_when_to_move_tag_to_meta_info_including_its_value",
|
||||||
|
"key": "name_of_tag",
|
||||||
|
"value": "name_of_meta_info"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"move_tag_to_field_if": [
|
||||||
|
{
|
||||||
|
"if" : "condition_when_to_move_tag_to_fields_including_its_value",
|
||||||
|
"key": "name_of_tag",
|
||||||
|
"value": "name_of_field"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"move_meta_to_tag_if": [
|
||||||
|
{
|
||||||
|
"if" : "condition_when_to_move_meta_info_to_tags_including_its_value",
|
||||||
|
"key": "name_of_meta_info",
|
||||||
|
"value": "name_of_tag"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"move_meta_to_field_if": [
|
||||||
|
{
|
||||||
|
"if" : "condition_when_to_move_meta_info_to_fields_including_its_value",
|
||||||
|
"key": "name_of_tag",
|
||||||
|
"value": "name_of_meta_info"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"move_field_to_tag_if": [
|
||||||
|
{
|
||||||
|
"if" : "condition_when_to_move_field_to_tags_including_its_stringified_value",
|
||||||
|
"key": "name_of_field",
|
||||||
|
"value": "name_of_tag"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"move_field_to_meta_if": [
|
||||||
|
{
|
||||||
|
"if" : "condition_when_to_move_field_to_meta_info_including_its_stringified_value",
|
||||||
|
"key": "name_of_field",
|
||||||
|
"value": "name_of_meta_info"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"drop_by_message_type": [
|
||||||
|
"metric",
|
||||||
|
"event",
|
||||||
|
"log",
|
||||||
|
"control"
|
||||||
|
],
|
||||||
|
"change_unit_prefix": {
|
||||||
|
"name == 'metric_with_wrong_unit_prefix'" : "G",
|
||||||
|
"only_if_messagetype == 'metric'": "T"
|
||||||
|
},
|
||||||
|
"normalize_units": true,
|
||||||
|
"add_base_env": {
|
||||||
|
"MY_CONSTANT_FOR_CUSTOM_CONDITIONS": 1.0,
|
||||||
|
"output_value_for_test_metrics": 42.0,
|
||||||
|
},
|
||||||
|
"stage_order": [
|
||||||
|
"rename_messages_if",
|
||||||
|
"drop_messages"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The options `change_unit_prefix` and `normalize_units` are only applied to CCMetrics. It is not possible to delete the field related to each message type as defined in [cc-specification](https://github.com/ClusterCockpit/cc-specifications/tree/master/interfaces/lineprotocol). In short:
|
||||||
|
- CCMetrics always have to have a field named `value`
|
||||||
|
- CCEvents always have to have a field named `event`
|
||||||
|
- CCLogs always have to have a field named `log`
|
||||||
|
- CCControl messages always have to have a field named `control`
|
||||||
|
|
||||||
|
With `add_base_env`, one can specifiy mykey=myvalue pairs that can be used in conditions like `tag.type == mykey`.
|
||||||
|
|
||||||
|
The order in which each message is processed, can be specified with the `stage_order` option. The stage names are the keys in the JSON configuration, thus `change_unit_prefix`, `move_field_to_meta_if`, etc. Stages can be listed multiple times.
|
||||||
|
|
||||||
|
### Using the component
|
||||||
|
In order to load the configuration from a `json.RawMessage`:
|
||||||
|
```golang
|
||||||
|
mp, err := NewMessageProcessor()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("failed to create new message processor")
|
||||||
|
}
|
||||||
|
mp.FromConfigJSON(configJson)
|
||||||
|
```
|
||||||
|
|
||||||
|
After initialization and adding the different operations, the `ProcessMessage()` function applies all operations and returns whether the message should be dropped.
|
||||||
|
|
||||||
|
```golang
|
||||||
|
m := lp.CCMetric{}
|
||||||
|
|
||||||
|
x, err := mp.ProcessMessage(m)
|
||||||
|
if err != nil {
|
||||||
|
// handle error
|
||||||
|
}
|
||||||
|
if x != nil {
|
||||||
|
// process x further
|
||||||
|
} else {
|
||||||
|
// this message got dropped
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Single operations can be added and removed at runtime
|
||||||
|
```golang
|
||||||
|
type MessageProcessor interface {
|
||||||
|
// Functions to set the execution order of the processing stages
|
||||||
|
SetStages([]string) error
|
||||||
|
DefaultStages() []string
|
||||||
|
// Function to add variables to the base evaluation environment
|
||||||
|
AddBaseEnv(env map[string]interface{}) error
|
||||||
|
// Functions to add and remove rules
|
||||||
|
AddDropMessagesByName(name string) error
|
||||||
|
RemoveDropMessagesByName(name string)
|
||||||
|
AddDropMessagesByCondition(condition string) error
|
||||||
|
RemoveDropMessagesByCondition(condition string)
|
||||||
|
AddRenameMetricByCondition(condition string, name string) error
|
||||||
|
RemoveRenameMetricByCondition(condition string)
|
||||||
|
AddRenameMetricByName(from, to string) error
|
||||||
|
RemoveRenameMetricByName(from string)
|
||||||
|
SetNormalizeUnits(settings bool)
|
||||||
|
AddChangeUnitPrefix(condition string, prefix string) error
|
||||||
|
RemoveChangeUnitPrefix(condition string)
|
||||||
|
AddAddTagsByCondition(condition, key, value string) error
|
||||||
|
RemoveAddTagsByCondition(condition string)
|
||||||
|
AddDeleteTagsByCondition(condition, key, value string) error
|
||||||
|
RemoveDeleteTagsByCondition(condition string)
|
||||||
|
AddAddMetaByCondition(condition, key, value string) error
|
||||||
|
RemoveAddMetaByCondition(condition string)
|
||||||
|
AddDeleteMetaByCondition(condition, key, value string) error
|
||||||
|
RemoveDeleteMetaByCondition(condition string)
|
||||||
|
AddMoveTagToMeta(condition, key, value string) error
|
||||||
|
RemoveMoveTagToMeta(condition string)
|
||||||
|
AddMoveTagToFields(condition, key, value string) error
|
||||||
|
RemoveMoveTagToFields(condition string)
|
||||||
|
AddMoveMetaToTags(condition, key, value string) error
|
||||||
|
RemoveMoveMetaToTags(condition string)
|
||||||
|
AddMoveMetaToFields(condition, key, value string) error
|
||||||
|
RemoveMoveMetaToFields(condition string)
|
||||||
|
AddMoveFieldToTags(condition, key, value string) error
|
||||||
|
RemoveMoveFieldToTags(condition string)
|
||||||
|
AddMoveFieldToMeta(condition, key, value string) error
|
||||||
|
RemoveMoveFieldToMeta(condition string)
|
||||||
|
// Read in a JSON configuration
|
||||||
|
FromConfigJSON(config json.RawMessage) error
|
||||||
|
ProcessMessage(m lp2.CCMessage) (lp2.CCMessage, error)
|
||||||
|
// Processing functions for legacy CCMetric and current CCMessage
|
||||||
|
ProcessMetric(m lp.CCMetric) (lp2.CCMessage, error)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Syntax for evaluatable terms
|
||||||
|
|
||||||
|
The message processor uses `gval` for evaluating the terms. It provides a basic set of operators like string comparison and arithmetic operations.
|
||||||
|
|
||||||
|
Accessible for operations are
|
||||||
|
- `name` of the message
|
||||||
|
- `timestamp` or `time` of the message
|
||||||
|
- `type`, `type-id` of the message (also `tag_type`, `tag_type-id` and `tag_typeid`)
|
||||||
|
- `stype`, `stype-id` of the message (if message has theses tags, also `tag_stype`, `tag_stype-id` and `tag_stypeid`)
|
||||||
|
- `value` for a CCMetric message (also `field_value`)
|
||||||
|
- `event` for a CCEvent message (also `field_event`)
|
||||||
|
- `control` for a CCControl message (also `field_control`)
|
||||||
|
- `log` for a CCLog message (also `field_log`)
|
||||||
|
- `messagetype` or `msgtype`. Possible values `event`, `metric`, `log` and `control`.
|
||||||
|
|
||||||
|
Generally, all tags are accessible with `tag_<tagkey>`, `tags_<tagkey>` or `tags.<tagkey>`. Similarly for all fields with `field[s]?[_.]<fieldkey>`. For meta information `meta[_.]<metakey>` (there is no `metas[_.]<metakey>`).
|
||||||
|
|
||||||
|
The [syntax of `expr`](https://expr-lang.org/docs/language-definition) is accepted with some additions:
|
||||||
|
- Comparing strings: `==`, `!=`, `str matches regex` (use `%` instead of `\`!)
|
||||||
|
- Combining conditions: `&&`, `||`
|
||||||
|
- Comparing numbers: `==`, `!=`, `<`, `>`, `<=`, `>=`
|
||||||
|
- Test lists: `<value> in <list>`
|
||||||
|
- Topological tests: `tag_type-id in getCpuListOfType("socket", "1")` (test if the metric belongs to socket 1 in local node topology)
|
||||||
|
|
||||||
|
Often the operations are written in JSON files for loading them at startup. In JSON, some characters are not allowed. Therefore, the term syntax reflects that:
|
||||||
|
- use `''` instead of `""` for strings
|
||||||
|
- for the regexes, use `%` instead of `\`
|
||||||
|
|
||||||
|
|
||||||
|
For operations that should be applied on all messages, use the condition `true`.
|
||||||
|
|
||||||
|
### Overhead
|
||||||
|
|
||||||
|
The operations taking conditions are pre-processed, which is commonly the time consuming part but, of course, with each added operation, the time to process a message
|
||||||
|
increases. Moreover, the processing creates a copy of the message.
|
||||||
|
|
||||||
988
pkg/messageProcessor/messageProcessor.go
Normal file
988
pkg/messageProcessor/messageProcessor.go
Normal file
@@ -0,0 +1,988 @@
|
|||||||
|
package messageprocessor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
lplegacy "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
|
||||||
|
|
||||||
|
"github.com/expr-lang/expr"
|
||||||
|
"github.com/expr-lang/expr/vm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Message processor add/delete tag/meta configuration
|
||||||
|
type messageProcessorTagConfig struct {
|
||||||
|
Key string `json:"key"` // Tag name
|
||||||
|
Value string `json:"value,omitempty"` // Tag value
|
||||||
|
Condition string `json:"if"` // Condition for adding or removing corresponding tag
|
||||||
|
}
|
||||||
|
|
||||||
|
type messageProcessorConfig struct {
|
||||||
|
StageOrder []string `json:"stage_order,omitempty"` // List of stages to execute them in the specified order and to skip unrequired ones
|
||||||
|
DropMessages []string `json:"drop_messages,omitempty"` // List of metric names to drop. For fine-grained dropping use drop_messages_if
|
||||||
|
DropMessagesIf []string `json:"drop_messages_if,omitempty"` // List of evaluatable terms to drop messages
|
||||||
|
RenameMessages map[string]string `json:"rename_messages,omitempty"` // Map of metric names to rename
|
||||||
|
RenameMessagesIf map[string]string `json:"rename_messages_if,omitempty"` // Map to rename metric name based on a condition
|
||||||
|
NormalizeUnits bool `json:"normalize_units,omitempty"` // Check unit meta flag and normalize it using cc-units
|
||||||
|
ChangeUnitPrefix map[string]string `json:"change_unit_prefix,omitempty"` // Add prefix that should be applied to the messages
|
||||||
|
AddTagsIf []messageProcessorTagConfig `json:"add_tags_if"` // List of tags that are added when the condition is met
|
||||||
|
DelTagsIf []messageProcessorTagConfig `json:"delete_tags_if"` // List of tags that are removed when the condition is met
|
||||||
|
AddMetaIf []messageProcessorTagConfig `json:"add_meta_if"` // List of meta infos that are added when the condition is met
|
||||||
|
DelMetaIf []messageProcessorTagConfig `json:"delete_meta_if"` // List of meta infos that are removed when the condition is met
|
||||||
|
AddFieldIf []messageProcessorTagConfig `json:"add_field_if"` // List of fields that are added when the condition is met
|
||||||
|
DelFieldIf []messageProcessorTagConfig `json:"delete_field_if"` // List of fields that are removed when the condition is met
|
||||||
|
DropByType []string `json:"drop_by_message_type"` // List of message types that should be dropped
|
||||||
|
MoveTagToMeta []messageProcessorTagConfig `json:"move_tag_to_meta_if"`
|
||||||
|
MoveTagToField []messageProcessorTagConfig `json:"move_tag_to_field_if"`
|
||||||
|
MoveMetaToTag []messageProcessorTagConfig `json:"move_meta_to_tag_if"`
|
||||||
|
MoveMetaToField []messageProcessorTagConfig `json:"move_meta_to_field_if"`
|
||||||
|
MoveFieldToTag []messageProcessorTagConfig `json:"move_field_to_tag_if"`
|
||||||
|
MoveFieldToMeta []messageProcessorTagConfig `json:"move_field_to_meta_if"`
|
||||||
|
AddBaseEnv map[string]interface{} `json:"add_base_env"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type messageProcessor struct {
|
||||||
|
|
||||||
|
// For thread-safety
|
||||||
|
mutex sync.RWMutex
|
||||||
|
|
||||||
|
// mapping contains all evalables as strings to gval.Evaluable
|
||||||
|
// because it is not possible to get the original string out of
|
||||||
|
// a gval.Evaluable
|
||||||
|
mapping map[string]*vm.Program
|
||||||
|
|
||||||
|
stages []string // order of stage execution
|
||||||
|
dropMessages map[string]struct{} // internal lookup map
|
||||||
|
dropTypes map[string]struct{} // internal lookup map
|
||||||
|
dropMessagesIf map[*vm.Program]struct{} // pre-processed dropMessagesIf
|
||||||
|
renameMessages map[string]string // internal lookup map
|
||||||
|
renameMessagesIf map[*vm.Program]string // pre-processed RenameMessagesIf
|
||||||
|
changeUnitPrefix map[*vm.Program]string // pre-processed ChangeUnitPrefix
|
||||||
|
normalizeUnits bool
|
||||||
|
addTagsIf map[*vm.Program]messageProcessorTagConfig // pre-processed AddTagsIf
|
||||||
|
deleteTagsIf map[*vm.Program]messageProcessorTagConfig // pre-processed DelTagsIf
|
||||||
|
addMetaIf map[*vm.Program]messageProcessorTagConfig // pre-processed AddMetaIf
|
||||||
|
deleteMetaIf map[*vm.Program]messageProcessorTagConfig // pre-processed DelMetaIf
|
||||||
|
addFieldIf map[*vm.Program]messageProcessorTagConfig // pre-processed AddFieldIf
|
||||||
|
deleteFieldIf map[*vm.Program]messageProcessorTagConfig // pre-processed DelFieldIf
|
||||||
|
moveTagToMeta map[*vm.Program]messageProcessorTagConfig // pre-processed MoveTagToMeta
|
||||||
|
moveTagToField map[*vm.Program]messageProcessorTagConfig // pre-processed MoveTagToField
|
||||||
|
moveMetaToTag map[*vm.Program]messageProcessorTagConfig // pre-processed MoveMetaToTag
|
||||||
|
moveMetaToField map[*vm.Program]messageProcessorTagConfig // pre-processed MoveMetaToField
|
||||||
|
moveFieldToTag map[*vm.Program]messageProcessorTagConfig // pre-processed MoveFieldToTag
|
||||||
|
moveFieldToMeta map[*vm.Program]messageProcessorTagConfig // pre-processed MoveFieldToMeta
|
||||||
|
}
|
||||||
|
|
||||||
|
type MessageProcessor interface {
|
||||||
|
// Functions to set the execution order of the processing stages
|
||||||
|
SetStages([]string) error
|
||||||
|
DefaultStages() []string
|
||||||
|
// Function to add variables to the base evaluation environment
|
||||||
|
AddBaseEnv(env map[string]interface{}) error
|
||||||
|
// Functions to add and remove rules
|
||||||
|
AddDropMessagesByName(name string) error
|
||||||
|
RemoveDropMessagesByName(name string)
|
||||||
|
AddDropMessagesByCondition(condition string) error
|
||||||
|
RemoveDropMessagesByCondition(condition string)
|
||||||
|
AddRenameMetricByCondition(condition string, name string) error
|
||||||
|
RemoveRenameMetricByCondition(condition string)
|
||||||
|
AddRenameMetricByName(from, to string) error
|
||||||
|
RemoveRenameMetricByName(from string)
|
||||||
|
SetNormalizeUnits(settings bool)
|
||||||
|
AddChangeUnitPrefix(condition string, prefix string) error
|
||||||
|
RemoveChangeUnitPrefix(condition string)
|
||||||
|
AddAddTagsByCondition(condition, key, value string) error
|
||||||
|
RemoveAddTagsByCondition(condition string)
|
||||||
|
AddDeleteTagsByCondition(condition, key, value string) error
|
||||||
|
RemoveDeleteTagsByCondition(condition string)
|
||||||
|
AddAddMetaByCondition(condition, key, value string) error
|
||||||
|
RemoveAddMetaByCondition(condition string)
|
||||||
|
AddDeleteMetaByCondition(condition, key, value string) error
|
||||||
|
RemoveDeleteMetaByCondition(condition string)
|
||||||
|
AddMoveTagToMeta(condition, key, value string) error
|
||||||
|
RemoveMoveTagToMeta(condition string)
|
||||||
|
AddMoveTagToFields(condition, key, value string) error
|
||||||
|
RemoveMoveTagToFields(condition string)
|
||||||
|
AddMoveMetaToTags(condition, key, value string) error
|
||||||
|
RemoveMoveMetaToTags(condition string)
|
||||||
|
AddMoveMetaToFields(condition, key, value string) error
|
||||||
|
RemoveMoveMetaToFields(condition string)
|
||||||
|
AddMoveFieldToTags(condition, key, value string) error
|
||||||
|
RemoveMoveFieldToTags(condition string)
|
||||||
|
AddMoveFieldToMeta(condition, key, value string) error
|
||||||
|
RemoveMoveFieldToMeta(condition string)
|
||||||
|
// Read in a JSON configuration
|
||||||
|
FromConfigJSON(config json.RawMessage) error
|
||||||
|
// Processing functions for legacy CCMetric and current CCMessage
|
||||||
|
ProcessMetric(m lplegacy.CCMetric) (lp.CCMessage, error)
|
||||||
|
ProcessMessage(m lp.CCMessage) (lp.CCMessage, error)
|
||||||
|
//EvalToBool(condition string, parameters map[string]interface{}) (bool, error)
|
||||||
|
//EvalToFloat64(condition string, parameters map[string]interface{}) (float64, error)
|
||||||
|
//EvalToString(condition string, parameters map[string]interface{}) (string, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
STAGENAME_DROP_BY_NAME string = "drop_by_name"
|
||||||
|
STAGENAME_DROP_BY_TYPE string = "drop_by_type"
|
||||||
|
STAGENAME_DROP_IF string = "drop_if"
|
||||||
|
STAGENAME_ADD_TAG string = "add_tag"
|
||||||
|
STAGENAME_DELETE_TAG string = "delete_tag"
|
||||||
|
STAGENAME_MOVE_TAG_META string = "move_tag_to_meta"
|
||||||
|
STAGENAME_MOVE_TAG_FIELD string = "move_tag_to_fields"
|
||||||
|
STAGENAME_ADD_META string = "add_meta"
|
||||||
|
STAGENAME_DELETE_META string = "delete_meta"
|
||||||
|
STAGENAME_MOVE_META_TAG string = "move_meta_to_tags"
|
||||||
|
STAGENAME_MOVE_META_FIELD string = "move_meta_to_fields"
|
||||||
|
STAGENAME_ADD_FIELD string = "add_field"
|
||||||
|
STAGENAME_DELETE_FIELD string = "delete_field"
|
||||||
|
STAGENAME_MOVE_FIELD_TAG string = "move_field_to_tags"
|
||||||
|
STAGENAME_MOVE_FIELD_META string = "move_field_to_meta"
|
||||||
|
STAGENAME_RENAME_BY_NAME string = "rename"
|
||||||
|
STAGENAME_RENAME_IF string = "rename_if"
|
||||||
|
STAGENAME_CHANGE_UNIT_PREFIX string = "change_unit_prefix"
|
||||||
|
STAGENAME_NORMALIZE_UNIT string = "normalize_unit"
|
||||||
|
)
|
||||||
|
|
||||||
|
var StageNames = []string{
|
||||||
|
STAGENAME_DROP_BY_NAME,
|
||||||
|
STAGENAME_DROP_BY_TYPE,
|
||||||
|
STAGENAME_DROP_IF,
|
||||||
|
STAGENAME_ADD_TAG,
|
||||||
|
STAGENAME_DELETE_TAG,
|
||||||
|
STAGENAME_MOVE_TAG_META,
|
||||||
|
STAGENAME_MOVE_TAG_FIELD,
|
||||||
|
STAGENAME_ADD_META,
|
||||||
|
STAGENAME_DELETE_META,
|
||||||
|
STAGENAME_MOVE_META_TAG,
|
||||||
|
STAGENAME_MOVE_META_FIELD,
|
||||||
|
STAGENAME_ADD_FIELD,
|
||||||
|
STAGENAME_DELETE_FIELD,
|
||||||
|
STAGENAME_MOVE_FIELD_TAG,
|
||||||
|
STAGENAME_MOVE_FIELD_META,
|
||||||
|
STAGENAME_RENAME_BY_NAME,
|
||||||
|
STAGENAME_RENAME_IF,
|
||||||
|
STAGENAME_CHANGE_UNIT_PREFIX,
|
||||||
|
STAGENAME_NORMALIZE_UNIT,
|
||||||
|
}
|
||||||
|
|
||||||
|
var paramMapPool = sync.Pool{
|
||||||
|
New: func() any {
|
||||||
|
return make(map[string]interface{})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func sanitizeExprString(key string) string {
|
||||||
|
return strings.ReplaceAll(key, "type-id", "typeid")
|
||||||
|
}
|
||||||
|
|
||||||
|
func getParamMap(point lp.CCMetric) map[string]interface{} {
|
||||||
|
params := paramMapPool.Get().(map[string]interface{})
|
||||||
|
params["message"] = point
|
||||||
|
params["msg"] = point
|
||||||
|
params["name"] = point.Name()
|
||||||
|
params["timestamp"] = point.Time().Unix()
|
||||||
|
params["time"] = params["timestamp"]
|
||||||
|
|
||||||
|
fields := paramMapPool.Get().(map[string]interface{})
|
||||||
|
for key, value := range point.Fields() {
|
||||||
|
fields[key] = value
|
||||||
|
switch key {
|
||||||
|
case "value":
|
||||||
|
params["messagetype"] = "metric"
|
||||||
|
params["value"] = value
|
||||||
|
params["metric"] = value
|
||||||
|
case "event":
|
||||||
|
params["messagetype"] = "event"
|
||||||
|
params["event"] = value
|
||||||
|
case "control":
|
||||||
|
params["messagetype"] = "control"
|
||||||
|
params["control"] = value
|
||||||
|
case "log":
|
||||||
|
params["messagetype"] = "log"
|
||||||
|
params["log"] = value
|
||||||
|
default:
|
||||||
|
params["messagetype"] = "unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
params["msgtype"] = params["messagetype"]
|
||||||
|
params["fields"] = fields
|
||||||
|
params["field"] = fields
|
||||||
|
tags := paramMapPool.Get().(map[string]interface{})
|
||||||
|
for key, value := range point.Tags() {
|
||||||
|
tags[sanitizeExprString(key)] = value
|
||||||
|
}
|
||||||
|
params["tags"] = tags
|
||||||
|
params["tag"] = tags
|
||||||
|
meta := paramMapPool.Get().(map[string]interface{})
|
||||||
|
for key, value := range point.Meta() {
|
||||||
|
meta[sanitizeExprString(key)] = value
|
||||||
|
}
|
||||||
|
params["meta"] = meta
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
|
||||||
|
var baseenv = map[string]interface{}{
|
||||||
|
"name": "",
|
||||||
|
"messagetype": "unknown",
|
||||||
|
"msgtype": "unknown",
|
||||||
|
"tag": map[string]interface{}{
|
||||||
|
"type": "unknown",
|
||||||
|
"typeid": "0",
|
||||||
|
"stype": "unknown",
|
||||||
|
"stypeid": "0",
|
||||||
|
"hostname": "localhost",
|
||||||
|
"cluster": "nocluster",
|
||||||
|
},
|
||||||
|
"tags": map[string]interface{}{
|
||||||
|
"type": "unknown",
|
||||||
|
"typeid": "0",
|
||||||
|
"stype": "unknown",
|
||||||
|
"stypeid": "0",
|
||||||
|
"hostname": "localhost",
|
||||||
|
"cluster": "nocluster",
|
||||||
|
},
|
||||||
|
"meta": map[string]interface{}{
|
||||||
|
"unit": "invalid",
|
||||||
|
"source": "unknown",
|
||||||
|
},
|
||||||
|
"fields": map[string]interface{}{
|
||||||
|
"value": 0,
|
||||||
|
"event": "",
|
||||||
|
"control": "",
|
||||||
|
"log": "",
|
||||||
|
},
|
||||||
|
"field": map[string]interface{}{
|
||||||
|
"value": 0,
|
||||||
|
"event": "",
|
||||||
|
"control": "",
|
||||||
|
"log": "",
|
||||||
|
},
|
||||||
|
"timestamp": 1234567890,
|
||||||
|
"msg": lp.EmptyMessage(),
|
||||||
|
"message": lp.EmptyMessage(),
|
||||||
|
}
|
||||||
|
|
||||||
|
func addBaseEnvWalker(values map[string]interface{}) map[string]interface{} {
|
||||||
|
out := make(map[string]interface{})
|
||||||
|
for k, v := range values {
|
||||||
|
switch value := v.(type) {
|
||||||
|
case int, int32, int64, uint, uint32, uint64, string, float32, float64:
|
||||||
|
out[k] = value
|
||||||
|
case map[string]interface{}:
|
||||||
|
if _, ok := baseenv[k]; !ok {
|
||||||
|
out[k] = addBaseEnvWalker(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddBaseEnv(env map[string]interface{}) error {
|
||||||
|
for k, v := range env {
|
||||||
|
switch value := v.(type) {
|
||||||
|
case int, int32, int64, uint, uint32, uint64, string, float32, float64:
|
||||||
|
baseenv[k] = value
|
||||||
|
case map[string]interface{}:
|
||||||
|
if _, ok := baseenv[k]; !ok {
|
||||||
|
baseenv[k] = addBaseEnvWalker(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) init() error {
|
||||||
|
mp.stages = make([]string, 0)
|
||||||
|
mp.mapping = make(map[string]*vm.Program)
|
||||||
|
mp.dropMessages = make(map[string]struct{})
|
||||||
|
mp.dropTypes = make(map[string]struct{})
|
||||||
|
mp.dropMessagesIf = make(map[*vm.Program]struct{})
|
||||||
|
mp.renameMessages = make(map[string]string)
|
||||||
|
mp.renameMessagesIf = make(map[*vm.Program]string)
|
||||||
|
mp.changeUnitPrefix = make(map[*vm.Program]string)
|
||||||
|
mp.addTagsIf = make(map[*vm.Program]messageProcessorTagConfig)
|
||||||
|
mp.addMetaIf = make(map[*vm.Program]messageProcessorTagConfig)
|
||||||
|
mp.addFieldIf = make(map[*vm.Program]messageProcessorTagConfig)
|
||||||
|
mp.deleteTagsIf = make(map[*vm.Program]messageProcessorTagConfig)
|
||||||
|
mp.deleteMetaIf = make(map[*vm.Program]messageProcessorTagConfig)
|
||||||
|
mp.deleteFieldIf = make(map[*vm.Program]messageProcessorTagConfig)
|
||||||
|
mp.moveFieldToMeta = make(map[*vm.Program]messageProcessorTagConfig)
|
||||||
|
mp.moveFieldToTag = make(map[*vm.Program]messageProcessorTagConfig)
|
||||||
|
mp.moveMetaToField = make(map[*vm.Program]messageProcessorTagConfig)
|
||||||
|
mp.moveMetaToTag = make(map[*vm.Program]messageProcessorTagConfig)
|
||||||
|
mp.moveTagToField = make(map[*vm.Program]messageProcessorTagConfig)
|
||||||
|
mp.moveTagToMeta = make(map[*vm.Program]messageProcessorTagConfig)
|
||||||
|
mp.normalizeUnits = false
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddDropMessagesByName(name string) error {
|
||||||
|
mp.mutex.Lock()
|
||||||
|
if _, ok := mp.dropMessages[name]; !ok {
|
||||||
|
mp.dropMessages[name] = struct{}{}
|
||||||
|
}
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveDropMessagesByName(name string) {
|
||||||
|
mp.mutex.Lock()
|
||||||
|
delete(mp.dropMessages, name)
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddDropMessagesByType(typestring string) error {
|
||||||
|
valid := []string{"metric", "event", "control", "log"}
|
||||||
|
isValid := false
|
||||||
|
for _, t := range valid {
|
||||||
|
if t == typestring {
|
||||||
|
isValid = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isValid {
|
||||||
|
mp.mutex.Lock()
|
||||||
|
if _, ok := mp.dropTypes[typestring]; !ok {
|
||||||
|
cclog.ComponentDebug("MessageProcessor", "Adding type", typestring, "for dropping")
|
||||||
|
mp.dropTypes[typestring] = struct{}{}
|
||||||
|
}
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("invalid message type %s", typestring)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveDropMessagesByType(typestring string) {
|
||||||
|
mp.mutex.Lock()
|
||||||
|
delete(mp.dropTypes, typestring)
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) addTagConfig(condition, key, value string, config *map[*vm.Program]messageProcessorTagConfig) error {
|
||||||
|
var err error
|
||||||
|
evaluable, err := expr.Compile(sanitizeExprString(condition), expr.Env(baseenv), expr.AsBool())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create condition evaluable of '%s': %v", condition, err.Error())
|
||||||
|
}
|
||||||
|
mp.mutex.Lock()
|
||||||
|
if _, ok := (*config)[evaluable]; !ok {
|
||||||
|
mp.mapping[condition] = evaluable
|
||||||
|
(*config)[evaluable] = messageProcessorTagConfig{
|
||||||
|
Condition: condition,
|
||||||
|
Key: key,
|
||||||
|
Value: value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) removeTagConfig(condition string, config *map[*vm.Program]messageProcessorTagConfig) {
|
||||||
|
mp.mutex.Lock()
|
||||||
|
if e, ok := mp.mapping[condition]; ok {
|
||||||
|
delete(mp.mapping, condition)
|
||||||
|
delete(*config, e)
|
||||||
|
}
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddAddTagsByCondition(condition, key, value string) error {
|
||||||
|
return mp.addTagConfig(condition, key, value, &mp.addTagsIf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveAddTagsByCondition(condition string) {
|
||||||
|
mp.removeTagConfig(condition, &mp.addTagsIf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddDeleteTagsByCondition(condition, key, value string) error {
|
||||||
|
return mp.addTagConfig(condition, key, value, &mp.deleteTagsIf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveDeleteTagsByCondition(condition string) {
|
||||||
|
mp.removeTagConfig(condition, &mp.deleteTagsIf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddAddMetaByCondition(condition, key, value string) error {
|
||||||
|
return mp.addTagConfig(condition, key, value, &mp.addMetaIf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveAddMetaByCondition(condition string) {
|
||||||
|
mp.removeTagConfig(condition, &mp.addMetaIf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddDeleteMetaByCondition(condition, key, value string) error {
|
||||||
|
return mp.addTagConfig(condition, key, value, &mp.deleteMetaIf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveDeleteMetaByCondition(condition string) {
|
||||||
|
mp.removeTagConfig(condition, &mp.deleteMetaIf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddAddFieldByCondition(condition, key, value string) error {
|
||||||
|
return mp.addTagConfig(condition, key, value, &mp.addFieldIf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveAddFieldByCondition(condition string) {
|
||||||
|
mp.removeTagConfig(condition, &mp.addFieldIf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddDeleteFieldByCondition(condition, key, value string) error {
|
||||||
|
return mp.addTagConfig(condition, key, value, &mp.deleteFieldIf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveDeleteFieldByCondition(condition string) {
|
||||||
|
mp.removeTagConfig(condition, &mp.deleteFieldIf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddDropMessagesByCondition(condition string) error {
|
||||||
|
|
||||||
|
var err error
|
||||||
|
evaluable, err := expr.Compile(sanitizeExprString(condition), expr.Env(baseenv), expr.AsBool())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create condition evaluable of '%s': %v", condition, err.Error())
|
||||||
|
}
|
||||||
|
mp.mutex.Lock()
|
||||||
|
if _, ok := mp.dropMessagesIf[evaluable]; !ok {
|
||||||
|
mp.mapping[condition] = evaluable
|
||||||
|
mp.dropMessagesIf[evaluable] = struct{}{}
|
||||||
|
}
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveDropMessagesByCondition(condition string) {
|
||||||
|
mp.mutex.Lock()
|
||||||
|
if e, ok := mp.mapping[condition]; ok {
|
||||||
|
delete(mp.mapping, condition)
|
||||||
|
delete(mp.dropMessagesIf, e)
|
||||||
|
}
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddRenameMetricByCondition(condition string, name string) error {
|
||||||
|
|
||||||
|
var err error
|
||||||
|
evaluable, err := expr.Compile(sanitizeExprString(condition), expr.Env(baseenv), expr.AsBool())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create condition evaluable of '%s': %v", condition, err.Error())
|
||||||
|
}
|
||||||
|
mp.mutex.Lock()
|
||||||
|
if _, ok := mp.renameMessagesIf[evaluable]; !ok {
|
||||||
|
mp.mapping[condition] = evaluable
|
||||||
|
mp.renameMessagesIf[evaluable] = name
|
||||||
|
} else {
|
||||||
|
mp.renameMessagesIf[evaluable] = name
|
||||||
|
}
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveRenameMetricByCondition(condition string) {
|
||||||
|
mp.mutex.Lock()
|
||||||
|
if e, ok := mp.mapping[condition]; ok {
|
||||||
|
delete(mp.mapping, condition)
|
||||||
|
delete(mp.renameMessagesIf, e)
|
||||||
|
}
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) SetNormalizeUnits(setting bool) {
|
||||||
|
mp.normalizeUnits = setting
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddChangeUnitPrefix(condition string, prefix string) error {
|
||||||
|
|
||||||
|
var err error
|
||||||
|
evaluable, err := expr.Compile(sanitizeExprString(condition), expr.Env(baseenv), expr.AsBool())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create condition evaluable of '%s': %v", condition, err.Error())
|
||||||
|
}
|
||||||
|
mp.mutex.Lock()
|
||||||
|
if _, ok := mp.changeUnitPrefix[evaluable]; !ok {
|
||||||
|
mp.mapping[condition] = evaluable
|
||||||
|
mp.changeUnitPrefix[evaluable] = prefix
|
||||||
|
} else {
|
||||||
|
mp.changeUnitPrefix[evaluable] = prefix
|
||||||
|
}
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveChangeUnitPrefix(condition string) {
|
||||||
|
mp.mutex.Lock()
|
||||||
|
if e, ok := mp.mapping[condition]; ok {
|
||||||
|
delete(mp.mapping, condition)
|
||||||
|
delete(mp.changeUnitPrefix, e)
|
||||||
|
}
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddRenameMetricByName(from, to string) error {
|
||||||
|
mp.mutex.Lock()
|
||||||
|
if _, ok := mp.renameMessages[from]; !ok {
|
||||||
|
mp.renameMessages[from] = to
|
||||||
|
}
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveRenameMetricByName(from string) {
|
||||||
|
mp.mutex.Lock()
|
||||||
|
delete(mp.renameMessages, from)
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddMoveTagToMeta(condition, key, value string) error {
|
||||||
|
return mp.addTagConfig(condition, key, value, &mp.moveTagToMeta)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveMoveTagToMeta(condition string) {
|
||||||
|
mp.removeTagConfig(condition, &mp.moveTagToMeta)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddMoveTagToFields(condition, key, value string) error {
|
||||||
|
return mp.addTagConfig(condition, key, value, &mp.moveTagToField)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveMoveTagToFields(condition string) {
|
||||||
|
mp.removeTagConfig(condition, &mp.moveTagToField)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddMoveMetaToTags(condition, key, value string) error {
|
||||||
|
return mp.addTagConfig(condition, key, value, &mp.moveMetaToTag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveMoveMetaToTags(condition string) {
|
||||||
|
mp.removeTagConfig(condition, &mp.moveMetaToTag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddMoveMetaToFields(condition, key, value string) error {
|
||||||
|
return mp.addTagConfig(condition, key, value, &mp.moveMetaToField)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveMoveMetaToFields(condition string) {
|
||||||
|
mp.removeTagConfig(condition, &mp.moveMetaToField)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddMoveFieldToTags(condition, key, value string) error {
|
||||||
|
return mp.addTagConfig(condition, key, value, &mp.moveFieldToTag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveMoveFieldToTags(condition string) {
|
||||||
|
mp.removeTagConfig(condition, &mp.moveFieldToTag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) AddMoveFieldToMeta(condition, key, value string) error {
|
||||||
|
return mp.addTagConfig(condition, key, value, &mp.moveFieldToMeta)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) RemoveMoveFieldToMeta(condition string) {
|
||||||
|
mp.removeTagConfig(condition, &mp.moveFieldToMeta)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) SetStages(stages []string) error {
|
||||||
|
newstages := make([]string, 0)
|
||||||
|
if len(stages) == 0 {
|
||||||
|
mp.mutex.Lock()
|
||||||
|
mp.stages = newstages
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for i, s := range stages {
|
||||||
|
valid := false
|
||||||
|
for _, v := range StageNames {
|
||||||
|
if s == v {
|
||||||
|
valid = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if valid {
|
||||||
|
newstages = append(newstages, s)
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("invalid stage %s at index %d", s, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mp.mutex.Lock()
|
||||||
|
mp.stages = newstages
|
||||||
|
mp.mutex.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) DefaultStages() []string {
|
||||||
|
return StageNames
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) FromConfigJSON(config json.RawMessage) error {
|
||||||
|
var c messageProcessorConfig
|
||||||
|
|
||||||
|
err := json.Unmarshal(config, &c)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(c.StageOrder) > 0 {
|
||||||
|
err = mp.SetStages(c.StageOrder)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = mp.SetStages(mp.DefaultStages())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, m := range c.DropMessages {
|
||||||
|
err = mp.AddDropMessagesByName(m)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, m := range c.DropByType {
|
||||||
|
err = mp.AddDropMessagesByType(m)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, m := range c.DropMessagesIf {
|
||||||
|
err = mp.AddDropMessagesByCondition(m)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for k, v := range c.RenameMessagesIf {
|
||||||
|
err = mp.AddRenameMetricByCondition(k, v)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for k, v := range c.RenameMessages {
|
||||||
|
err = mp.AddRenameMetricByName(k, v)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for k, v := range c.ChangeUnitPrefix {
|
||||||
|
err = mp.AddChangeUnitPrefix(k, v)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, c := range c.AddTagsIf {
|
||||||
|
err = mp.AddAddTagsByCondition(c.Condition, c.Key, c.Value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, c := range c.AddMetaIf {
|
||||||
|
err = mp.AddAddMetaByCondition(c.Condition, c.Key, c.Value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, c := range c.AddFieldIf {
|
||||||
|
err = mp.AddAddFieldByCondition(c.Condition, c.Key, c.Value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, c := range c.DelTagsIf {
|
||||||
|
err = mp.AddDeleteTagsByCondition(c.Condition, c.Key, c.Value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, c := range c.DelMetaIf {
|
||||||
|
err = mp.AddDeleteMetaByCondition(c.Condition, c.Key, c.Value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, c := range c.DelFieldIf {
|
||||||
|
err = mp.AddDeleteFieldByCondition(c.Condition, c.Key, c.Value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, c := range c.MoveTagToMeta {
|
||||||
|
err = mp.AddMoveTagToMeta(c.Condition, c.Key, c.Value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, c := range c.MoveTagToField {
|
||||||
|
err = mp.AddMoveTagToFields(c.Condition, c.Key, c.Value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, c := range c.MoveMetaToTag {
|
||||||
|
err = mp.AddMoveMetaToTags(c.Condition, c.Key, c.Value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, c := range c.MoveMetaToField {
|
||||||
|
err = mp.AddMoveMetaToFields(c.Condition, c.Key, c.Value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, c := range c.MoveFieldToTag {
|
||||||
|
err = mp.AddMoveFieldToTags(c.Condition, c.Key, c.Value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, c := range c.MoveFieldToMeta {
|
||||||
|
err = mp.AddMoveFieldToMeta(c.Condition, c.Key, c.Value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, m := range c.DropByType {
|
||||||
|
err = mp.AddDropMessagesByType(m)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(c.AddBaseEnv) > 0 {
|
||||||
|
err = mp.AddBaseEnv(c.AddBaseEnv)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to process config JSON: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mp.SetNormalizeUnits(c.NormalizeUnits)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) ProcessMetric(metric lplegacy.CCMetric) (lp.CCMessage, error) {
|
||||||
|
m, err := lp.NewMessage(
|
||||||
|
metric.Name(),
|
||||||
|
metric.Tags(),
|
||||||
|
metric.Meta(),
|
||||||
|
metric.Fields(),
|
||||||
|
metric.Time(),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return m, fmt.Errorf("failed to parse metric to message: %v", err.Error())
|
||||||
|
}
|
||||||
|
return mp.ProcessMessage(m)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mp *messageProcessor) ProcessMessage(m lp.CCMessage) (lp.CCMessage, error) {
|
||||||
|
var err error = nil
|
||||||
|
var out lp.CCMessage = lp.FromMessage(m)
|
||||||
|
|
||||||
|
name := out.Name()
|
||||||
|
|
||||||
|
if len(mp.stages) == 0 {
|
||||||
|
mp.SetStages(mp.DefaultStages())
|
||||||
|
}
|
||||||
|
|
||||||
|
mp.mutex.RLock()
|
||||||
|
defer mp.mutex.RUnlock()
|
||||||
|
|
||||||
|
params := getParamMap(out)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
params["field"] = nil
|
||||||
|
params["tag"] = nil
|
||||||
|
paramMapPool.Put(params["fields"])
|
||||||
|
paramMapPool.Put(params["tags"])
|
||||||
|
paramMapPool.Put(params["meta"])
|
||||||
|
paramMapPool.Put(params)
|
||||||
|
}()
|
||||||
|
|
||||||
|
for _, s := range mp.stages {
|
||||||
|
switch s {
|
||||||
|
case STAGENAME_DROP_BY_NAME:
|
||||||
|
if len(mp.dropMessages) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Dropping by message name ", name)
|
||||||
|
if _, ok := mp.dropMessages[name]; ok {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Drop")
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_DROP_BY_TYPE:
|
||||||
|
if len(mp.dropTypes) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Dropping by message type")
|
||||||
|
if _, ok := mp.dropTypes[params["messagetype"].(string)]; ok {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Drop")
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_DROP_IF:
|
||||||
|
if len(mp.dropMessagesIf) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Dropping by condition")
|
||||||
|
drop, err := dropMessagesIf(¶ms, &mp.dropMessagesIf)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
if drop {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Drop")
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_RENAME_BY_NAME:
|
||||||
|
if len(mp.renameMessages) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Renaming by name match")
|
||||||
|
if newname, ok := mp.renameMessages[name]; ok {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Rename to", newname)
|
||||||
|
out.SetName(newname)
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Add old name as 'oldname' to meta", name)
|
||||||
|
out.AddMeta("oldname", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_RENAME_IF:
|
||||||
|
if len(mp.renameMessagesIf) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Renaming by condition")
|
||||||
|
_, err := renameMessagesIf(out, ¶ms, &mp.renameMessagesIf)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_ADD_TAG:
|
||||||
|
if len(mp.addTagsIf) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Adding tags")
|
||||||
|
_, err = addTagIf(out, ¶ms, &mp.addTagsIf)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_DELETE_TAG:
|
||||||
|
if len(mp.deleteTagsIf) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Delete tags")
|
||||||
|
_, err = deleteTagIf(out, ¶ms, &mp.deleteTagsIf)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_ADD_META:
|
||||||
|
if len(mp.addMetaIf) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Adding meta information")
|
||||||
|
_, err = addMetaIf(out, ¶ms, &mp.addMetaIf)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_DELETE_META:
|
||||||
|
if len(mp.deleteMetaIf) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Delete meta information")
|
||||||
|
_, err = deleteMetaIf(out, ¶ms, &mp.deleteMetaIf)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_ADD_FIELD:
|
||||||
|
if len(mp.addFieldIf) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Adding fields")
|
||||||
|
_, err = addFieldIf(out, ¶ms, &mp.addFieldIf)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_DELETE_FIELD:
|
||||||
|
if len(mp.deleteFieldIf) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Delete fields")
|
||||||
|
_, err = deleteFieldIf(out, ¶ms, &mp.deleteFieldIf)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_MOVE_TAG_META:
|
||||||
|
if len(mp.moveTagToMeta) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Move tag to meta")
|
||||||
|
_, err := moveTagToMeta(out, ¶ms, &mp.moveTagToMeta)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_MOVE_TAG_FIELD:
|
||||||
|
if len(mp.moveTagToField) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Move tag to fields")
|
||||||
|
_, err := moveTagToField(out, ¶ms, &mp.moveTagToField)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_MOVE_META_TAG:
|
||||||
|
if len(mp.moveMetaToTag) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Move meta to tags")
|
||||||
|
_, err := moveMetaToTag(out, ¶ms, &mp.moveMetaToTag)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_MOVE_META_FIELD:
|
||||||
|
if len(mp.moveMetaToField) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Move meta to fields")
|
||||||
|
_, err := moveMetaToField(out, ¶ms, &mp.moveMetaToField)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_MOVE_FIELD_META:
|
||||||
|
if len(mp.moveFieldToMeta) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Move field to meta")
|
||||||
|
_, err := moveFieldToMeta(out, ¶ms, &mp.moveFieldToMeta)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_MOVE_FIELD_TAG:
|
||||||
|
if len(mp.moveFieldToTag) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Move field to tags")
|
||||||
|
_, err := moveFieldToTag(out, ¶ms, &mp.moveFieldToTag)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case STAGENAME_NORMALIZE_UNIT:
|
||||||
|
if mp.normalizeUnits {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Normalize units")
|
||||||
|
if lp.IsMetric(out) {
|
||||||
|
_, err := normalizeUnits(out)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cclog.ComponentDebug("MessageProcessor", "skipped, no metric")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case STAGENAME_CHANGE_UNIT_PREFIX:
|
||||||
|
if len(mp.changeUnitPrefix) > 0 {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Change unit prefix")
|
||||||
|
if lp.IsMetric(out) {
|
||||||
|
_, err := changeUnitPrefix(out, ¶ms, &mp.changeUnitPrefix)
|
||||||
|
if err != nil {
|
||||||
|
return out, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cclog.ComponentDebug("MessageProcessor", "skipped, no metric")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a new instace of a message processor.
|
||||||
|
func NewMessageProcessor() (MessageProcessor, error) {
|
||||||
|
mp := new(messageProcessor)
|
||||||
|
err := mp.init()
|
||||||
|
if err != nil {
|
||||||
|
err := fmt.Errorf("failed to create MessageProcessor: %v", err.Error())
|
||||||
|
cclog.ComponentError("MessageProcessor", err.Error())
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return mp, nil
|
||||||
|
}
|
||||||
262
pkg/messageProcessor/messageProcessorFuncs.go
Normal file
262
pkg/messageProcessor/messageProcessorFuncs.go
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
package messageprocessor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
lp2 "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
units "github.com/ClusterCockpit/cc-units"
|
||||||
|
"github.com/expr-lang/expr"
|
||||||
|
"github.com/expr-lang/expr/vm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MessageLocation int
|
||||||
|
|
||||||
|
const (
|
||||||
|
MESSAGE_LOCATION_TAGS MessageLocation = iota
|
||||||
|
MESSAGE_LOCATION_META
|
||||||
|
MESSAGE_LOCATION_FIELDS
|
||||||
|
)
|
||||||
|
|
||||||
|
// Abstract function to move entries from one location to another
|
||||||
|
func moveInMessage(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig, from, to MessageLocation) (bool, error) {
|
||||||
|
for d, data := range *checks {
|
||||||
|
value, err := expr.Run(d, *params)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Move from", from, "to", to)
|
||||||
|
if value.(bool) {
|
||||||
|
var v string
|
||||||
|
var ok bool = false
|
||||||
|
switch from {
|
||||||
|
case MESSAGE_LOCATION_TAGS:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Getting tag key", data.Key)
|
||||||
|
v, ok = message.GetTag(data.Key)
|
||||||
|
case MESSAGE_LOCATION_META:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Getting meta key", data.Key)
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", message.Meta())
|
||||||
|
v, ok = message.GetMeta(data.Key)
|
||||||
|
case MESSAGE_LOCATION_FIELDS:
|
||||||
|
var x interface{}
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Getting field key", data.Key)
|
||||||
|
x, ok = message.GetField(data.Key)
|
||||||
|
v = fmt.Sprintf("%v", x)
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
switch from {
|
||||||
|
case MESSAGE_LOCATION_TAGS:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Removing tag key", data.Key)
|
||||||
|
message.RemoveTag(data.Key)
|
||||||
|
case MESSAGE_LOCATION_META:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Removing meta key", data.Key)
|
||||||
|
message.RemoveMeta(data.Key)
|
||||||
|
case MESSAGE_LOCATION_FIELDS:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Removing field key", data.Key)
|
||||||
|
message.RemoveField(data.Key)
|
||||||
|
}
|
||||||
|
switch to {
|
||||||
|
case MESSAGE_LOCATION_TAGS:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Adding tag", data.Value, "->", v)
|
||||||
|
message.AddTag(data.Value, v)
|
||||||
|
case MESSAGE_LOCATION_META:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Adding meta", data.Value, "->", v)
|
||||||
|
message.AddMeta(data.Value, v)
|
||||||
|
case MESSAGE_LOCATION_FIELDS:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Adding field", data.Value, "->", v)
|
||||||
|
message.AddField(data.Value, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteIf(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig, location MessageLocation) (bool, error) {
|
||||||
|
for d, data := range *checks {
|
||||||
|
value, err := expr.Run(d, *params)
|
||||||
|
if err != nil {
|
||||||
|
return true, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
if value.(bool) {
|
||||||
|
switch location {
|
||||||
|
case MESSAGE_LOCATION_FIELDS:
|
||||||
|
switch data.Key {
|
||||||
|
case "value", "event", "log", "control":
|
||||||
|
return false, errors.New("cannot delete protected fields")
|
||||||
|
default:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Removing field for", data.Key)
|
||||||
|
message.RemoveField(data.Key)
|
||||||
|
}
|
||||||
|
case MESSAGE_LOCATION_TAGS:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Removing tag for", data.Key)
|
||||||
|
message.RemoveTag(data.Key)
|
||||||
|
case MESSAGE_LOCATION_META:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Removing meta for", data.Key)
|
||||||
|
message.RemoveMeta(data.Key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func addIf(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig, location MessageLocation) (bool, error) {
|
||||||
|
for d, data := range *checks {
|
||||||
|
value, err := expr.Run(d, *params)
|
||||||
|
if err != nil {
|
||||||
|
return true, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
if value.(bool) {
|
||||||
|
switch location {
|
||||||
|
case MESSAGE_LOCATION_FIELDS:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Adding field", data.Value, "->", data.Value)
|
||||||
|
message.AddField(data.Key, data.Value)
|
||||||
|
case MESSAGE_LOCATION_TAGS:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Adding tag", data.Value, "->", data.Value)
|
||||||
|
message.AddTag(data.Key, data.Value)
|
||||||
|
case MESSAGE_LOCATION_META:
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Adding meta", data.Value, "->", data.Value)
|
||||||
|
message.AddMeta(data.Key, data.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteTagIf(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig) (bool, error) {
|
||||||
|
return deleteIf(message, params, checks, MESSAGE_LOCATION_TAGS)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addTagIf(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig) (bool, error) {
|
||||||
|
return addIf(message, params, checks, MESSAGE_LOCATION_TAGS)
|
||||||
|
}
|
||||||
|
|
||||||
|
func moveTagToMeta(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig) (bool, error) {
|
||||||
|
return moveInMessage(message, params, checks, MESSAGE_LOCATION_TAGS, MESSAGE_LOCATION_META)
|
||||||
|
}
|
||||||
|
|
||||||
|
func moveTagToField(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig) (bool, error) {
|
||||||
|
return moveInMessage(message, params, checks, MESSAGE_LOCATION_TAGS, MESSAGE_LOCATION_FIELDS)
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteMetaIf(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig) (bool, error) {
|
||||||
|
return deleteIf(message, params, checks, MESSAGE_LOCATION_META)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addMetaIf(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig) (bool, error) {
|
||||||
|
return addIf(message, params, checks, MESSAGE_LOCATION_META)
|
||||||
|
}
|
||||||
|
|
||||||
|
func moveMetaToTag(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig) (bool, error) {
|
||||||
|
return moveInMessage(message, params, checks, MESSAGE_LOCATION_META, MESSAGE_LOCATION_TAGS)
|
||||||
|
}
|
||||||
|
|
||||||
|
func moveMetaToField(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig) (bool, error) {
|
||||||
|
return moveInMessage(message, params, checks, MESSAGE_LOCATION_META, MESSAGE_LOCATION_FIELDS)
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteFieldIf(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig) (bool, error) {
|
||||||
|
return deleteIf(message, params, checks, MESSAGE_LOCATION_FIELDS)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addFieldIf(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig) (bool, error) {
|
||||||
|
return addIf(message, params, checks, MESSAGE_LOCATION_FIELDS)
|
||||||
|
}
|
||||||
|
|
||||||
|
func moveFieldToTag(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig) (bool, error) {
|
||||||
|
return moveInMessage(message, params, checks, MESSAGE_LOCATION_FIELDS, MESSAGE_LOCATION_TAGS)
|
||||||
|
}
|
||||||
|
|
||||||
|
func moveFieldToMeta(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]messageProcessorTagConfig) (bool, error) {
|
||||||
|
return moveInMessage(message, params, checks, MESSAGE_LOCATION_FIELDS, MESSAGE_LOCATION_META)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dropMessagesIf(params *map[string]interface{}, checks *map[*vm.Program]struct{}) (bool, error) {
|
||||||
|
for d := range *checks {
|
||||||
|
value, err := expr.Run(d, *params)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
if value.(bool) {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizeUnits(message lp2.CCMessage) (bool, error) {
|
||||||
|
if in_unit, ok := message.GetMeta("unit"); ok {
|
||||||
|
u := units.NewUnit(in_unit)
|
||||||
|
if u.Valid() {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Update unit with", u.Short())
|
||||||
|
message.AddMeta("unit", u.Short())
|
||||||
|
}
|
||||||
|
} else if in_unit, ok := message.GetTag("unit"); ok {
|
||||||
|
u := units.NewUnit(in_unit)
|
||||||
|
if u.Valid() {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Update unit with", u.Short())
|
||||||
|
message.AddTag("unit", u.Short())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func changeUnitPrefix(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]string) (bool, error) {
|
||||||
|
for r, n := range *checks {
|
||||||
|
value, err := expr.Run(r, *params)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
if value.(bool) {
|
||||||
|
newPrefix := units.NewPrefix(n)
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Condition matches, change to prefix", newPrefix.String())
|
||||||
|
if in_unit, ok := message.GetMeta("unit"); ok && newPrefix != units.InvalidPrefix {
|
||||||
|
u := units.NewUnit(in_unit)
|
||||||
|
if u.Valid() {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Input unit", u.Short())
|
||||||
|
conv, out_unit := units.GetUnitPrefixFactor(u, newPrefix)
|
||||||
|
if conv != nil && out_unit.Valid() {
|
||||||
|
if val, ok := message.GetField("value"); ok {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Update unit with", out_unit.Short())
|
||||||
|
message.AddField("value", conv(val))
|
||||||
|
message.AddMeta("unit", out_unit.Short())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if in_unit, ok := message.GetTag("unit"); ok && newPrefix != units.InvalidPrefix {
|
||||||
|
u := units.NewUnit(in_unit)
|
||||||
|
if u.Valid() {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Input unit", u.Short())
|
||||||
|
conv, out_unit := units.GetUnitPrefixFactor(u, newPrefix)
|
||||||
|
if conv != nil && out_unit.Valid() {
|
||||||
|
if val, ok := message.GetField("value"); ok {
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Update unit with", out_unit.Short())
|
||||||
|
message.AddField("value", conv(val))
|
||||||
|
message.AddTag("unit", out_unit.Short())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func renameMessagesIf(message lp2.CCMessage, params *map[string]interface{}, checks *map[*vm.Program]string) (bool, error) {
|
||||||
|
for d, n := range *checks {
|
||||||
|
value, err := expr.Run(d, *params)
|
||||||
|
if err != nil {
|
||||||
|
return true, fmt.Errorf("failed to evaluate: %v", err.Error())
|
||||||
|
}
|
||||||
|
if value.(bool) {
|
||||||
|
old := message.Name()
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Rename to", n)
|
||||||
|
message.SetName(n)
|
||||||
|
//cclog.ComponentDebug("MessageProcessor", "Add old name as 'oldname' to meta", old)
|
||||||
|
message.AddMeta("oldname", old)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
396
pkg/messageProcessor/messageProcessor_test.go
Normal file
396
pkg/messageProcessor/messageProcessor_test.go
Normal file
@@ -0,0 +1,396 @@
|
|||||||
|
package messageprocessor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
)
|
||||||
|
|
||||||
|
func generate_message_lists(num_lists, num_entries int) ([][]lp.CCMessage, error) {
|
||||||
|
mlist := make([][]lp.CCMessage, 0)
|
||||||
|
for j := 0; j < num_lists; j++ {
|
||||||
|
out := make([]lp.CCMessage, 0)
|
||||||
|
for i := 0; i < num_entries; i++ {
|
||||||
|
var x lp.CCMessage
|
||||||
|
var err error = nil
|
||||||
|
switch {
|
||||||
|
case i%4 == 0:
|
||||||
|
x, err = lp.NewEvent("myevent", map[string]string{"type": "socket", "type-id": "0"}, map[string]string{}, "nothing happend", time.Now())
|
||||||
|
case i%4 == 1:
|
||||||
|
x, err = lp.NewMetric("mymetric", map[string]string{"type": "socket", "type-id": "0"}, map[string]string{"unit": "kByte"}, 12.145, time.Now())
|
||||||
|
case i%4 == 2:
|
||||||
|
x, err = lp.NewLog("mylog", map[string]string{"type": "socket", "type-id": "0"}, map[string]string{}, "disk status: OK", time.Now())
|
||||||
|
case i%4 == 3:
|
||||||
|
x, err = lp.NewGetControl("mycontrol", map[string]string{"type": "socket", "type-id": "0"}, map[string]string{}, time.Now())
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
x.AddTag("hostname", "myhost")
|
||||||
|
out = append(out, x)
|
||||||
|
} else {
|
||||||
|
return nil, errors.New("failed to create message")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mlist = append(mlist, out)
|
||||||
|
}
|
||||||
|
return mlist, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewMessageProcessor(t *testing.T) {
|
||||||
|
_, err := NewMessageProcessor()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Configs struct {
|
||||||
|
name string
|
||||||
|
config json.RawMessage
|
||||||
|
drop bool
|
||||||
|
errors bool
|
||||||
|
pre func(msg lp.CCMessage) error
|
||||||
|
check func(msg lp.CCMessage) error
|
||||||
|
}
|
||||||
|
|
||||||
|
var test_configs = []Configs{
|
||||||
|
{
|
||||||
|
name: "single_dropif_nomatch",
|
||||||
|
config: json.RawMessage(`{"drop_messages_if": [ "name == 'testname' && tags.type == 'socket' && tags.typeid % 2 == 1"]}`),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "drop_by_name",
|
||||||
|
config: json.RawMessage(`{"drop_messages": [ "net_bytes_in"]}`),
|
||||||
|
drop: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "drop_by_type_match",
|
||||||
|
config: json.RawMessage(`{"drop_by_message_type": [ "metric"]}`),
|
||||||
|
drop: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "drop_by_type_nomatch",
|
||||||
|
config: json.RawMessage(`{"drop_by_message_type": [ "event"]}`),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "single_dropif_match",
|
||||||
|
config: json.RawMessage(`{"drop_messages_if": [ "name == 'net_bytes_in' && tags.type == 'node'"]}`),
|
||||||
|
drop: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "double_dropif_match_nomatch",
|
||||||
|
config: json.RawMessage(`{"drop_messages_if": [ "name == 'net_bytes_in' && tags.type == 'node'", "name == 'testname' && tags.type == 'socket' && tags.typeid % 2 == 1"]}`),
|
||||||
|
drop: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rename_simple",
|
||||||
|
config: json.RawMessage(`{"rename_messages": { "net_bytes_in" : "net_bytes_out", "rapl_power": "cpu_power"}}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if msg.Name() != "net_bytes_out" {
|
||||||
|
return errors.New("expected name net_bytes_out but still have net_bytes_in")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rename_match",
|
||||||
|
config: json.RawMessage(`{"rename_messages_if": { "name == 'net_bytes_in'" : "net_bytes_out", "name == 'rapl_power'": "cpu_power"}}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if msg.Name() != "net_bytes_out" {
|
||||||
|
return errors.New("expected name net_bytes_out but still have net_bytes_in")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rename_nomatch",
|
||||||
|
config: json.RawMessage(`{"rename_messages_if": { "name == 'net_bytes_out'" : "net_bytes_in", "name == 'rapl_power'": "cpu_power"}}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if msg.Name() != "net_bytes_in" {
|
||||||
|
return errors.New("expected name net_bytes_in but still have net_bytes_out")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "add_tag",
|
||||||
|
config: json.RawMessage(`{"add_tags_if": [{"if": "name == 'net_bytes_in'", "key" : "cluster", "value" : "mycluster"}]}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if !msg.HasTag("cluster") {
|
||||||
|
return errors.New("expected new tag 'cluster' but not present")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "del_tag",
|
||||||
|
config: json.RawMessage(`{"delete_tags_if": [{"if": "name == 'net_bytes_in'", "key" : "type"}]}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if msg.HasTag("type") {
|
||||||
|
return errors.New("expected to have no 'type' but still present")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "add_meta",
|
||||||
|
config: json.RawMessage(`{"add_meta_if": [{"if": "name == 'net_bytes_in'", "key" : "source", "value" : "example"}]}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if !msg.HasMeta("source") {
|
||||||
|
return errors.New("expected new tag 'source' but not present")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "del_meta",
|
||||||
|
config: json.RawMessage(`{"delete_meta_if": [{"if": "name == 'net_bytes_in'", "key" : "unit"}]}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if msg.HasMeta("unit") {
|
||||||
|
return errors.New("expected to have no 'unit' but still present")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "add_field",
|
||||||
|
config: json.RawMessage(`{"add_fields_if": [{"if": "name == 'net_bytes_in'", "key" : "myfield", "value" : "example"}]}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if !msg.HasField("myfield") {
|
||||||
|
return errors.New("expected new tag 'source' but not present")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "delete_fields_if_protected",
|
||||||
|
config: json.RawMessage(`{"delete_fields_if": [{"if": "name == 'net_bytes_in'", "key" : "value"}]}`),
|
||||||
|
errors: true,
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if !msg.HasField("value") {
|
||||||
|
return errors.New("expected to still have 'value' field because it is a protected field key")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "delete_fields_if_unprotected",
|
||||||
|
config: json.RawMessage(`{"delete_fields_if": [{"if": "name == 'net_bytes_in'", "key" : "testfield"}]}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if msg.HasField("testfield") {
|
||||||
|
return errors.New("expected to still have 'testfield' field but should be deleted")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
pre: func(msg lp.CCMessage) error {
|
||||||
|
msg.AddField("testfield", 4.123)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "single_change_prefix_match",
|
||||||
|
config: json.RawMessage(`{"change_unit_prefix": {"name == 'net_bytes_in' && tags.type == 'node'": "M"}}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if u, ok := msg.GetMeta("unit"); ok {
|
||||||
|
if u != "MB" {
|
||||||
|
return fmt.Errorf("expected unit MB but have %s", u)
|
||||||
|
}
|
||||||
|
} else if u, ok := msg.GetTag("unit"); ok {
|
||||||
|
if u != "MB" {
|
||||||
|
return fmt.Errorf("expected unit MB but have %s", u)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "normalize_units",
|
||||||
|
config: json.RawMessage(`{"normalize_units": true}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if u, ok := msg.GetMeta("unit"); ok {
|
||||||
|
if u != "B" {
|
||||||
|
return fmt.Errorf("expected unit B but have %s", u)
|
||||||
|
}
|
||||||
|
} else if u, ok := msg.GetTag("unit"); ok {
|
||||||
|
if u != "B" {
|
||||||
|
return fmt.Errorf("expected unit B but have %s", u)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "move_tag_to_meta",
|
||||||
|
config: json.RawMessage(`{"move_tag_to_meta_if": [{"if": "name == 'net_bytes_in'", "key" : "type-id", "value": "typeid"}]}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if msg.HasTag("type-id") || !msg.HasMeta("typeid") {
|
||||||
|
return errors.New("moving tag 'type-id' to meta 'typeid' failed")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
pre: func(msg lp.CCMessage) error {
|
||||||
|
msg.AddTag("type-id", "0")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "move_tag_to_field",
|
||||||
|
config: json.RawMessage(`{"move_tag_to_field_if": [{"if": "name == 'net_bytes_in'", "key" : "type-id", "value": "typeid"}]}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if msg.HasTag("type-id") || !msg.HasField("typeid") {
|
||||||
|
return errors.New("moving tag 'type-id' to field 'typeid' failed")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
pre: func(msg lp.CCMessage) error {
|
||||||
|
msg.AddTag("type-id", "0")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "move_meta_to_tag",
|
||||||
|
config: json.RawMessage(`{"move_meta_to_tag_if": [{"if": "name == 'net_bytes_in'", "key" : "unit", "value": "unit"}]}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if msg.HasMeta("unit") || !msg.HasTag("unit") {
|
||||||
|
return errors.New("moving meta 'unit' to tag 'unit' failed")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "move_meta_to_field",
|
||||||
|
config: json.RawMessage(`{"move_meta_to_field_if": [{"if": "name == 'net_bytes_in'", "key" : "unit", "value": "unit"}]}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if msg.HasMeta("unit") || !msg.HasField("unit") {
|
||||||
|
return errors.New("moving meta 'unit' to field 'unit' failed")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "move_field_to_tag",
|
||||||
|
config: json.RawMessage(`{"move_field_to_tag_if": [{"if": "name == 'net_bytes_in'", "key" : "myfield", "value": "field"}]}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if msg.HasField("myfield") || !msg.HasTag("field") {
|
||||||
|
return errors.New("moving meta 'myfield' to tag 'field' failed")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
pre: func(msg lp.CCMessage) error {
|
||||||
|
msg.AddField("myfield", 12)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "move_field_to_meta",
|
||||||
|
config: json.RawMessage(`{"move_field_to_meta_if": [{"if": "name == 'net_bytes_in'", "key" : "myfield", "value": "field"}]}`),
|
||||||
|
check: func(msg lp.CCMessage) error {
|
||||||
|
if msg.HasField("myfield") || !msg.HasMeta("field") {
|
||||||
|
return errors.New("moving meta 'myfield' to meta 'field' failed")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
pre: func(msg lp.CCMessage) error {
|
||||||
|
msg.AddField("myfield", 12)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConfigList(t *testing.T) {
|
||||||
|
for _, c := range test_configs {
|
||||||
|
t.Run(c.name, func(t *testing.T) {
|
||||||
|
m, err := lp.NewMetric("net_bytes_in", map[string]string{"type": "node", "type-id": "0"}, map[string]string{"unit": "Byte"}, float64(1024.0), time.Now())
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if c.pre != nil {
|
||||||
|
if err = c.pre(m); err != nil {
|
||||||
|
t.Errorf("error running pre-test function: %v", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mp, err := NewMessageProcessor()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = mp.FromConfigJSON(c.config)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//t.Log(m.ToLineProtocol(nil))
|
||||||
|
out, err := mp.ProcessMessage(m)
|
||||||
|
if err != nil && !c.errors {
|
||||||
|
cclog.SetDebug()
|
||||||
|
mp.ProcessMessage(m)
|
||||||
|
t.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if out == nil && !c.drop {
|
||||||
|
t.Error("fail, message should NOT be dropped but processor signalled dropping")
|
||||||
|
return
|
||||||
|
} else if out != nil && c.drop {
|
||||||
|
t.Error("fail, message should be dropped but processor signalled NO dropping")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// {
|
||||||
|
// if c.drop {
|
||||||
|
// t.Error("fail, message should be dropped but processor signalled NO dropping")
|
||||||
|
// } else {
|
||||||
|
// t.Error("fail, message should NOT be dropped but processor signalled dropping")
|
||||||
|
// }
|
||||||
|
// cclog.SetDebug()
|
||||||
|
// mp.ProcessMessage(m)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
if c.check != nil {
|
||||||
|
if err := c.check(out); err != nil {
|
||||||
|
t.Errorf("check failed with %v", err.Error())
|
||||||
|
t.Log("Rerun with debugging")
|
||||||
|
cclog.SetDebug()
|
||||||
|
mp.ProcessMessage(m)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkProcessing(b *testing.B) {
|
||||||
|
|
||||||
|
mlist, err := generate_message_lists(b.N, 1000)
|
||||||
|
if err != nil {
|
||||||
|
b.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mp, err := NewMessageProcessor()
|
||||||
|
if err != nil {
|
||||||
|
b.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = mp.FromConfigJSON(json.RawMessage(`{"move_meta_to_tag_if": [{"if" : "name == 'mymetric'", "key":"unit", "value":"unit"}]}`))
|
||||||
|
if err != nil {
|
||||||
|
b.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b.StartTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
for _, m := range mlist[i] {
|
||||||
|
if _, err := mp.ProcessMessage(m); err != nil {
|
||||||
|
b.Errorf("failed processing message '%s': %v", m.ToLineProtocol(nil), err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.StopTimer()
|
||||||
|
b.ReportMetric(float64(b.Elapsed())/float64(len(mlist)*b.N), "ns/message")
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ package multiChanTicker
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type multiChanTicker struct {
|
type multiChanTicker struct {
|
||||||
@@ -1,8 +1,44 @@
|
|||||||
{
|
{
|
||||||
"natsrecv" : {
|
"natsrecv": {
|
||||||
"type": "nats",
|
"type": "nats",
|
||||||
"address": "nats://my-url",
|
"address": "nats://my-url",
|
||||||
"port" : "4222",
|
"port": "4222",
|
||||||
"database": "testcluster"
|
"database": "testcluster"
|
||||||
|
},
|
||||||
|
"redfish_recv": {
|
||||||
|
"type": "redfish",
|
||||||
|
"endpoint": "https://%h-bmc",
|
||||||
|
"client_config": [
|
||||||
|
{
|
||||||
|
"host_list": "my-host-1-[1-2]",
|
||||||
|
"username": "username-1",
|
||||||
|
"password": "password-1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host_list": "my-host-2-[1,2]",
|
||||||
|
"username": "username-2",
|
||||||
|
"password": "password-2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ipmi_recv": {
|
||||||
|
"type": "ipmi",
|
||||||
|
"endpoint": "ipmi-sensors://%h-ipmi",
|
||||||
|
"exclude_metrics": [
|
||||||
|
"fan_speed",
|
||||||
|
"voltage"
|
||||||
|
],
|
||||||
|
"client_config": [
|
||||||
|
{
|
||||||
|
"username": "username-1",
|
||||||
|
"password": "password-1",
|
||||||
|
"host_list": "my-host-1-[1-2]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"username": "username-2",
|
||||||
|
"password": "password-2",
|
||||||
|
"host_list": "my-host-2-[1,2]"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
This folder contains the ReceiveManager and receiver implementations for the cc-metric-collector.
|
This folder contains the ReceiveManager and receiver implementations for the cc-metric-collector.
|
||||||
|
|
||||||
# Configuration
|
## Configuration
|
||||||
|
|
||||||
The configuration file for the receivers is a list of configurations. The `type` field in each specifies which receiver to initialize.
|
The configuration file for the receivers is a list of configurations. The `type` field in each specifies which receiver to initialize.
|
||||||
|
|
||||||
@@ -21,8 +21,12 @@ This allows to specify
|
|||||||
|
|
||||||
- [`nats`](./natsReceiver.md): Receive metrics from the NATS network
|
- [`nats`](./natsReceiver.md): Receive metrics from the NATS network
|
||||||
- [`prometheus`](./prometheusReceiver.md): Scrape data from a Prometheus client
|
- [`prometheus`](./prometheusReceiver.md): Scrape data from a Prometheus client
|
||||||
|
- [`http`](./httpReceiver.md): Listen for HTTP Post requests transporting metrics in InfluxDB line protocol
|
||||||
|
- [`ipmi`](./ipmiReceiver.md): Read IPMI sensor readings
|
||||||
|
- [`redfish`](redfishReceiver.md) Use the Redfish (specification) to query thermal and power metrics
|
||||||
|
|
||||||
|
## Contributing own receivers
|
||||||
|
|
||||||
# Contributing own receivers
|
|
||||||
A receiver contains a few functions and is derived from the type `Receiver` (in `metricReceiver.go`):
|
A receiver contains a few functions and is derived from the type `Receiver` (in `metricReceiver.go`):
|
||||||
|
|
||||||
For an example, check the [sample receiver](./sampleReceiver.go)
|
For an example, check the [sample receiver](./sampleReceiver.go)
|
||||||
|
|||||||
242
receivers/httpReceiver.go
Normal file
242
receivers/httpReceiver.go
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
package receivers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
mp "github.com/ClusterCockpit/cc-metric-collector/pkg/messageProcessor"
|
||||||
|
influx "github.com/influxdata/line-protocol/v2/lineprotocol"
|
||||||
|
)
|
||||||
|
|
||||||
|
const HTTP_RECEIVER_PORT = "8080"
|
||||||
|
|
||||||
|
type HttpReceiverConfig struct {
|
||||||
|
defaultReceiverConfig
|
||||||
|
Addr string `json:"address"`
|
||||||
|
Port string `json:"port"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
|
||||||
|
// Maximum amount of time to wait for the next request when keep-alives are enabled
|
||||||
|
// should be larger than the measurement interval to keep the connection open
|
||||||
|
IdleTimeout string `json:"idle_timeout"`
|
||||||
|
idleTimeout time.Duration
|
||||||
|
|
||||||
|
// Controls whether HTTP keep-alives are enabled. By default, keep-alives are enabled
|
||||||
|
KeepAlivesEnabled bool `json:"keep_alives_enabled"`
|
||||||
|
|
||||||
|
// Basic authentication
|
||||||
|
Username string `json:"username"`
|
||||||
|
Password string `json:"password"`
|
||||||
|
useBasicAuth bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type HttpReceiver struct {
|
||||||
|
receiver
|
||||||
|
//meta map[string]string
|
||||||
|
config HttpReceiverConfig
|
||||||
|
server *http.Server
|
||||||
|
wg sync.WaitGroup
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *HttpReceiver) Init(name string, config json.RawMessage) error {
|
||||||
|
r.name = fmt.Sprintf("HttpReceiver(%s)", name)
|
||||||
|
|
||||||
|
// Set default values
|
||||||
|
r.config.Port = HTTP_RECEIVER_PORT
|
||||||
|
r.config.KeepAlivesEnabled = true
|
||||||
|
// should be larger than the measurement interval to keep the connection open
|
||||||
|
r.config.IdleTimeout = "120s"
|
||||||
|
|
||||||
|
// Read config
|
||||||
|
if len(config) > 0 {
|
||||||
|
err := json.Unmarshal(config, &r.config)
|
||||||
|
if err != nil {
|
||||||
|
cclog.ComponentError(r.name, "Error reading config:", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(r.config.Port) == 0 {
|
||||||
|
return errors.New("not all configuration variables set required by HttpReceiver")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check idle timeout config
|
||||||
|
if len(r.config.IdleTimeout) > 0 {
|
||||||
|
t, err := time.ParseDuration(r.config.IdleTimeout)
|
||||||
|
if err == nil {
|
||||||
|
cclog.ComponentDebug(r.name, "idleTimeout", t)
|
||||||
|
r.config.idleTimeout = t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check basic authentication config
|
||||||
|
if len(r.config.Username) > 0 || len(r.config.Password) > 0 {
|
||||||
|
r.config.useBasicAuth = true
|
||||||
|
}
|
||||||
|
if r.config.useBasicAuth && len(r.config.Username) == 0 {
|
||||||
|
return errors.New("basic authentication requires username")
|
||||||
|
}
|
||||||
|
if r.config.useBasicAuth && len(r.config.Password) == 0 {
|
||||||
|
return errors.New("basic authentication requires password")
|
||||||
|
}
|
||||||
|
msgp, err := mp.NewMessageProcessor()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("initialization of message processor failed: %v", err.Error())
|
||||||
|
}
|
||||||
|
r.mp = msgp
|
||||||
|
if len(r.config.MessageProcessor) > 0 {
|
||||||
|
err = r.mp.FromConfigJSON(r.config.MessageProcessor)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed parsing JSON for message processor: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r.mp.AddAddMetaByCondition("true", "source", r.name)
|
||||||
|
|
||||||
|
//r.meta = map[string]string{"source": r.name}
|
||||||
|
p := r.config.Path
|
||||||
|
if !strings.HasPrefix(p, "/") {
|
||||||
|
p = "/" + p
|
||||||
|
}
|
||||||
|
addr := fmt.Sprintf("%s:%s", r.config.Addr, r.config.Port)
|
||||||
|
uri := addr + p
|
||||||
|
cclog.ComponentDebug(r.name, "INIT", "listen on:", uri)
|
||||||
|
|
||||||
|
// Register handler function r.ServerHttp for path p in the DefaultServeMux
|
||||||
|
http.HandleFunc(p, r.ServerHttp)
|
||||||
|
|
||||||
|
// Create http server
|
||||||
|
r.server = &http.Server{
|
||||||
|
Addr: addr,
|
||||||
|
Handler: nil, // handler to invoke, http.DefaultServeMux if nil
|
||||||
|
IdleTimeout: r.config.idleTimeout,
|
||||||
|
}
|
||||||
|
r.server.SetKeepAlivesEnabled(r.config.KeepAlivesEnabled)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *HttpReceiver) Start() {
|
||||||
|
cclog.ComponentDebug(r.name, "START")
|
||||||
|
r.wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
err := r.server.ListenAndServe()
|
||||||
|
if err != nil && err.Error() != "http: Server closed" {
|
||||||
|
cclog.ComponentError(r.name, err.Error())
|
||||||
|
}
|
||||||
|
r.wg.Done()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *HttpReceiver) ServerHttp(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
|
// Check request method, only post method is handled
|
||||||
|
if req.Method != http.MethodPost {
|
||||||
|
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check basic authentication
|
||||||
|
if r.config.useBasicAuth {
|
||||||
|
username, password, ok := req.BasicAuth()
|
||||||
|
if !ok || username != r.config.Username || password != r.config.Password {
|
||||||
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if r.sink != nil {
|
||||||
|
d := influx.NewDecoder(req.Body)
|
||||||
|
for d.Next() {
|
||||||
|
|
||||||
|
// Decode measurement name
|
||||||
|
measurement, err := d.Measurement()
|
||||||
|
if err != nil {
|
||||||
|
msg := "ServerHttp: Failed to decode measurement: " + err.Error()
|
||||||
|
cclog.ComponentError(r.name, msg)
|
||||||
|
http.Error(w, msg, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode tags
|
||||||
|
tags := make(map[string]string)
|
||||||
|
for {
|
||||||
|
key, value, err := d.NextTag()
|
||||||
|
if err != nil {
|
||||||
|
msg := "ServerHttp: Failed to decode tag: " + err.Error()
|
||||||
|
cclog.ComponentError(r.name, msg)
|
||||||
|
http.Error(w, msg, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if key == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
tags[string(key)] = string(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode fields
|
||||||
|
fields := make(map[string]interface{})
|
||||||
|
for {
|
||||||
|
key, value, err := d.NextField()
|
||||||
|
if err != nil {
|
||||||
|
msg := "ServerHttp: Failed to decode field: " + err.Error()
|
||||||
|
cclog.ComponentError(r.name, msg)
|
||||||
|
http.Error(w, msg, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if key == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fields[string(key)] = value.Interface()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode time stamp
|
||||||
|
t, err := d.Time(influx.Nanosecond, time.Time{})
|
||||||
|
if err != nil {
|
||||||
|
msg := "ServerHttp: Failed to decode time stamp: " + err.Error()
|
||||||
|
cclog.ComponentError(r.name, msg)
|
||||||
|
http.Error(w, msg, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
y, _ := lp.NewMessage(
|
||||||
|
string(measurement),
|
||||||
|
tags,
|
||||||
|
nil,
|
||||||
|
fields,
|
||||||
|
t,
|
||||||
|
)
|
||||||
|
|
||||||
|
m, err := r.mp.ProcessMessage(y)
|
||||||
|
if err == nil && m != nil {
|
||||||
|
r.sink <- m
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// Check for IO errors
|
||||||
|
err := d.Err()
|
||||||
|
if err != nil {
|
||||||
|
msg := "ServerHttp: Failed to decode: " + err.Error()
|
||||||
|
cclog.ComponentError(r.name, msg)
|
||||||
|
http.Error(w, msg, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *HttpReceiver) Close() {
|
||||||
|
r.server.Shutdown(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHttpReceiver(name string, config json.RawMessage) (Receiver, error) {
|
||||||
|
r := new(HttpReceiver)
|
||||||
|
err := r.Init(name, config)
|
||||||
|
return r, err
|
||||||
|
}
|
||||||
43
receivers/httpReceiver.md
Normal file
43
receivers/httpReceiver.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
## `http` receiver
|
||||||
|
|
||||||
|
The `http` receiver can be used receive metrics through HTTP POST requests.
|
||||||
|
|
||||||
|
### Configuration structure
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"<name>": {
|
||||||
|
"type": "http",
|
||||||
|
"address" : "",
|
||||||
|
"port" : "8080",
|
||||||
|
"path" : "/write",
|
||||||
|
"idle_timeout": "120s",
|
||||||
|
"username": "myUser",
|
||||||
|
"password": "myPW"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- `type`: makes the receiver a `http` receiver
|
||||||
|
- `address`: Listen address
|
||||||
|
- `port`: Listen port
|
||||||
|
- `path`: URL path for the write endpoint
|
||||||
|
- `idle_timeout`: Maximum amount of time to wait for the next request when keep-alives are enabled should be larger than the measurement interval to keep the connection open
|
||||||
|
- `keep_alives_enabled`: Controls whether HTTP keep-alives are enabled. By default, keep-alives are enabled.
|
||||||
|
- `username`: username for basic authentication
|
||||||
|
- `password`: password for basic authentication
|
||||||
|
|
||||||
|
The HTTP endpoint listens to `http://<address>:<port>/<path>`
|
||||||
|
|
||||||
|
### Debugging
|
||||||
|
|
||||||
|
- Install [curl](https://curl.se/)
|
||||||
|
- Use curl to send message to `http` receiver
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl http://localhost:8080/write \
|
||||||
|
--user "myUser:myPW" \
|
||||||
|
--data \
|
||||||
|
"myMetric,hostname=myHost,type=hwthread,type-id=0,unit=Hz value=400000i 1694777161164284635
|
||||||
|
myMetric,hostname=myHost,type=hwthread,type-id=1,unit=Hz value=400001i 1694777161164284635"
|
||||||
|
```
|
||||||
571
receivers/ipmiReceiver.go
Normal file
571
receivers/ipmiReceiver.go
Normal file
@@ -0,0 +1,571 @@
|
|||||||
|
package receivers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
|
"github.com/ClusterCockpit/cc-metric-collector/pkg/hostlist"
|
||||||
|
mp "github.com/ClusterCockpit/cc-metric-collector/pkg/messageProcessor"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IPMIReceiverClientConfig struct {
|
||||||
|
|
||||||
|
// Hostname the IPMI service belongs to
|
||||||
|
Protocol string // Protocol / tool to use for IPMI sensor reading
|
||||||
|
DriverType string // Out of band IPMI driver
|
||||||
|
Fanout int // Maximum number of simultaneous IPMI connections
|
||||||
|
NumHosts int // Number of remote IPMI devices with the same configuration
|
||||||
|
IPMIHosts string // List of remote IPMI devices to communicate with
|
||||||
|
IPMI2HostMapping map[string]string // Mapping between IPMI device name and host name
|
||||||
|
Username string // User name to authenticate with
|
||||||
|
Password string // Password to use for authentication
|
||||||
|
CLIOptions []string // Additional command line options for ipmi-sensors
|
||||||
|
isExcluded map[string]bool // is metric excluded
|
||||||
|
mp mp.MessageProcessor
|
||||||
|
}
|
||||||
|
|
||||||
|
type IPMIReceiver struct {
|
||||||
|
receiver
|
||||||
|
config struct {
|
||||||
|
defaultReceiverConfig
|
||||||
|
Interval time.Duration
|
||||||
|
|
||||||
|
// Client config for each IPMI hosts
|
||||||
|
ClientConfigs []IPMIReceiverClientConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
// Storage for static information
|
||||||
|
//meta map[string]string
|
||||||
|
|
||||||
|
done chan bool // channel to finish / stop IPMI receiver
|
||||||
|
wg sync.WaitGroup // wait group for IPMI receiver
|
||||||
|
mp mp.MessageProcessor
|
||||||
|
}
|
||||||
|
|
||||||
|
// doReadMetrics reads metrics from all configure IPMI hosts.
|
||||||
|
func (r *IPMIReceiver) doReadMetric() {
|
||||||
|
for i := range r.config.ClientConfigs {
|
||||||
|
clientConfig := &r.config.ClientConfigs[i]
|
||||||
|
var cmd_options []string
|
||||||
|
if clientConfig.Protocol == "ipmi-sensors" {
|
||||||
|
cmd_options = append(cmd_options,
|
||||||
|
"--always-prefix",
|
||||||
|
"--sdr-cache-recreate",
|
||||||
|
// Attempt to interpret OEM data, such as event data, sensor readings, or general extra info
|
||||||
|
"--interpret-oem-data",
|
||||||
|
// Ignore not-available (i.e. N/A) sensors in output
|
||||||
|
"--ignore-not-available-sensors",
|
||||||
|
// Ignore unrecognized sensor events
|
||||||
|
"--ignore-unrecognized-events",
|
||||||
|
// Output fields in comma separated format
|
||||||
|
"--comma-separated-output",
|
||||||
|
// Do not output column headers
|
||||||
|
"--no-header-output",
|
||||||
|
// Output non-abbreviated units (e.g. 'Amps' instead of 'A').
|
||||||
|
// May aid in disambiguation of units (e.g. 'C' for Celsius or Coulombs).
|
||||||
|
"--non-abbreviated-units",
|
||||||
|
"--fanout", fmt.Sprint(clientConfig.Fanout),
|
||||||
|
"--driver-type", clientConfig.DriverType,
|
||||||
|
"--hostname", clientConfig.IPMIHosts,
|
||||||
|
"--username", clientConfig.Username,
|
||||||
|
"--password", clientConfig.Password,
|
||||||
|
)
|
||||||
|
cmd_options := append(cmd_options, clientConfig.CLIOptions...)
|
||||||
|
|
||||||
|
command := exec.Command("ipmi-sensors", cmd_options...)
|
||||||
|
stdout, _ := command.StdoutPipe()
|
||||||
|
errBuf := new(bytes.Buffer)
|
||||||
|
command.Stderr = errBuf
|
||||||
|
|
||||||
|
// start command
|
||||||
|
if err := command.Start(); err != nil {
|
||||||
|
cclog.ComponentError(
|
||||||
|
r.name,
|
||||||
|
fmt.Sprintf("doReadMetric(): Failed to start command \"%s\": %v", command.String(), err),
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read command output
|
||||||
|
const (
|
||||||
|
idxID = iota
|
||||||
|
idxName
|
||||||
|
idxType
|
||||||
|
idxReading
|
||||||
|
idxUnits
|
||||||
|
idxEvent
|
||||||
|
)
|
||||||
|
numPrefixRegex := regexp.MustCompile("^[[:digit:]][[:digit:]]-(.*)$")
|
||||||
|
scanner := bufio.NewScanner(stdout)
|
||||||
|
for scanner.Scan() {
|
||||||
|
// Read host
|
||||||
|
v1 := strings.Split(scanner.Text(), ": ")
|
||||||
|
if len(v1) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
host, ok := clientConfig.IPMI2HostMapping[v1[0]]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read sensors
|
||||||
|
v2 := strings.Split(v1[1], ",")
|
||||||
|
if len(v2) != 6 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Skip sensors with non available sensor readings
|
||||||
|
if v2[idxReading] == "N/A" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
metric := strings.ToLower(v2[idxType])
|
||||||
|
name := strings.ToLower(
|
||||||
|
strings.Replace(
|
||||||
|
strings.TrimSpace(
|
||||||
|
v2[idxName]), " ", "_", -1))
|
||||||
|
// remove prefix enumeration like 01-...
|
||||||
|
if v := numPrefixRegex.FindStringSubmatch(name); v != nil {
|
||||||
|
name = v[1]
|
||||||
|
}
|
||||||
|
unit := v2[idxUnits]
|
||||||
|
if unit == "Watts" {
|
||||||
|
|
||||||
|
// Power
|
||||||
|
metric = "power"
|
||||||
|
name = strings.TrimSuffix(name, "_power")
|
||||||
|
name = strings.TrimSuffix(name, "_pwr")
|
||||||
|
name = strings.TrimPrefix(name, "pwr_")
|
||||||
|
} else if metric == "voltage" &&
|
||||||
|
unit == "Volts" {
|
||||||
|
|
||||||
|
// Voltage
|
||||||
|
name = strings.TrimPrefix(name, "volt_")
|
||||||
|
} else if metric == "current" &&
|
||||||
|
unit == "Amps" {
|
||||||
|
|
||||||
|
// Current
|
||||||
|
unit = "Ampere"
|
||||||
|
} else if metric == "temperature" &&
|
||||||
|
unit == "degrees C" {
|
||||||
|
|
||||||
|
// Temperature
|
||||||
|
name = strings.TrimSuffix(name, "_temp")
|
||||||
|
unit = "degC"
|
||||||
|
} else if metric == "temperature" &&
|
||||||
|
unit == "degrees F" {
|
||||||
|
|
||||||
|
// Temperature
|
||||||
|
name = strings.TrimSuffix(name, "_temp")
|
||||||
|
unit = "degF"
|
||||||
|
} else if metric == "fan" && unit == "RPM" {
|
||||||
|
|
||||||
|
// Fan speed
|
||||||
|
metric = "fan_speed"
|
||||||
|
name = strings.TrimSuffix(name, "_tach")
|
||||||
|
name = strings.TrimPrefix(name, "spd_")
|
||||||
|
} else if (metric == "cooling device" ||
|
||||||
|
metric == "other units based sensor") &&
|
||||||
|
name == "system_air_flow" &&
|
||||||
|
unit == "CFM" {
|
||||||
|
|
||||||
|
// Air flow
|
||||||
|
metric = "air_flow"
|
||||||
|
name = strings.TrimSuffix(name, "_air_flow")
|
||||||
|
unit = "CubicFeetPerMinute"
|
||||||
|
} else if (metric == "processor" ||
|
||||||
|
metric == "other units based sensor") &&
|
||||||
|
(name == "cpu_utilization" ||
|
||||||
|
name == "io_utilization" ||
|
||||||
|
name == "mem_utilization" ||
|
||||||
|
name == "sys_utilization") &&
|
||||||
|
(unit == "unspecified" ||
|
||||||
|
unit == "%") {
|
||||||
|
|
||||||
|
// Utilization
|
||||||
|
metric = "utilization"
|
||||||
|
name = strings.TrimSuffix(name, "_utilization")
|
||||||
|
unit = "percent"
|
||||||
|
} else {
|
||||||
|
if false {
|
||||||
|
// Debug output for unprocessed metrics
|
||||||
|
fmt.Printf(
|
||||||
|
"host: '%s', metric: '%s', name: '%s', unit: '%s'\n",
|
||||||
|
host, metric, name, unit)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip excluded metrics
|
||||||
|
if clientConfig.isExcluded[metric] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse sensor value
|
||||||
|
value, err := strconv.ParseFloat(v2[idxReading], 64)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
y, err := lp.NewMessage(
|
||||||
|
metric,
|
||||||
|
map[string]string{
|
||||||
|
"hostname": host,
|
||||||
|
"type": "node",
|
||||||
|
"name": name,
|
||||||
|
},
|
||||||
|
map[string]string{
|
||||||
|
"source": r.name,
|
||||||
|
"group": "IPMI",
|
||||||
|
"unit": unit,
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": value,
|
||||||
|
},
|
||||||
|
time.Now())
|
||||||
|
if err == nil {
|
||||||
|
mc, err := clientConfig.mp.ProcessMessage(y)
|
||||||
|
if err == nil && mc != nil {
|
||||||
|
m, err := r.mp.ProcessMessage(mc)
|
||||||
|
if err == nil && m != nil {
|
||||||
|
r.sink <- m
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for command end
|
||||||
|
if err := command.Wait(); err != nil {
|
||||||
|
errMsg, _ := io.ReadAll(errBuf)
|
||||||
|
cclog.ComponentError(
|
||||||
|
r.name,
|
||||||
|
fmt.Sprintf("doReadMetric(): Failed to wait for the end of command \"%s\": %v\n",
|
||||||
|
strings.Replace(command.String(), clientConfig.Password, "<PW>", -1), err),
|
||||||
|
fmt.Sprintf("doReadMetric(): command stderr: \"%s\"\n", string(errMsg)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *IPMIReceiver) Start() {
|
||||||
|
cclog.ComponentDebug(r.name, "START")
|
||||||
|
|
||||||
|
// Start IPMI receiver
|
||||||
|
r.wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer r.wg.Done()
|
||||||
|
|
||||||
|
// Create ticker
|
||||||
|
ticker := time.NewTicker(r.config.Interval)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
for {
|
||||||
|
r.doReadMetric()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case tickerTime := <-ticker.C:
|
||||||
|
// Check if we missed the ticker event
|
||||||
|
if since := time.Since(tickerTime); since > 5*time.Second {
|
||||||
|
cclog.ComponentInfo(r.name, "Missed ticker event for more then", since)
|
||||||
|
}
|
||||||
|
|
||||||
|
// process ticker event -> continue
|
||||||
|
continue
|
||||||
|
case <-r.done:
|
||||||
|
// process done event
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
cclog.ComponentDebug(r.name, "STARTED")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close receiver: close network connection, close files, close libraries, ...
|
||||||
|
func (r *IPMIReceiver) Close() {
|
||||||
|
cclog.ComponentDebug(r.name, "CLOSE")
|
||||||
|
|
||||||
|
// Send the signal and wait
|
||||||
|
close(r.done)
|
||||||
|
r.wg.Wait()
|
||||||
|
|
||||||
|
cclog.ComponentDebug(r.name, "DONE")
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewIPMIReceiver creates a new instance of the redfish receiver
|
||||||
|
// Initialize the receiver by giving it a name and reading in the config JSON
|
||||||
|
func NewIPMIReceiver(name string, config json.RawMessage) (Receiver, error) {
|
||||||
|
var err error
|
||||||
|
r := new(IPMIReceiver)
|
||||||
|
|
||||||
|
// Config options from config file
|
||||||
|
configJSON := struct {
|
||||||
|
defaultReceiverConfig
|
||||||
|
|
||||||
|
// How often the IPMI sensor metrics should be read and send to the sink (default: 30 s)
|
||||||
|
IntervalString string `json:"interval,omitempty"`
|
||||||
|
|
||||||
|
// Maximum number of simultaneous IPMI connections (default: 64)
|
||||||
|
Fanout int `json:"fanout,omitempty"`
|
||||||
|
|
||||||
|
// Out of band IPMI driver (default: LAN_2_0)
|
||||||
|
DriverType string `json:"driver_type,omitempty"`
|
||||||
|
|
||||||
|
// Default client username, password and endpoint
|
||||||
|
Username *string `json:"username"` // User name to authenticate with
|
||||||
|
Password *string `json:"password"` // Password to use for authentication
|
||||||
|
Endpoint *string `json:"endpoint"` // URL of the IPMI device
|
||||||
|
|
||||||
|
// Globally excluded metrics
|
||||||
|
ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
|
||||||
|
|
||||||
|
ClientConfigs []struct {
|
||||||
|
Fanout int `json:"fanout,omitempty"` // Maximum number of simultaneous IPMI connections (default: 64)
|
||||||
|
DriverType string `json:"driver_type,omitempty"` // Out of band IPMI driver (default: LAN_2_0)
|
||||||
|
HostList string `json:"host_list"` // List of hosts with the same client configuration
|
||||||
|
Username *string `json:"username"` // User name to authenticate with
|
||||||
|
Password *string `json:"password"` // Password to use for authentication
|
||||||
|
Endpoint *string `json:"endpoint"` // URL of the IPMI service
|
||||||
|
|
||||||
|
// Per client excluded metrics
|
||||||
|
ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
|
||||||
|
|
||||||
|
// Additional command line options for ipmi-sensors
|
||||||
|
CLIOptions []string `json:"cli_options,omitempty"`
|
||||||
|
MessageProcessor json.RawMessage `json:"process_messages,omitempty"`
|
||||||
|
} `json:"client_config"`
|
||||||
|
}{
|
||||||
|
// Set defaults values
|
||||||
|
// Allow overwriting these defaults by reading config JSON
|
||||||
|
Fanout: 64,
|
||||||
|
DriverType: "LAN_2_0",
|
||||||
|
IntervalString: "30s",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set name of IPMIReceiver
|
||||||
|
r.name = fmt.Sprintf("IPMIReceiver(%s)", name)
|
||||||
|
|
||||||
|
// Create done channel
|
||||||
|
r.done = make(chan bool)
|
||||||
|
|
||||||
|
p, err := mp.NewMessageProcessor()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("initialization of message processor failed: %v", err.Error())
|
||||||
|
}
|
||||||
|
r.mp = p
|
||||||
|
|
||||||
|
// Set static information
|
||||||
|
//r.meta = map[string]string{"source": r.name}
|
||||||
|
r.mp.AddAddMetaByCondition("true", "source", r.name)
|
||||||
|
|
||||||
|
// Read the IPMI receiver specific JSON config
|
||||||
|
if len(config) > 0 {
|
||||||
|
d := json.NewDecoder(bytes.NewReader(config))
|
||||||
|
d.DisallowUnknownFields()
|
||||||
|
if err := d.Decode(&configJSON); err != nil {
|
||||||
|
cclog.ComponentError(r.name, "Error reading config:", err.Error())
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(r.config.MessageProcessor) > 0 {
|
||||||
|
err = r.mp.FromConfigJSON(r.config.MessageProcessor)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed parsing JSON for message processor: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Convert interval string representation to duration
|
||||||
|
|
||||||
|
r.config.Interval, err = time.ParseDuration(configJSON.IntervalString)
|
||||||
|
if err != nil {
|
||||||
|
err := fmt.Errorf(
|
||||||
|
"failed to parse duration string interval='%s': %w",
|
||||||
|
configJSON.IntervalString,
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
cclog.Error(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create client config from JSON config
|
||||||
|
totalNumHosts := 0
|
||||||
|
for i := range configJSON.ClientConfigs {
|
||||||
|
clientConfigJSON := &configJSON.ClientConfigs[i]
|
||||||
|
|
||||||
|
var endpoint string
|
||||||
|
if clientConfigJSON.Endpoint != nil {
|
||||||
|
endpoint = *clientConfigJSON.Endpoint
|
||||||
|
} else if configJSON.Endpoint != nil {
|
||||||
|
endpoint = *configJSON.Endpoint
|
||||||
|
} else {
|
||||||
|
err := fmt.Errorf("client config number %v requires endpoint", i)
|
||||||
|
cclog.ComponentError(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fanout := configJSON.Fanout
|
||||||
|
if clientConfigJSON.Fanout != 0 {
|
||||||
|
fanout = clientConfigJSON.Fanout
|
||||||
|
}
|
||||||
|
|
||||||
|
driverType := configJSON.DriverType
|
||||||
|
if clientConfigJSON.DriverType != "" {
|
||||||
|
driverType = clientConfigJSON.DriverType
|
||||||
|
}
|
||||||
|
if driverType != "LAN" && driverType != "LAN_2_0" {
|
||||||
|
err := fmt.Errorf("client config number %v has invalid driver type %s", i, driverType)
|
||||||
|
cclog.ComponentError(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var protocol string
|
||||||
|
var host_pattern string
|
||||||
|
if e := strings.Split(endpoint, "://"); len(e) == 2 {
|
||||||
|
protocol = e[0]
|
||||||
|
host_pattern = e[1]
|
||||||
|
} else {
|
||||||
|
err := fmt.Errorf("client config number %v has invalid endpoint %s", i, endpoint)
|
||||||
|
cclog.ComponentError(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var username string
|
||||||
|
if clientConfigJSON.Username != nil {
|
||||||
|
username = *clientConfigJSON.Username
|
||||||
|
} else if configJSON.Username != nil {
|
||||||
|
username = *configJSON.Username
|
||||||
|
} else {
|
||||||
|
err := fmt.Errorf("client config number %v requires username", i)
|
||||||
|
cclog.ComponentError(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var password string
|
||||||
|
if clientConfigJSON.Password != nil {
|
||||||
|
password = *clientConfigJSON.Password
|
||||||
|
} else if configJSON.Password != nil {
|
||||||
|
password = *configJSON.Password
|
||||||
|
} else {
|
||||||
|
err := fmt.Errorf("client config number %v requires password", i)
|
||||||
|
cclog.ComponentError(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create mapping between IPMI host name and node host name
|
||||||
|
// This also guaranties that all IPMI host names are unique
|
||||||
|
ipmi2HostMapping := make(map[string]string)
|
||||||
|
hostList, err := hostlist.Expand(clientConfigJSON.HostList)
|
||||||
|
if err != nil {
|
||||||
|
err := fmt.Errorf("client config number %d failed to parse host list %s: %v",
|
||||||
|
i, clientConfigJSON.HostList, err)
|
||||||
|
cclog.ComponentError(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, host := range hostList {
|
||||||
|
ipmiHost := strings.Replace(host_pattern, "%h", host, -1)
|
||||||
|
ipmi2HostMapping[ipmiHost] = host
|
||||||
|
}
|
||||||
|
|
||||||
|
numHosts := len(ipmi2HostMapping)
|
||||||
|
totalNumHosts += numHosts
|
||||||
|
ipmiHostList := make([]string, 0, numHosts)
|
||||||
|
for ipmiHost := range ipmi2HostMapping {
|
||||||
|
ipmiHostList = append(ipmiHostList, ipmiHost)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Additional command line options
|
||||||
|
for _, v := range clientConfigJSON.CLIOptions {
|
||||||
|
switch {
|
||||||
|
case v == "-u" || strings.HasPrefix(v, "--username"):
|
||||||
|
err := fmt.Errorf("client config number %v: do not set username in cli_options. Use json config username instead", i)
|
||||||
|
cclog.ComponentError(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
case v == "-p" || strings.HasPrefix(v, "--password"):
|
||||||
|
err := fmt.Errorf("client config number %v: do not set password in cli_options. Use json config password instead", i)
|
||||||
|
cclog.ComponentError(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
case v == "-h" || strings.HasPrefix(v, "--hostname"):
|
||||||
|
err := fmt.Errorf("client config number %v: do not set hostname in cli_options. Use json config host_list instead", i)
|
||||||
|
cclog.ComponentError(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
case v == "-D" || strings.HasPrefix(v, "--driver-type"):
|
||||||
|
err := fmt.Errorf("client config number %v: do not set driver type in cli_options. Use json config driver_type instead", i)
|
||||||
|
cclog.ComponentError(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
case v == "-F" || strings.HasPrefix(v, " --fanout"):
|
||||||
|
err := fmt.Errorf("client config number %v: do not set fanout in cli_options. Use json config fanout instead", i)
|
||||||
|
cclog.ComponentError(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
case v == "--always-prefix" ||
|
||||||
|
v == "--sdr-cache-recreate" ||
|
||||||
|
v == "--interpret-oem-data" ||
|
||||||
|
v == "--ignore-not-available-sensors" ||
|
||||||
|
v == "--ignore-unrecognized-events" ||
|
||||||
|
v == "--comma-separated-output" ||
|
||||||
|
v == "--no-header-output" ||
|
||||||
|
v == "--non-abbreviated-units":
|
||||||
|
err := fmt.Errorf("client config number %v: Do not use option %s in cli_options, it is used internally", i, v)
|
||||||
|
cclog.ComponentError(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cliOptions := make([]string, 0)
|
||||||
|
cliOptions = append(cliOptions, clientConfigJSON.CLIOptions...)
|
||||||
|
|
||||||
|
// Is metrics excluded globally or per client
|
||||||
|
isExcluded := make(map[string]bool)
|
||||||
|
for _, key := range clientConfigJSON.ExcludeMetrics {
|
||||||
|
isExcluded[key] = true
|
||||||
|
}
|
||||||
|
for _, key := range configJSON.ExcludeMetrics {
|
||||||
|
isExcluded[key] = true
|
||||||
|
}
|
||||||
|
p, err := mp.NewMessageProcessor()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("initialization of message processor failed: %v", err.Error())
|
||||||
|
}
|
||||||
|
if len(clientConfigJSON.MessageProcessor) > 0 {
|
||||||
|
err = p.FromConfigJSON(clientConfigJSON.MessageProcessor)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed parsing JSON for message processor: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
r.config.ClientConfigs = append(
|
||||||
|
r.config.ClientConfigs,
|
||||||
|
IPMIReceiverClientConfig{
|
||||||
|
Protocol: protocol,
|
||||||
|
Fanout: fanout,
|
||||||
|
DriverType: driverType,
|
||||||
|
NumHosts: numHosts,
|
||||||
|
IPMIHosts: strings.Join(ipmiHostList, ","),
|
||||||
|
IPMI2HostMapping: ipmi2HostMapping,
|
||||||
|
Username: username,
|
||||||
|
Password: password,
|
||||||
|
CLIOptions: cliOptions,
|
||||||
|
isExcluded: isExcluded,
|
||||||
|
mp: p,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if totalNumHosts == 0 {
|
||||||
|
err := fmt.Errorf("at least one IPMI host config is required")
|
||||||
|
cclog.ComponentError(r.name, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cclog.ComponentInfo(r.name, "monitoring", totalNumHosts, "IPMI hosts")
|
||||||
|
return r, nil
|
||||||
|
}
|
||||||
48
receivers/ipmiReceiver.md
Normal file
48
receivers/ipmiReceiver.md
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
## IPMI Receiver
|
||||||
|
|
||||||
|
The IPMI Receiver uses `ipmi-sensors` from the [FreeIPMI](https://www.gnu.org/software/freeipmi/) project to read IPMI sensor readings and sensor data repository (SDR) information. The available metrics depend on the sensors provided by the hardware vendor but typically contain temperature, fan speed, voltage and power metrics.
|
||||||
|
|
||||||
|
### Configuration structure
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"<IPMI receiver name>": {
|
||||||
|
"type": "ipmi",
|
||||||
|
"interval": "30s",
|
||||||
|
"fanout": 256,
|
||||||
|
"username": "<Username>",
|
||||||
|
"password": "<Password>",
|
||||||
|
"endpoint": "ipmi-sensors://%h-bmc",
|
||||||
|
"exclude_metrics": [ "fan_speed", "voltage" ],
|
||||||
|
"client_config": [
|
||||||
|
{
|
||||||
|
"host_list": "n[1,2-4]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host_list": "n[5-6]",
|
||||||
|
"driver_type": "LAN",
|
||||||
|
"cli_options": [ "--workaround-flags=..." ],
|
||||||
|
"password": "<Password 2>"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Global settings:
|
||||||
|
|
||||||
|
- `interval`: How often the IPMI sensor metrics should be read and send to the sink (default: 30 s)
|
||||||
|
|
||||||
|
Global and per IPMI device settings (per IPMI device settings overwrite the global settings):
|
||||||
|
|
||||||
|
- `exclude_metrics`: list of excluded metrics e.g. fan_speed, power, temperature, utilization, voltage
|
||||||
|
- `fanout`: Maximum number of simultaneous IPMI connections (default: 64)
|
||||||
|
- `driver_type`: Out of band IPMI driver (default: LAN_2_0)
|
||||||
|
- `username`: User name to authenticate with
|
||||||
|
- `password`: Password to use for authentication
|
||||||
|
- `endpoint`: URL of the IPMI device (placeholder `%h` gets replaced by the hostname)
|
||||||
|
|
||||||
|
Per IPMI device settings:
|
||||||
|
|
||||||
|
- `host_list`: List of hosts with the same client configuration
|
||||||
|
- `cli_options`: Additional command line options for ipmi-sensors
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
package receivers
|
package receivers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
"encoding/json"
|
||||||
|
|
||||||
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
|
mp "github.com/ClusterCockpit/cc-metric-collector/pkg/messageProcessor"
|
||||||
)
|
)
|
||||||
|
|
||||||
type defaultReceiverConfig struct {
|
type defaultReceiverConfig struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
MessageProcessor json.RawMessage `json:"process_messages,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receiver configuration: Listen address, port
|
// Receiver configuration: Listen address, port
|
||||||
@@ -19,14 +23,15 @@ type ReceiverConfig struct {
|
|||||||
|
|
||||||
type receiver struct {
|
type receiver struct {
|
||||||
name string
|
name string
|
||||||
sink chan lp.CCMetric
|
sink chan lp.CCMessage
|
||||||
|
mp mp.MessageProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
type Receiver interface {
|
type Receiver interface {
|
||||||
Start()
|
Start()
|
||||||
Close() // Close / finish metric receiver
|
Close() // Close / finish metric receiver
|
||||||
Name() string // Name of the metric receiver
|
Name() string // Name of the metric receiver
|
||||||
SetSink(sink chan lp.CCMetric) // Set sink channel
|
SetSink(sink chan lp.CCMessage) // Set sink channel
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name returns the name of the metric receiver
|
// Name returns the name of the metric receiver
|
||||||
@@ -35,6 +40,6 @@ func (r *receiver) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetSink set the sink channel
|
// SetSink set the sink channel
|
||||||
func (r *receiver) SetSink(sink chan lp.CCMetric) {
|
func (r *receiver) SetSink(sink chan lp.CCMessage) {
|
||||||
r.sink = sink
|
r.sink = sink
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,54 +4,110 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
influx "github.com/influxdata/line-protocol"
|
mp "github.com/ClusterCockpit/cc-metric-collector/pkg/messageProcessor"
|
||||||
|
influx "github.com/influxdata/line-protocol/v2/lineprotocol"
|
||||||
nats "github.com/nats-io/nats.go"
|
nats "github.com/nats-io/nats.go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NatsReceiverConfig struct {
|
type NatsReceiverConfig struct {
|
||||||
Type string `json:"type"`
|
defaultReceiverConfig
|
||||||
Addr string `json:"address"`
|
Addr string `json:"address"`
|
||||||
Port string `json:"port"`
|
Port string `json:"port"`
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
|
User string `json:"user,omitempty"`
|
||||||
|
Password string `json:"password,omitempty"`
|
||||||
|
NkeyFile string `json:"nkey_file,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NatsReceiver struct {
|
type NatsReceiver struct {
|
||||||
receiver
|
receiver
|
||||||
nc *nats.Conn
|
nc *nats.Conn
|
||||||
handler *influx.MetricHandler
|
//meta map[string]string
|
||||||
parser *influx.Parser
|
|
||||||
meta map[string]string
|
|
||||||
config NatsReceiverConfig
|
config NatsReceiverConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
var DefaultTime = func() time.Time {
|
// Start subscribes to the configured NATS subject
|
||||||
return time.Unix(42, 0)
|
// Messages wil be handled by r._NatsReceive
|
||||||
}
|
|
||||||
|
|
||||||
func (r *NatsReceiver) Start() {
|
func (r *NatsReceiver) Start() {
|
||||||
cclog.ComponentDebug(r.name, "START")
|
cclog.ComponentDebug(r.name, "START")
|
||||||
r.nc.Subscribe(r.config.Subject, r._NatsReceive)
|
r.nc.Subscribe(r.config.Subject, r._NatsReceive)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// _NatsReceive receives subscribed messages from the NATS server
|
||||||
func (r *NatsReceiver) _NatsReceive(m *nats.Msg) {
|
func (r *NatsReceiver) _NatsReceive(m *nats.Msg) {
|
||||||
metrics, err := r.parser.Parse(m.Data)
|
|
||||||
if err == nil {
|
|
||||||
for _, m := range metrics {
|
|
||||||
y := lp.FromInfluxMetric(m)
|
|
||||||
for k, v := range r.meta {
|
|
||||||
y.AddMeta(k, v)
|
|
||||||
}
|
|
||||||
if r.sink != nil {
|
if r.sink != nil {
|
||||||
r.sink <- y
|
d := influx.NewDecoderWithBytes(m.Data)
|
||||||
|
for d.Next() {
|
||||||
|
|
||||||
|
// Decode measurement name
|
||||||
|
measurement, err := d.Measurement()
|
||||||
|
if err != nil {
|
||||||
|
msg := "_NatsReceive: Failed to decode measurement: " + err.Error()
|
||||||
|
cclog.ComponentError(r.name, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode tags
|
||||||
|
tags := make(map[string]string)
|
||||||
|
for {
|
||||||
|
key, value, err := d.NextTag()
|
||||||
|
if err != nil {
|
||||||
|
msg := "_NatsReceive: Failed to decode tag: " + err.Error()
|
||||||
|
cclog.ComponentError(r.name, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if key == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
tags[string(key)] = string(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode fields
|
||||||
|
fields := make(map[string]interface{})
|
||||||
|
for {
|
||||||
|
key, value, err := d.NextField()
|
||||||
|
if err != nil {
|
||||||
|
msg := "_NatsReceive: Failed to decode field: " + err.Error()
|
||||||
|
cclog.ComponentError(r.name, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if key == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fields[string(key)] = value.Interface()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode time stamp
|
||||||
|
t, err := d.Time(influx.Nanosecond, time.Time{})
|
||||||
|
if err != nil {
|
||||||
|
msg := "_NatsReceive: Failed to decode time: " + err.Error()
|
||||||
|
cclog.ComponentError(r.name, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
y, _ := lp.NewMessage(
|
||||||
|
string(measurement),
|
||||||
|
tags,
|
||||||
|
nil,
|
||||||
|
fields,
|
||||||
|
t,
|
||||||
|
)
|
||||||
|
|
||||||
|
m, err := r.mp.ProcessMessage(y)
|
||||||
|
if err == nil && m != nil {
|
||||||
|
r.sink <- m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes the connection to the NATS server
|
||||||
func (r *NatsReceiver) Close() {
|
func (r *NatsReceiver) Close() {
|
||||||
if r.nc != nil {
|
if r.nc != nil {
|
||||||
cclog.ComponentDebug(r.name, "CLOSE")
|
cclog.ComponentDebug(r.name, "CLOSE")
|
||||||
@@ -59,10 +115,14 @@ func (r *NatsReceiver) Close() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewNatsReceiver creates a new Receiver which subscribes to messages from a NATS server
|
||||||
func NewNatsReceiver(name string, config json.RawMessage) (Receiver, error) {
|
func NewNatsReceiver(name string, config json.RawMessage) (Receiver, error) {
|
||||||
|
var uinfo nats.Option = nil
|
||||||
r := new(NatsReceiver)
|
r := new(NatsReceiver)
|
||||||
r.name = fmt.Sprintf("NatsReceiver(%s)", name)
|
r.name = fmt.Sprintf("NatsReceiver(%s)", name)
|
||||||
r.config.Addr = nats.DefaultURL
|
|
||||||
|
// Read configuration file, allow overwriting default config
|
||||||
|
r.config.Addr = "localhost"
|
||||||
r.config.Port = "4222"
|
r.config.Port = "4222"
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err := json.Unmarshal(config, &r.config)
|
err := json.Unmarshal(config, &r.config)
|
||||||
@@ -76,17 +136,45 @@ func NewNatsReceiver(name string, config json.RawMessage) (Receiver, error) {
|
|||||||
len(r.config.Subject) == 0 {
|
len(r.config.Subject) == 0 {
|
||||||
return nil, errors.New("not all configuration variables set required by NatsReceiver")
|
return nil, errors.New("not all configuration variables set required by NatsReceiver")
|
||||||
}
|
}
|
||||||
r.meta = map[string]string{"source": r.name}
|
p, err := mp.NewMessageProcessor()
|
||||||
uri := fmt.Sprintf("%s:%s", r.config.Addr, r.config.Port)
|
if err != nil {
|
||||||
cclog.ComponentDebug(r.name, "NewNatsReceiver", uri, "Subject", r.config.Subject)
|
return nil, fmt.Errorf("initialization of message processor failed: %v", err.Error())
|
||||||
if nc, err := nats.Connect(uri); err == nil {
|
}
|
||||||
|
r.mp = p
|
||||||
|
if len(r.config.MessageProcessor) > 0 {
|
||||||
|
err = r.mp.FromConfigJSON(r.config.MessageProcessor)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed parsing JSON for message processor: %v", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set metadata
|
||||||
|
// r.meta = map[string]string{
|
||||||
|
// "source": r.name,
|
||||||
|
// }
|
||||||
|
r.mp.AddAddMetaByCondition("true", "source", r.name)
|
||||||
|
|
||||||
|
if len(r.config.User) > 0 && len(r.config.Password) > 0 {
|
||||||
|
uinfo = nats.UserInfo(r.config.User, r.config.Password)
|
||||||
|
} else if len(r.config.NkeyFile) > 0 {
|
||||||
|
_, err := os.Stat(r.config.NkeyFile)
|
||||||
|
if err == nil {
|
||||||
|
uinfo = nats.UserCredentials(r.config.NkeyFile)
|
||||||
|
} else {
|
||||||
|
cclog.ComponentError(r.name, "NKEY file", r.config.NkeyFile, "does not exist: %v", err.Error())
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect to NATS server
|
||||||
|
url := fmt.Sprintf("nats://%s:%s", r.config.Addr, r.config.Port)
|
||||||
|
cclog.ComponentDebug(r.name, "NewNatsReceiver", url, "Subject", r.config.Subject)
|
||||||
|
if nc, err := nats.Connect(url, uinfo); err == nil {
|
||||||
r.nc = nc
|
r.nc = nc
|
||||||
} else {
|
} else {
|
||||||
r.nc = nil
|
r.nc = nil
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
r.handler = influx.NewMetricHandler()
|
|
||||||
r.parser = influx.NewParser(r.handler)
|
|
||||||
r.parser.SetTimeFunc(DefaultTime)
|
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ The `nats` receiver can be used receive metrics from the NATS network. The `nats
|
|||||||
"type": "nats",
|
"type": "nats",
|
||||||
"address" : "nats-server.example.org",
|
"address" : "nats-server.example.org",
|
||||||
"port" : "4222",
|
"port" : "4222",
|
||||||
"subject" : "subject"
|
"subject" : "subject",
|
||||||
|
"user": "natsuser",
|
||||||
|
"password": "natssecret",
|
||||||
|
"nkey_file": "/path/to/nkey_file"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -19,3 +22,35 @@ The `nats` receiver can be used receive metrics from the NATS network. The `nats
|
|||||||
- `address`: Address of the NATS control server
|
- `address`: Address of the NATS control server
|
||||||
- `port`: Port of the NATS control server
|
- `port`: Port of the NATS control server
|
||||||
- `subject`: Subscribes to this subject and receive metrics
|
- `subject`: Subscribes to this subject and receive metrics
|
||||||
|
- `user`: Connect to nats using this user
|
||||||
|
- `password`: Connect to nats using this password
|
||||||
|
- `nkey_file`: Path to credentials file with NKEY
|
||||||
|
|
||||||
|
### Debugging
|
||||||
|
|
||||||
|
- Install NATS server and command line client
|
||||||
|
- Start NATS server
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nats-server --net nats-server.example.org --port 4222
|
||||||
|
```
|
||||||
|
|
||||||
|
- Check NATS server works as expected
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nats --server=nats-server-db.example.org:4222 server check
|
||||||
|
```
|
||||||
|
|
||||||
|
- Use NATS command line client to subscribe to all messages
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nats --server=nats-server-db.example.org:4222 sub ">"
|
||||||
|
```
|
||||||
|
|
||||||
|
- Use NATS command line client to send message to NATS receiver
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nats --server=nats-server-db.example.org:4222 pub subject \
|
||||||
|
"myMetric,hostname=myHost,type=hwthread,type-id=0,unit=Hz value=400000i 1694777161164284635
|
||||||
|
myMetric,hostname=myHost,type=hwthread,type-id=1,unit=Hz value=400001i 1694777161164284635"
|
||||||
|
```
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PrometheusReceiverConfig struct {
|
type PrometheusReceiverConfig struct {
|
||||||
@@ -74,7 +74,7 @@ func (r *PrometheusReceiver) Start() {
|
|||||||
}
|
}
|
||||||
value, err := strconv.ParseFloat(lineSplit[1], 64)
|
value, err := strconv.ParseFloat(lineSplit[1], 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
y, err := lp.New(name, tags, r.meta, map[string]interface{}{"value": value}, t)
|
y, err := lp.NewMessage(name, tags, r.meta, map[string]interface{}{"value": value}, t)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
r.sink <- y
|
r.sink <- y
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,29 +2,31 @@ package receivers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
var AvailableReceivers = map[string]func(name string, config json.RawMessage) (Receiver, error){
|
var AvailableReceivers = map[string]func(name string, config json.RawMessage) (Receiver, error){
|
||||||
|
"http": NewHttpReceiver,
|
||||||
|
"ipmi": NewIPMIReceiver,
|
||||||
"nats": NewNatsReceiver,
|
"nats": NewNatsReceiver,
|
||||||
|
"redfish": NewRedfishReceiver,
|
||||||
}
|
}
|
||||||
|
|
||||||
type receiveManager struct {
|
type receiveManager struct {
|
||||||
inputs []Receiver
|
inputs []Receiver
|
||||||
output chan lp.CCMetric
|
output chan lp.CCMessage
|
||||||
done chan bool
|
|
||||||
wg *sync.WaitGroup
|
|
||||||
config []json.RawMessage
|
config []json.RawMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReceiveManager interface {
|
type ReceiveManager interface {
|
||||||
Init(wg *sync.WaitGroup, receiverConfigFile string) error
|
Init(wg *sync.WaitGroup, receiverConfigFile string) error
|
||||||
AddInput(name string, rawConfig json.RawMessage) error
|
AddInput(name string, rawConfig json.RawMessage) error
|
||||||
AddOutput(output chan lp.CCMetric)
|
AddOutput(output chan lp.CCMessage)
|
||||||
Start()
|
Start()
|
||||||
Close()
|
Close()
|
||||||
}
|
}
|
||||||
@@ -33,8 +35,6 @@ func (rm *receiveManager) Init(wg *sync.WaitGroup, receiverConfigFile string) er
|
|||||||
// Initialize struct fields
|
// Initialize struct fields
|
||||||
rm.inputs = make([]Receiver, 0)
|
rm.inputs = make([]Receiver, 0)
|
||||||
rm.output = nil
|
rm.output = nil
|
||||||
rm.done = make(chan bool)
|
|
||||||
rm.wg = wg
|
|
||||||
rm.config = make([]json.RawMessage, 0)
|
rm.config = make([]json.RawMessage, 0)
|
||||||
|
|
||||||
configFile, err := os.Open(receiverConfigFile)
|
configFile, err := os.Open(receiverConfigFile)
|
||||||
@@ -58,7 +58,7 @@ func (rm *receiveManager) Init(wg *sync.WaitGroup, receiverConfigFile string) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rm *receiveManager) Start() {
|
func (rm *receiveManager) Start() {
|
||||||
rm.wg.Add(1)
|
cclog.ComponentDebug("ReceiveManager", "START")
|
||||||
|
|
||||||
for _, r := range rm.inputs {
|
for _, r := range rm.inputs {
|
||||||
cclog.ComponentDebug("ReceiveManager", "START", r.Name())
|
cclog.ComponentDebug("ReceiveManager", "START", r.Name())
|
||||||
@@ -74,9 +74,13 @@ func (rm *receiveManager) AddInput(name string, rawConfig json.RawMessage) error
|
|||||||
cclog.ComponentError("ReceiveManager", "SKIP", config.Type, "JSON config error:", err.Error())
|
cclog.ComponentError("ReceiveManager", "SKIP", config.Type, "JSON config error:", err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if config.Type == "" {
|
||||||
|
cclog.ComponentError("ReceiveManager", "SKIP", "JSON config for receiver", name, "does not contain a receiver type")
|
||||||
|
return fmt.Errorf("JSON config for receiver %s does not contain a receiver type", name)
|
||||||
|
}
|
||||||
if _, found := AvailableReceivers[config.Type]; !found {
|
if _, found := AvailableReceivers[config.Type]; !found {
|
||||||
cclog.ComponentError("ReceiveManager", "SKIP", config.Type, "unknown receiver:", err.Error())
|
cclog.ComponentError("ReceiveManager", "SKIP", "unknown receiver type:", config.Type)
|
||||||
return err
|
return fmt.Errorf("unknown receiver type: %s", config.Type)
|
||||||
}
|
}
|
||||||
r, err := AvailableReceivers[config.Type](name, rawConfig)
|
r, err := AvailableReceivers[config.Type](name, rawConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -89,7 +93,7 @@ func (rm *receiveManager) AddInput(name string, rawConfig json.RawMessage) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rm *receiveManager) AddOutput(output chan lp.CCMetric) {
|
func (rm *receiveManager) AddOutput(output chan lp.CCMessage) {
|
||||||
rm.output = output
|
rm.output = output
|
||||||
for _, r := range rm.inputs {
|
for _, r := range rm.inputs {
|
||||||
r.SetSink(rm.output)
|
r.SetSink(rm.output)
|
||||||
@@ -97,16 +101,19 @@ func (rm *receiveManager) AddOutput(output chan lp.CCMetric) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rm *receiveManager) Close() {
|
func (rm *receiveManager) Close() {
|
||||||
|
cclog.ComponentDebug("ReceiveManager", "CLOSE")
|
||||||
|
|
||||||
|
// Close all receivers
|
||||||
for _, r := range rm.inputs {
|
for _, r := range rm.inputs {
|
||||||
cclog.ComponentDebug("ReceiveManager", "CLOSE", r.Name())
|
cclog.ComponentDebug("ReceiveManager", "CLOSE", r.Name())
|
||||||
r.Close()
|
r.Close()
|
||||||
}
|
}
|
||||||
rm.wg.Done()
|
|
||||||
cclog.ComponentDebug("ReceiveManager", "CLOSE")
|
cclog.ComponentDebug("ReceiveManager", "DONE")
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(wg *sync.WaitGroup, receiverConfigFile string) (ReceiveManager, error) {
|
func New(wg *sync.WaitGroup, receiverConfigFile string) (ReceiveManager, error) {
|
||||||
r := &receiveManager{}
|
r := new(receiveManager)
|
||||||
err := r.Init(wg, receiverConfigFile)
|
err := r.Init(wg, receiverConfigFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
1055
receivers/redfishReceiver.go
Normal file
1055
receivers/redfishReceiver.go
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user