-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from cha87de/profiler
Integrate Profiler into Master
- Loading branch information
Showing
24 changed files
with
526 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_builder/do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
FROM alpine:latest | ||
RUN apk update | ||
RUN apk add libvirt-client ncurses5-libs | ||
RUN apk add libvirt-client ncurses5-libs git gettext curl bash make | ||
RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 | ||
RUN ln -s /usr/lib/libncurses.so.5 /usr/lib/libtinfo.so.5 | ||
ADD kvmtop /bin/kvmtop | ||
CMD [ "/bin/kvmtop" ] | ||
|
||
# use bpkg to handle complex bash entrypoints | ||
RUN curl -Lo- "https://raw.githubusercontent.com/bpkg/bpkg/master/setup.sh" | bash | ||
RUN bpkg install cha87de/bashutil -g | ||
|
||
# copy entrypoint | ||
RUN mkdir -p /opt/docker-init | ||
ADD init /opt/docker-init | ||
|
||
# add kvmtop binaries | ||
ADD dist/linux_amd64/kvmtop /bin/kvmtop | ||
ADD dist/linux_amd64/kvmprofiler /bin/kvmprofiler | ||
|
||
# set parameters | ||
ENV PARAMS "-c qemu:///system --printer=text --cpu --mem --net --disk" | ||
ENV PROFILER_PARAMS "--states 4 --history 1 --filterstddevs 12 --outputFreq 20" | ||
|
||
# start from init folder | ||
WORKDIR /opt/docker-init | ||
ENTRYPOINT ["./entrypoint"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/cha87de/kvmtop/collectors/cpucollector" | ||
"github.com/cha87de/kvmtop/collectors/iocollector" | ||
"github.com/cha87de/kvmtop/collectors/netcollector" | ||
"github.com/cha87de/kvmtop/config" | ||
"github.com/cha87de/kvmtop/models" | ||
flags "github.com/jessevdk/go-flags" | ||
) | ||
|
||
func initializeFlags() { | ||
// initialize parser for flags | ||
parser := flags.NewParser(&config.Options, flags.Default) | ||
parser.ShortDescription = "kvmprofiler" | ||
parser.LongDescription = "Compute statistical profiles from monitoring data of virtual machines via kvmtop" | ||
|
||
// Parse parameters | ||
if _, err := parser.Parse(); err != nil { | ||
code := 1 | ||
if fe, ok := err.(*flags.Error); ok { | ||
if fe.Type == flags.ErrHelp { | ||
code = 0 | ||
} | ||
} | ||
if code != 0 { | ||
fmt.Printf("Error parsing flags: %s\n", err) | ||
} | ||
os.Exit(code) | ||
} | ||
|
||
// Set collectors from flags | ||
if config.Options.EnableCPU { | ||
collector := cpucollector.CreateCollector() | ||
models.Collection.Collectors.Store("cpu", &collector) | ||
} | ||
if config.Options.EnableMEM { | ||
fmt.Println("memory profiling not supported.") | ||
} | ||
if config.Options.EnableDISK { | ||
fmt.Println("disk profiling not supported.") | ||
} | ||
if config.Options.EnableNET { | ||
collector := netcollector.CreateCollector() | ||
models.Collection.Collectors.Store("net", &collector) | ||
} | ||
if config.Options.EnableIO { | ||
collector := iocollector.CreateCollector() | ||
models.Collection.Collectors.Store("io", &collector) | ||
} | ||
if config.Options.EnableHost { | ||
fmt.Println("host profiling not supported.") | ||
} | ||
|
||
// Parse periodsize csv string | ||
periodSizeStr := strings.Split(config.Options.Profiler.PeriodSize, ",") | ||
periodSize := make([]int, 0) | ||
for _, s := range periodSizeStr { | ||
if s == "" { | ||
continue | ||
} | ||
si, _ := strconv.Atoi(s) | ||
periodSize = append(periodSize, si) | ||
} | ||
config.Options.Profiler.PeriodSizeParsed = periodSize | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"sync" | ||
|
||
"github.com/cha87de/kvmtop/config" | ||
"github.com/cha87de/kvmtop/connector" | ||
"github.com/cha87de/kvmtop/models" | ||
"github.com/cha87de/kvmtop/profiler" | ||
"github.com/cha87de/kvmtop/runners" | ||
) | ||
|
||
func main() { | ||
|
||
// handle flags | ||
initializeFlags() | ||
|
||
// connect to libvirt | ||
connector.Libvirt.ConnectionURI = config.Options.LibvirtURI | ||
err := connector.InitializeConnection() | ||
if err != nil { | ||
fmt.Println("failed to initialize connection to libvirt. kvmprofile will terminate.") | ||
os.Exit(1) | ||
} | ||
|
||
// initialize host measureable | ||
models.Collection.Host = &models.Host{ | ||
Measurable: &models.Measurable{}, | ||
} | ||
|
||
// start lookup and collect runners | ||
var wg sync.WaitGroup | ||
wg.Add(1) // terminate when first thread terminates | ||
go runners.InitializeLookup(&wg) | ||
go runners.InitializeCollect(&wg) | ||
go profiler.InitializeProfiler(&wg) | ||
wg.Wait() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package config | ||
|
||
import "time" | ||
|
||
// ProfilerOptionsType describes profiler options | ||
type ProfilerOptionsType struct { | ||
States int `long:"states" default:"4"` | ||
BufferSize int `long:"buffersize" default:"10"` | ||
History int `long:"history" default:"1"` | ||
FilterStdDevs int `long:"filterstddevs" default:"-1"` | ||
FixedBound bool `long:"fixedbound"` | ||
PeriodSize string `long:"periodsize" default:"" description:"comma separated list of ints, specifies descrete states per period"` | ||
OutputFreq time.Duration `long:"outputFreq" default:"60"` | ||
|
||
PeriodSizeParsed []int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
|
||
# include bpkg dependencies | ||
source /usr/local/bin/retry | ||
source /usr/local/bin/bgo | ||
source /usr/local/bin/bgowait | ||
|
||
############################################################################## | ||
function start_metrics(){ | ||
kvmtop $PARAMS | ||
} | ||
function start_profiler(){ | ||
kvmprofiler $PARAMS $PROFILER_PARAMS | ||
} | ||
function start(){ | ||
echo "starting applications..." | ||
bgo start_metrics start_profiler | ||
if [[ $? != 0 ]]; then | ||
echo "start failed. exiting now." >&2 | ||
exit 1 | ||
fi | ||
} | ||
|
||
############################################################################## | ||
function main(){ | ||
# start | ||
start | ||
if [[ $? != 0 ]]; then | ||
echo "start failed. exiting now." >&2 | ||
exit 1 | ||
fi | ||
|
||
# wait | ||
echo "done. now waiting for services." | ||
#freq=5; waitForN=-1; killTasks=0 # fail one, ignore (development mode) | ||
freq=5; waitForN=1; killTasks=1 #fail one, fail all (production mode) | ||
bgowait $freq $waitForN $killTasks | ||
} | ||
|
||
if [[ "$1" == "" ]]; then | ||
main | ||
else | ||
exec "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Profiler for virtual machine monitoring kvmtop | ||
After=libvirtd.service | ||
|
||
[Service] | ||
Type=simple | ||
Restart=always | ||
RestartSec=3 | ||
EnvironmentFile=/etc/kvmtop.conf | ||
ExecStart=/usr/bin/kvmprofiler --printer=json --output=tcp --target=${KVMTOP_TARGET} --cpu --net --mem --io --disk --host --verbose ${KVMPROFILER_PARAMS} | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
KVMTOP_TARGET=192.168.50.230:12345 | ||
KVMTOP_TARGET=192.168.50.230:12345 | ||
KVMPROFILER_PARAMS="--states 4 --history 1 --filterstddevs 256 --outputFreq 60s --buffersize 10" |
Oops, something went wrong.