mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-07-21 12:21:41 +02:00
Compare commits
8 Commits
amqp_sink
...
nats_nkey_
Author | SHA1 | Date | |
---|---|---|---|
|
ccce00d64f | ||
|
a36f8fe19d | ||
|
2efed7c631 | ||
|
2affb4d8a7 | ||
|
55cb12c9f8 | ||
|
b69efdc2a4 | ||
|
caa04da163 | ||
|
0ae537fdc9 |
22
.github/workflows/Release.yml
vendored
22
.github/workflows/Release.yml
vendored
@@ -44,16 +44,16 @@ jobs:
|
|||||||
# Use dnf to install build dependencies
|
# Use dnf to install build dependencies
|
||||||
- name: Install build dependencies
|
- name: Install build dependencies
|
||||||
run: |
|
run: |
|
||||||
dnf --assumeyes install \
|
wget -q https://go.dev/dl/go1.22.4.linux-amd64.tar.gz --output-document=- | \
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/golang-1.21.7-1.module_el8+960+4060efbe.x86_64.rpm \
|
tar --directory=/usr/local --extract --gzip
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/golang-bin-1.21.7-1.module_el8+960+4060efbe.x86_64.rpm \
|
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/golang-src-1.21.7-1.module_el8+960+4060efbe.noarch.rpm \
|
go version
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/go-toolset-1.21.7-1.module_el8+960+4060efbe.x86_64.rpm
|
|
||||||
|
|
||||||
- name: RPM build MetricCollector
|
- name: RPM build MetricCollector
|
||||||
id: rpmbuild
|
id: rpmbuild
|
||||||
run: |
|
run: |
|
||||||
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
||||||
make RPM
|
make RPM
|
||||||
|
|
||||||
# AlmaLinux 8 is a derivate of RedHat Enterprise Linux 8 (UBI8),
|
# AlmaLinux 8 is a derivate of RedHat Enterprise Linux 8 (UBI8),
|
||||||
@@ -114,16 +114,16 @@ jobs:
|
|||||||
# Use dnf to install build dependencies
|
# Use dnf to install build dependencies
|
||||||
- name: Install build dependencies
|
- name: Install build dependencies
|
||||||
run: |
|
run: |
|
||||||
dnf --assumeyes --disableplugin=subscription-manager install \
|
wget -q https://go.dev/dl/go1.22.4.linux-amd64.tar.gz --output-document=- | \
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/golang-1.21.7-1.module_el8+960+4060efbe.x86_64.rpm \
|
tar --directory=/usr/local --extract --gzip
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/golang-bin-1.21.7-1.module_el8+960+4060efbe.x86_64.rpm \
|
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/golang-src-1.21.7-1.module_el8+960+4060efbe.noarch.rpm \
|
go version
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/go-toolset-1.21.7-1.module_el8+960+4060efbe.x86_64.rpm
|
|
||||||
|
|
||||||
- name: RPM build MetricCollector
|
- name: RPM build MetricCollector
|
||||||
id: rpmbuild
|
id: rpmbuild
|
||||||
run: |
|
run: |
|
||||||
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
||||||
make RPM
|
make RPM
|
||||||
|
|
||||||
# See: https://github.com/actions/upload-artifact
|
# See: https://github.com/actions/upload-artifact
|
||||||
@@ -165,7 +165,7 @@ jobs:
|
|||||||
# Use official golang package
|
# Use official golang package
|
||||||
- name: Install Golang
|
- name: Install Golang
|
||||||
run: |
|
run: |
|
||||||
wget -q https://go.dev/dl/go1.21.1.linux-amd64.tar.gz --output-document=- | \
|
wget -q https://go.dev/dl/go1.22.4.linux-amd64.tar.gz --output-document=- | \
|
||||||
tar --directory=/usr/local --extract --gzip
|
tar --directory=/usr/local --extract --gzip
|
||||||
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
||||||
go version
|
go version
|
||||||
|
22
.github/workflows/runonce.yml
vendored
22
.github/workflows/runonce.yml
vendored
@@ -91,16 +91,16 @@ jobs:
|
|||||||
# Use dnf to install build dependencies
|
# Use dnf to install build dependencies
|
||||||
- name: Install build dependencies
|
- name: Install build dependencies
|
||||||
run: |
|
run: |
|
||||||
dnf --assumeyes install \
|
wget -q https://go.dev/dl/go1.22.4.linux-amd64.tar.gz --output-document=- | \
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/golang-1.21.7-1.module_el8+960+4060efbe.x86_64.rpm \
|
tar --directory=/usr/local --extract --gzip
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/golang-bin-1.21.7-1.module_el8+960+4060efbe.x86_64.rpm \
|
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/golang-src-1.21.7-1.module_el8+960+4060efbe.noarch.rpm \
|
go version
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/go-toolset-1.21.7-1.module_el8+960+4060efbe.x86_64.rpm
|
|
||||||
|
|
||||||
- name: RPM build MetricCollector
|
- name: RPM build MetricCollector
|
||||||
id: rpmbuild
|
id: rpmbuild
|
||||||
run: |
|
run: |
|
||||||
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
||||||
make RPM
|
make RPM
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -129,16 +129,16 @@ jobs:
|
|||||||
# Use dnf to install build dependencies
|
# Use dnf to install build dependencies
|
||||||
- name: Install build dependencies
|
- name: Install build dependencies
|
||||||
run: |
|
run: |
|
||||||
dnf --assumeyes --disableplugin=subscription-manager install \
|
wget -q https://go.dev/dl/go1.22.4.linux-amd64.tar.gz --output-document=- | \
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/golang-1.21.7-1.module_el8+960+4060efbe.x86_64.rpm \
|
tar --directory=/usr/local --extract --gzip
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/golang-bin-1.21.7-1.module_el8+960+4060efbe.x86_64.rpm \
|
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/golang-src-1.21.7-1.module_el8+960+4060efbe.noarch.rpm \
|
go version
|
||||||
http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/go-toolset-1.21.7-1.module_el8+960+4060efbe.x86_64.rpm
|
|
||||||
|
|
||||||
- name: RPM build MetricCollector
|
- name: RPM build MetricCollector
|
||||||
id: rpmbuild
|
id: rpmbuild
|
||||||
run: |
|
run: |
|
||||||
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
git config --global --add safe.directory /__w/cc-metric-collector/cc-metric-collector
|
||||||
|
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
||||||
make RPM
|
make RPM
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -165,7 +165,7 @@ jobs:
|
|||||||
# Use official golang package
|
# Use official golang package
|
||||||
- name: Install Golang
|
- name: Install Golang
|
||||||
run: |
|
run: |
|
||||||
wget -q https://go.dev/dl/go1.21.1.linux-amd64.tar.gz --output-document=- | \
|
wget -q https://go.dev/dl/go1.22.4.linux-amd64.tar.gz --output-document=- | \
|
||||||
tar --directory=/usr/local --extract --gzip
|
tar --directory=/usr/local --extract --gzip
|
||||||
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
export PATH=/usr/local/go/bin:/usr/local/go/pkg/tool/linux_amd64:$PATH
|
||||||
go version
|
go version
|
||||||
|
@@ -12,6 +12,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
|
lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
|
||||||
)
|
)
|
||||||
@@ -54,15 +55,30 @@ func (m *IpmiCollector) Init(config json.RawMessage) error {
|
|||||||
// Check if executables ipmitool or ipmisensors are found
|
// 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 {
|
||||||
m.ipmitool = p
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p, err = exec.LookPath(m.config.IpmisensorsPath)
|
p, err = exec.LookPath(m.config.IpmisensorsPath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
m.ipmisensors = p
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(m.ipmitool) == 0 && len(m.ipmisensors) == 0 {
|
if len(m.ipmitool) == 0 && len(m.ipmisensors) == 0 {
|
||||||
return errors.New("no IPMI reader found")
|
return errors.New("no usable IPMI reader found")
|
||||||
}
|
}
|
||||||
|
|
||||||
m.init = true
|
m.init = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -119,8 +135,8 @@ func (m *IpmiCollector) readIpmiTool(cmd string, output chan lp.CCMetric) {
|
|||||||
cclog.ComponentError(
|
cclog.ComponentError(
|
||||||
m.name,
|
m.name,
|
||||||
fmt.Sprintf("readIpmiTool(): Failed to wait for the end of command \"%s\": %v\n", command.String(), err),
|
fmt.Sprintf("readIpmiTool(): Failed to wait for the end of command \"%s\": %v\n", command.String(), err),
|
||||||
fmt.Sprintf("readIpmiTool(): command stderr: \"%s\"\n", string(errMsg)),
|
|
||||||
)
|
)
|
||||||
|
cclog.ComponentError(m.name, fmt.Sprintf("readIpmiTool(): command stderr: \"%s\"\n", strings.TrimSpace(string(errMsg))))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,8 +12,8 @@ The global file contains the paths to the other four files and some global optio
|
|||||||
"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"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
||||||
@@ -13,10 +14,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type NatsReceiverConfig struct {
|
type NatsReceiverConfig struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
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 {
|
||||||
@@ -109,6 +113,7 @@ func (r *NatsReceiver) Close() {
|
|||||||
|
|
||||||
// NewNatsReceiver creates a new Receiver which subscribes to messages from a NATS server
|
// 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)
|
||||||
|
|
||||||
@@ -133,10 +138,22 @@ func NewNatsReceiver(name string, config json.RawMessage) (Receiver, error) {
|
|||||||
"source": r.name,
|
"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
|
// Connect to NATS server
|
||||||
url := fmt.Sprintf("nats://%s:%s", r.config.Addr, r.config.Port)
|
url := fmt.Sprintf("nats://%s:%s", r.config.Addr, r.config.Port)
|
||||||
cclog.ComponentDebug(r.name, "NewNatsReceiver", url, "Subject", r.config.Subject)
|
cclog.ComponentDebug(r.name, "NewNatsReceiver", url, "Subject", r.config.Subject)
|
||||||
if nc, err := nats.Connect(url); err == nil {
|
if nc, err := nats.Connect(url, uinfo); err == nil {
|
||||||
r.nc = nc
|
r.nc = nc
|
||||||
} else {
|
} else {
|
||||||
r.nc = nil
|
r.nc = 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,6 +22,9 @@ 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
|
### Debugging
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@ This folder contains the SinkManager and sink implementations for the cc-metric-
|
|||||||
The configuration file for the sinks is a list of configurations. The `type` field in each specifies which sink to initialize.
|
The configuration file for the sinks is a list of configurations. The `type` field in each specifies which sink to initialize.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
[
|
{
|
||||||
"mystdout" : {
|
"mystdout" : {
|
||||||
"type" : "stdout",
|
"type" : "stdout",
|
||||||
"meta_as_tags" : [
|
"meta_as_tags" : [
|
||||||
@@ -31,7 +31,7 @@ The configuration file for the sinks is a list of configurations. The `type` fie
|
|||||||
"database" : "ccmetric",
|
"database" : "ccmetric",
|
||||||
"password" : "<jwt token>"
|
"password" : "<jwt token>"
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ type NatsSinkConfig struct {
|
|||||||
User string `json:"user,omitempty"`
|
User string `json:"user,omitempty"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
FlushDelay string `json:"flush_delay,omitempty"`
|
FlushDelay string `json:"flush_delay,omitempty"`
|
||||||
|
NkeyFile string `json:"nkey_file,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NatsSink struct {
|
type NatsSink struct {
|
||||||
@@ -42,6 +44,13 @@ func (s *NatsSink) connect() error {
|
|||||||
var nc *nats.Conn
|
var nc *nats.Conn
|
||||||
if len(s.config.User) > 0 && len(s.config.Password) > 0 {
|
if len(s.config.User) > 0 && len(s.config.Password) > 0 {
|
||||||
uinfo = nats.UserInfo(s.config.User, s.config.Password)
|
uinfo = nats.UserInfo(s.config.User, s.config.Password)
|
||||||
|
} else if len(s.config.NkeyFile) > 0 {
|
||||||
|
if _, err := os.Stat(s.config.NkeyFile); err == nil {
|
||||||
|
uinfo = nats.UserCredentials(s.config.NkeyFile)
|
||||||
|
} else {
|
||||||
|
cclog.ComponentError(s.name, "NKEY file", s.config.NkeyFile, "does not exist: %v", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
uri := fmt.Sprintf("nats://%s:%s", s.config.Host, s.config.Port)
|
uri := fmt.Sprintf("nats://%s:%s", s.config.Host, s.config.Port)
|
||||||
cclog.ComponentDebug(s.name, "Connect to", uri)
|
cclog.ComponentDebug(s.name, "Connect to", uri)
|
||||||
|
@@ -13,6 +13,7 @@ The `nats` sink publishes all metrics into a NATS network. The publishing key is
|
|||||||
"port": "4222",
|
"port": "4222",
|
||||||
"user": "exampleuser",
|
"user": "exampleuser",
|
||||||
"password" : "examplepw",
|
"password" : "examplepw",
|
||||||
|
"nkey_file": "/path/to/nkey_file",
|
||||||
"meta_as_tags" : [],
|
"meta_as_tags" : [],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,3 +26,4 @@ The `nats` sink publishes all metrics into a NATS network. The publishing key is
|
|||||||
- `user`: Username for basic authentication
|
- `user`: Username for basic authentication
|
||||||
- `password`: Password for basic authentication
|
- `password`: Password for basic authentication
|
||||||
- `meta_as_tags`: print all meta information as tags in the output (optional)
|
- `meta_as_tags`: print all meta information as tags in the output (optional)
|
||||||
|
- `nkey_file`: Path to credentials file with NKEY
|
||||||
|
Reference in New Issue
Block a user