Skip to content

Commit

Permalink
Merge pull request #34 from CapillarySoftware/add_docs
Browse files Browse the repository at this point in the history
add docs
  • Loading branch information
vrecan committed Jul 15, 2014
2 parents f4884bd + d857078 commit 60a91c9
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package diskStat

//diskStat parse raw disk stats from a string.
import (
"errors"
"strconv"
Expand Down
22 changes: 13 additions & 9 deletions src/github.com/CapillarySoftware/goiostat/goiostat.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package main

//main goiostat application that allows you to send send extended iostat info
//over zmq using protobuffers or json.

import (
"bufio"
"flag"
Expand All @@ -8,17 +11,15 @@ import (
"github.com/CapillarySoftware/goiostat/ioStatTransform"
"github.com/CapillarySoftware/goiostat/logOutput"
"github.com/CapillarySoftware/goiostat/outputInterface"
. "github.com/CapillarySoftware/goiostat/protocols"
"github.com/CapillarySoftware/goiostat/statsOutput"
"github.com/CapillarySoftware/goiostat/zmqOutput"
. "github.com/CapillarySoftware/goiostat/protocols"
"log"
"os"
"strings"
"time"
)



/**
Go version of iostat, pull stats from proc and optionally log or send to a zeroMQ
*/
Expand Down Expand Up @@ -50,16 +51,19 @@ func main() {
proto := PStdOut

switch *protocolType {
case "protobuffers": {
case "protobuffers":
{
proto = PProtoBuffers
}
case "json" : {
case "json":
{
proto = PJson
}
default: {
if(*outputType == "zmq") {
proto = PProtoBuffers
}else if(*outputType == "stdout") {
default:
{
if *outputType == "zmq" {
proto = PProtoBuffers
} else if *outputType == "stdout" {
proto = PStdOut
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var partition = regexp.MustCompile(`\w.*\d`)

const oneSecondInMilli = 1000

//DiskStatDiff struct for all extended io stats storing just the difference between
//the current and the last.
type DiskStatDiff struct {
Id int64
PartId int64
Expand All @@ -33,6 +35,7 @@ type DiskStatDiff struct {
SectorsTotalRaw float64
}

//TransformStat goroutine function to transform the stats and send to the stats output channel.
func TransformStat(channel <-chan *diskStat.DiskStat, statsOutputChannel chan *diskStat.ExtendedIoStats) (err error) {
for {
stat := <-channel
Expand Down Expand Up @@ -164,6 +167,7 @@ func getDiffDiskStat(old *diskStat.DiskStat, cur *diskStat.DiskStat) (r DiskStat
return
}

//getDiff gets old and current stat.
func getDiff(old int64, cur int64) (r float64, err error) {
if old > cur {
err = errors.New("Old is newer then current... impressive!")
Expand All @@ -173,6 +177,7 @@ func getDiff(old int64, cur int64) (r float64, err error) {
return
}

//getDiffUint64 gets old and current stat.
func getDiffUint64(old uint64, cur uint64) (r float64, err error) {
if old > cur {
err = errors.New("Old is newer then current... impressive!")
Expand All @@ -182,6 +187,7 @@ func getDiffUint64(old uint64, cur uint64) (r float64, err error) {
return
}

//getAvgRequestSize get the avg request size for a disk.
func getAvgRequestSize(diffSectorsTotalRaw float64, diffIoTotal float64) (r float64) {
if diffIoTotal <= 0 {
r = 0.00
Expand All @@ -191,14 +197,13 @@ func getAvgRequestSize(diffSectorsTotalRaw float64, diffIoTotal float64) (r floa
return
}

//getAvgQueueSize get the avg queue size for a disk.
func getAvgQueueSize(diffWeightedMillisDoingIo float64, time float64) (r float64) {
r = diffWeightedMillisDoingIo / time
return
}

// xds->await = (sdc->nr_ios - sdp->nr_ios) ?
// ((sdc->rd_ticks - sdp->rd_ticks) + (sdc->wr_ticks - sdp->wr_ticks)) /
// ((double) (sdc->nr_ios - sdp->nr_ios)) : 0.0;
//getAwait get average wait time for a disk.
func getAwait(diffMillisWriting float64, diffMillisReading float64, diffIoTotal float64) (r float64) {
if diffIoTotal <= 0 {
r = 0.00
Expand All @@ -210,6 +215,7 @@ func getAwait(diffMillisWriting float64, diffMillisReading float64, diffIoTotal

}

//getSingleAwait get single await time used for parsing read or write await times
func getSingleAwait(diffIo float64, diffMillis float64) (r float64) {
if diffIo <= 0 {
r = 0.00
Expand All @@ -219,6 +225,7 @@ func getSingleAwait(diffIo float64, diffMillis float64) (r float64) {
return
}

//getAvgServiceTime get the avg service time for a disk.
func getAvgServiceTime(diffIoTotal float64, time float64, util float64) (r float64) {
hz := systemCall.GetClockTicksPerSecond()
tput := diffIoTotal * float64(hz) / time
Expand All @@ -231,6 +238,7 @@ func getAvgServiceTime(diffIoTotal float64, time float64, util float64) (r float
return
}

//getUtilization get a single disks utilization percentage
func getUtilization(diffMillisDoingIo float64, time float64) (r float64) {
r = (float64(diffMillisDoingIo) / (time * 100) * 10.0) * oneSecondInMilli
if r > 100.00 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package logOutput

//logOutput Simple logout package to manage outputing info to stdout.

import (
"encoding/json"
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package outputInterface

//outputInterface simple interface to allow you to send stats using
//multiple interfaces.

import (
"github.com/CapillarySoftware/goiostat/diskStat"
// "errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package protoStat

//protoStat Package built to manage protobuffer stats messages.

import (
"bytes"
"errors"
. "github.com/CapillarySoftware/goiostat/diskStat"
"reflect"
// "fmt"
)

//GetProtoStats get a slice of protostats from extendedIOStats.
func GetProtoStats(eStat *ExtendedIoStats) (stats []ProtoStat, err error) {

deviceName := eStat.Device
Expand Down Expand Up @@ -39,4 +41,4 @@ func GetProtoStats(eStat *ExtendedIoStats) (stats []ProtoStat, err error) {
}
}
return
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package protocols

// protocols is an enum of possible protocols to use.

type Protocol int

const (
PStdOut Protocol = 0
PStdOut Protocol = 0
PProtoBuffers Protocol = 1
PJson Protocol = 2
)
PJson Protocol = 2
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package statsOutput

//statsOutput is a simple goroutine that uses the output interface and
//sends the stat to the interface given.

import (
"fmt"
"github.com/CapillarySoftware/goiostat/diskStat"
"github.com/CapillarySoftware/goiostat/outputInterface"
)

//Output takes an input channel and sends the data to the output interface.
func Output(channel <-chan *diskStat.ExtendedIoStats, output outputInterface.Output) {
for {
stat := <-channel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package zmqOutput

//zmqOutput Package that allows you to send stats over zeromq.

import (
"code.google.com/p/goprotobuf/proto"
"encoding/json"
Expand Down

0 comments on commit 60a91c9

Please sign in to comment.