Commit 6f45c0de authored by Azat Khuziyakhmetov's avatar Azat Khuziyakhmetov
Browse files

reformatted pfit-uprocstat and created Dockerfile for the testing container.

parent 411f19d3
......@@ -2,11 +2,11 @@ package pfituprocstat
import (
"fmt"
"os/exec"
"regexp"
"strconv"
"strings"
"time"
"os/exec"
"regexp"
"strings"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
......@@ -165,46 +165,46 @@ func (p *Procstat) addMetrics(proc Process, acc telegraf.Accumulator) {
fields[prefix+"memory_swap"] = mem.Swap
}
uids, err := proc.Uids()
uids, err := proc.Uids()
if err == nil {
proc.Tags()["uid"] = strconv.FormatInt(int64(uids[0]), 10)
}
// Add batch job id's from /proc/<PID>/environ
// Environment variables containing the job id's in case of
// SLURM: SLURM_JOBID,
// Moab/Torque: MOAB_JOBID/PBS_JOBID,
// Add batch job id's from /proc/<PID>/environ
// Environment variables containing the job id's in case of
// SLURM: SLURM_JOBID,
// Moab/Torque: MOAB_JOBID/PBS_JOBID,
// LSF: LSB_JOBID
pid := proc.PID()
pidenviron := "/proc/" + strconv.Itoa(int(pid)) + "/environ"
pid := proc.PID()
pidenviron := "/proc/" + strconv.Itoa(int(pid)) + "/environ"
// ToDo: maybe better use Go functions instead of calling "strings"
stringsCmd := exec.Command("strings", pidenviron)
stringsOut, _ := stringsCmd.Output()
// ToDo: maybe better use Go functions instead of calling "strings"
stringsCmd := exec.Command("strings", pidenviron)
stringsOut, _ := stringsCmd.Output()
jobid_pat := regexp.MustCompile(".*JOBID=.*")
jobid_varexpr := jobid_pat.FindAllString(string(stringsOut), -1)
jobid_pat := regexp.MustCompile(".*JOBID=.*")
jobid_varexpr := jobid_pat.FindAllString(string(stringsOut), -1)
if len(jobid_varexpr) > 0 {
for i,_ := range jobid_varexpr {
jobid_slice := strings.Split(jobid_varexpr[i], "=")
if jobid_slice[0] == "MOAB_JOBID" {
jobid1 := jobid_slice[1]
proc.Tags()["jobid1"] = jobid1
for i, _ := range jobid_varexpr {
jobid_slice := strings.Split(jobid_varexpr[i], "=")
if jobid_slice[0] == "MOAB_JOBID" {
jobid1 := jobid_slice[1]
proc.Tags()["jobid1"] = jobid1
} else if jobid_slice[0] == "PBS_JOBID" {
jobid2 := jobid_slice[1]
proc.Tags()["jobid2"] = jobid2
jobid2 := jobid_slice[1]
proc.Tags()["jobid2"] = jobid2
} else if jobid_slice[0] == "SLURM_JOBID" {
jobid := jobid_slice[1]
proc.Tags()["jobid1"] = jobid
proc.Tags()["jobid2"] = jobid
jobid := jobid_slice[1]
proc.Tags()["jobid1"] = jobid
proc.Tags()["jobid2"] = jobid
} else if jobid_slice[0] == "LSB_JOBID" {
jobid := jobid_slice[1]
proc.Tags()["jobid1"] = jobid
proc.Tags()["jobid2"] = jobid
jobid := jobid_slice[1]
proc.Tags()["jobid1"] = jobid
proc.Tags()["jobid2"] = jobid
}
}
}
}
}
acc.AddFields("pfit-uprocstat", fields, proc.Tags())
}
......@@ -282,7 +282,7 @@ func (p *Procstat) findPids() ([]PID, map[string]string, error) {
} else if p.User != "" {
pids, err = f.Uid(p.User)
tags = map[string]string{"user": p.User}
} else if p.StartFrom >=0 {
} else if p.StartFrom >= 0 {
pids, err = f.FindAll(p.IgnoreUsers, p.StartFrom)
tags = map[string]string{}
} else {
......
# Testing the plugins with Docker container
Build the container from the root of this repository:
```
docker build -t pfit-telegraf-plugins-test -f test/docker/Dockerfile .
```
Run the container to get the output of the plugins:
```
docker run pfit-telegraf-plugins-test
```
from ubuntu:latest
# Installing packages for Go and others
RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
gcc \
libc6-dev \
make \
pkg-config \
wget ca-certificates \
git-core \
vim-tiny \
&& rm -rf /var/lib/apt/lists/*
# Installing Go
ENV GOLANG_VERSION 1.11.2
RUN goRelArch='linux-amd64'; goRelSha256='1dfe664fa3d8ad714bbd15a36627992effd150ddabd7523931f077b3926d736d' \
url="https://golang.org/dl/go${GOLANG_VERSION}.${goRelArch}.tar.gz"; \
wget -O go.tgz "$url"; \
echo "${goRelSha256} *go.tgz" | sha256sum -c -; \
tar -C /usr/local -xzf go.tgz; \
rm go.tgz; \
export PATH="/usr/local/go/bin:$PATH"; \
go version;
ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
# Installing dep
RUN go get -d -u github.com/golang/dep; \
depv=v0.5.0; \
cd $GOPATH/src/github.com/golang/dep; \
git checkout tags/$depv; \
go install -ldflags="-X main.version=$depv" ./cmd/dep;
# Installing Telegraf
RUN go get -d github.com/influxdata/telegraf; \
cd "$GOPATH/src/github.com/influxdata/telegraf"; \
tlgrfv=1.8.3; \
git checkout tags/$tlgrfv; \
make && make go-install
##### INSTALLING PROFIT-HPC PLUGINS AND TEST
# Copying files into the container
COPY pfit-uprocstat/ \
$GOPATH/src/github.com/influxdata/telegraf/plugins/inputs/pfit-uprocstat
# Importing the plugin and compiling telegraf
RUN sed -ie '/^import (/a _ "github.com/influxdata/telegraf/plugins/inputs/pfit-uprocstat"' \
$GOPATH/src/github.com/influxdata/telegraf/plugins/inputs/all/all.go && \
cd $GOPATH/src/github.com/influxdata/telegraf && \
make && make go-install
COPY test/docker/telegraf.conf /root/.telegraf/telegraf.conf
COPY pfit-nodeinfo.sh /root/pfit-nodeinfo.sh
WORKDIR /root
CMD telegraf --test
[[inputs.pfit-uprocstat]]
## Must specify one of: pid_file, exe, or pattern
## PID file to monitor process
# pid_file = "/var/run/nginx.pid"
## executable name (ie, pgrep <exe>)
# exe = "nginx"
## pattern as argument for pgrep (ie, pgrep -f <pattern>)
# pattern = "nginx"
## user as argument for pgrep (ie, pgrep -u <user>)
# user = "nginx"
## override for process_name
## This is optional; default is sourced from /proc/<pid>/status
# process_name = "bar"
## Field name prefix
# prefix = ""
## comment this out if you want raw cpu_time stats
# fielddrop = ["cpu_time_*"]
## This is optional; moves pid into a tag instead of a field
# pid_tag = false
## If none of monitoring options is selected. Then we monitor all processes.
## the lowest process UID to be monitored
start_from = 0
## the list of users to be ignored
#ignore_users = ["influxdb"]
[[inputs.exec]]
## Commands array
commands = [
"/root/pfit-nodeinfo.sh"
]
## Timeout for each command to complete.
timeout = "5s"
## measurement name suffix (for separating different commands)
name_suffix = "_mycollector"
## Data format to consume.
## Each data format has its own unique set of configuration options, read
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
data_format = "influx"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment