本文整理匯總了Golang中github.com/mperham/inspeqtor/util.Debug函數的典型用法代碼示例。如果您正苦於以下問題:Golang Debug函數的具體用法?Golang Debug怎麽用?Golang Debug使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Debug函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: detectInitd
func detectInitd(root string) (InitSystem, error) {
ctlpath := root + "etc/init.d/"
result, err := util.FileExists(ctlpath)
if err != nil {
return nil, err
}
if !result {
util.Debug("init.d not detected in " + ctlpath)
return nil, nil
}
matches, err := filepath.Glob(ctlpath + "*")
if err != nil {
return nil, err
}
if !result {
util.Debug("init.d not detected in " + ctlpath)
return nil, nil
}
if len(matches) > 0 {
util.Info("Detected init.d in " + ctlpath)
return &Initd{ctlpath, root + "var/run/", pidForString}, nil
}
util.Info(ctlpath + " exists but appears to be empty")
return nil, nil
}
示例2: capturePs
/*
* So many hacks in this. OSX support can be seen as "bad" at best.
*/
func (ps *processStorage) capturePs(pid int) error {
cmd := exec.Command("ps", "So", "rss,time,utime", "-p", strconv.Itoa(pid))
sout, err := util.SafeRun(cmd)
if err != nil {
return err
}
lines, err := util.ReadLines(sout)
if err != nil {
return err
}
if len(lines) < 2 {
return errors.New("Insufficient output from ps")
}
fields := strings.Fields(lines[1])
val, err := strconv.ParseInt(fields[0], 10, 64)
if err != nil {
return err
}
ps.Save("memory", "rss", float64(1024*val))
times := timeRegexp.FindStringSubmatch(fields[1])
if times == nil {
util.Debug("Unable to parse CPU time in " + lines[1])
return nil
}
min, _ := strconv.ParseUint(times[1], 10, 32)
sec, _ := strconv.ParseUint(times[2], 10, 32)
cs, _ := strconv.ParseUint(times[3], 10, 32)
ticks := min*60*100 + sec*100 + cs
times = timeRegexp.FindStringSubmatch(fields[2])
if times == nil {
util.Debug("Unable to parse User time in " + lines[1])
return nil
}
min, _ = strconv.ParseUint(times[1], 10, 32)
sec, _ = strconv.ParseUint(times[2], 10, 32)
cs, _ = strconv.ParseUint(times[3], 10, 32)
uticks := min*60*100 + sec*100 + cs
ps.Save("cpu", "user", float64(uticks))
ps.Save("cpu", "system", float64(ticks-uticks))
return nil
}
示例3: collectDisk
func (hs *hostStorage) collectDisk(path string) error {
var lines []string
if path == "" {
cmd := exec.Command("df", "-P")
sout, err := util.SafeRun(cmd)
if err != nil {
return err
}
lines, err = util.ReadLines(sout)
if err != nil {
return err
}
} else {
data, err := ioutil.ReadFile(path)
if err != nil {
return err
}
lines, err = util.ReadLines(data)
if err != nil {
return err
}
}
usage := map[string]float64{}
for _, line := range lines {
if line[0] == '/' {
items := strings.Fields(line)
if len(items) < 5 {
util.Debug("Cannot parse df output: %v", items)
continue
}
pct := items[4]
if pct[len(pct)-1] == '%' {
val, err := strconv.ParseInt(pct[0:len(pct)-1], 10, 32)
if err != nil {
util.Debug("Cannot parse df output: " + line)
}
usage[items[len(items)-1]] = float64(val)
}
}
}
for name, used := range usage {
hs.saveType("disk", name, used, Gauge)
}
return nil
}
示例4: LookupService
func (l *Launchd) LookupService(serviceName string) (*ProcessStatus, error) {
cmd := exec.Command("launchctl", "list")
sout, err := util.SafeRun(cmd)
if err != nil {
return nil, &ServiceError{l.Name(), serviceName, err}
}
lines, err := util.ReadLines(sout)
if err != nil {
return nil, &ServiceError{l.Name(), serviceName, err}
}
for _, line := range lines {
if strings.Contains(line, serviceName) {
util.Debug("launchctl found " + serviceName)
parts := strings.SplitN(line, "\t", 3)
pid, err := strconv.ParseInt(parts[0], 10, 32)
if err != nil {
return nil, &ServiceError{l.Name(), serviceName, err}
}
return &ProcessStatus{int(pid), Up}, nil
}
}
path := l.resolvePlist(serviceName)
if path != "" {
return &ProcessStatus{0, Down}, nil
}
return nil, &ServiceError{l.Name(), serviceName, ErrServiceNotFound}
}
示例5: Resolve
/*
Resolve each defined service to its managing init system. Called only
at startup, this is what maps services to init and fires ProcessDoesNotExist events.
*/
func (svc *Service) Resolve(mgrs []services.InitSystem) error {
for _, sm := range mgrs {
// TODO There's a bizarre race condition here. Figure out
// why this is necessary. We shouldn't be multi-threaded yet.
if sm == nil {
continue
}
ps, err := sm.LookupService(svc.Name())
if err != nil {
serr := err.(*services.ServiceError)
if serr.Err == services.ErrServiceNotFound {
util.Debug(sm.Name() + " doesn't have " + svc.Name())
continue
}
return err
}
util.Info("Found %s/%s with status %s", sm.Name(), svc.Name(), ps)
svc.Manager = sm
svc.Transition(ps, func(et EventType) {
counters.Add("events", 1)
err = svc.EventHandler.Trigger(&Event{et, svc, nil})
if err != nil {
util.Warn("Error firing event: %s", err.Error())
}
})
break
}
if svc.Manager == nil {
return fmt.Errorf("Could not find service %s, did you misspell it?", svc.Name())
}
return nil
}
示例6: AddSource
func (ps *processStorage) AddSource(name string, config map[string]string) (Source, error) {
for _, x := range ps.daemonSpecific {
if x.Name() == name {
return x, nil
}
}
builder := Sources[name]
if builder == nil {
return nil, nil
}
util.Info("Activating metrics for %s", name)
src, err := builder(config)
if err != nil {
return nil, err
}
m, ok := src.(MandatorySource)
if ok && m.Mandatory() {
util.Debug("Registering all metrics for %s", name)
descs := src.ValidMetrics()
for _, d := range descs {
if d.MetricType == Counter {
ps.DeclareCounter(name, d.Name, nil, d.Display)
} else {
ps.DeclareGauge(name, d.Name, d.Display)
}
}
}
ps.daemonSpecific = append(ps.daemonSpecific, src)
return src, nil
}
示例7: sendSlackAlert
func sendSlackAlert(url string, params url.Values) error {
util.Debug("Sending slack alert to %s", url)
resp, err := http.PostForm(url, params)
if resp != nil {
resp.Body.Close()
}
return err
}
示例8: triggeredHandler
func triggeredHandler(rule *Rule, tripped bool) *Event {
if !tripped {
util.Info("%s[%s] recovered.", rule.EntityName(), rule.Metric())
rule.State = Recovered
return nil
}
util.Debug("%s[%s] still triggered. Current: %.1f, Threshold: %.1f", rule.EntityName(), rule.Metric(), rule.CurrentValue, rule.Threshold)
return nil
}
示例9: defaultClient
func defaultClient(host string, port string, ep string) ([]byte, error) {
url := fmt.Sprintf("http://%s:%s%s", host, port, ep)
util.Debug("Fetching nginx status from %s", url)
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
}
示例10: okHandler
func okHandler(rule *Rule, tripped bool) *Event {
if tripped && rule.TrippedCount == rule.CycleCount {
util.Warn("%s[%s] triggered. Current value = %.1f", rule.EntityName(), rule.Metric(), rule.CurrentValue)
rule.State = Triggered
return &Event{RuleFailed, rule.Entity, rule}
}
if tripped {
util.Debug("%s[%s] tripped. Current: %.1f, Threshold: %.1f", rule.EntityName(), rule.Metric(), rule.CurrentValue, rule.Threshold)
}
return nil
}
示例11: Start
func (i *Inspeqtor) Start() {
util.Debug("Starting command socket")
err := i.openSocket(i.SocketPath)
if err != nil {
util.Warn("Could not create Unix socket: %s", err.Error())
exit(i)
}
go func() {
for {
if !i.safelyAccept() {
util.Debug("Shutting down command socket")
return
}
}
}()
// if expose_port is 0, disable the feature altogether
if i.GlobalConfig.ExposePort != 0 {
sock, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", i.GlobalConfig.ExposePort))
if err != nil {
util.Warn("Could not listen on port %d: %s", i.GlobalConfig.ExposePort, err.Error())
exit(i)
}
i.Expose = sock
go func() {
// TODO How do we error handling here?
util.Info("Expose now available at port %d", i.GlobalConfig.ExposePort)
err := http.Serve(i.Expose, nil)
// Don't log an "error" when we shut down normally and close the socket
if err != nil && !strings.Contains(err.Error(), "use of closed network") {
util.Warn("HTTP server error: %s", err.Error())
}
}()
}
util.Debug("Starting main run loop")
go i.runLoop()
Singleton = i
}
示例12: Reload
func (svc *Service) Reload() error {
go func() {
util.Debug("Reloading %s", svc.Name())
err := svc.Manager.Reload(svc.Name())
if err != nil {
util.Warn(err.Error())
} else {
util.DebugDebug("Reloaded %s", svc.Name())
}
}()
return nil
}
示例13: Watch
func Watch(i *inspeqtor.Inspeqtor, jobs map[string]*Job) {
util.Debug("Starting recurring job watcher")
go func() {
for {
untilNext := check(jobs)
select {
case <-i.Stopping:
// reloading inspeqtor
util.Debug("Shutting down recurring job watcher")
return
case <-runNotifier:
// we just got notified a job ran,
// verify we don't need to fire JobRan
case <-time.After(untilNext + time.Minute):
// a job is due at this point in time.
// add an extra minute to allow for race conditions
// and slow performance
}
}
}()
}
示例14: HandleSignals
func HandleSignals() {
signals := make(chan os.Signal)
for k := range SignalHandlers {
signal.Notify(signals, k)
}
for {
sig := <-signals
util.Debug("Received signal %d", sig)
funk := SignalHandlers[sig]
funk(Singleton)
}
}
示例15: parseJobs
func parseJobs(global *inspeqtor.ConfigFile, confDir string) (map[string]*Job, error) {
util.Debug("Parsing jobs in " + confDir)
files, err := filepath.Glob(confDir + "/jobs.d/*.inq")
if err != nil {
return nil, err
}
jobs := map[string]*Job{}
for _, filename := range files {
util.DebugDebug("Parsing " + filename)
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
s := lexer.NewLexer([]byte(data))
p := parser.NewParser()
obj, err := p.Parse(s)
if err != nil {
util.Warn("Unable to parse " + filename + ": " + err.Error())
continue
}
astcontent := obj.(*ast.Content)
for _, astjob := range astcontent.Jobs {
if _, ok := jobs[astjob.Name]; ok {
return nil, fmt.Errorf("Duplicate job %s", astjob.Name)
}
j := New(astjob.Name, astjob.Interval, astcontent.Parameters)
owner := j.Parameters["owner"]
route := global.AlertRoutes[owner]
if owner == "" && route == nil {
return nil, fmt.Errorf("No default alert route configured!")
}
if route == nil {
return nil, fmt.Errorf("No such alert route: %s", owner)
}
alert, err := inspeqtor.Actions["alert"](j, route)
if err != nil {
return nil, err
}
j.alerter = alert
jobs[astjob.Name] = j
}
}
return jobs, nil
}