-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
560 additions
and
194 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
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,90 @@ | ||
package gohalt | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
type strbool bool | ||
|
||
func (b strbool) String() string { | ||
return fmt.Sprintf("%t", bool(b)) | ||
} | ||
|
||
type strpair struct { | ||
current uint64 | ||
threshold uint64 | ||
} | ||
|
||
func (p strpair) String() string { | ||
return fmt.Sprintf("%d out of %d", p.current, p.threshold) | ||
} | ||
|
||
type strpercent float64 | ||
|
||
func (p strpercent) String() string { | ||
return fmt.Sprintf("%.4f%%", float64(p)*100) | ||
} | ||
|
||
type strdurations struct { | ||
current time.Duration | ||
threshold time.Duration | ||
} | ||
|
||
func (d strdurations) String() string { | ||
return fmt.Sprintf("%s out of %s", d.current, d.threshold) | ||
} | ||
|
||
type strstats struct { | ||
current Stats | ||
threshold Stats | ||
} | ||
|
||
func (s strstats) String() string { | ||
return fmt.Sprintf( | ||
` | ||
%d out of %d bytes | ||
%d out of %d bytes | ||
%d out of %d ns | ||
%.4f out of %.4f %% | ||
`, | ||
s.current.MEMAlloc, | ||
s.threshold.MEMAlloc, | ||
s.current.MEMSystem, | ||
s.threshold.MEMSystem, | ||
s.current.CPUPause, | ||
s.threshold.CPUPause, | ||
s.current.CPUUsage*100, | ||
s.threshold.CPUUsage*100, | ||
) | ||
} | ||
|
||
// ErrorThreshold defines error type | ||
// that occurs if throttler reaches specified threshold. | ||
type ErrorThreshold struct { | ||
Throttler string | ||
Threshold fmt.Stringer | ||
} | ||
|
||
func (err ErrorThreshold) Error() string { | ||
return fmt.Sprintf( | ||
"throttler %q has reached its threshold: %s", | ||
err.Throttler, | ||
err.Threshold, | ||
) | ||
} | ||
|
||
// ErrorInternal defines error type | ||
// that occurs if throttler internal error happens. | ||
type ErrorInternal struct { | ||
Throttler string | ||
Message string | ||
} | ||
|
||
func (err ErrorInternal) Error() string { | ||
return fmt.Sprintf( | ||
"throttler %q internal error happened: %s", | ||
err.Throttler, | ||
err.Message, | ||
) | ||
} |
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
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
Oops, something went wrong.