本文整理匯總了Golang中Logger.Logger.Log方法的典型用法代碼示例。如果您正苦於以下問題:Golang Logger.Log方法的具體用法?Golang Logger.Log怎麽用?Golang Logger.Log使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Logger.Logger
的用法示例。
在下文中一共展示了Logger.Log方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: readUnixSocket
func readUnixSocket(path string, log *logger.Logger) interface{} {
fi, err := os.Stat(path)
if err != nil && os.IsNotExist(err) {
log.Log("crit", "Could not locate unix socket for json_poll at path: "+path)
return nil
}
if fi.Mode()&os.ModeSocket != os.ModeSocket {
log.Log("crit", path+" is not a unix socket for json_poll")
return nil
}
client := &http.Client{
Transport: &http.Transport{
Dial: func(network, addr string) (net.Conn, error) {
return net.Dial("unix", path)
},
},
}
req, _ := http.NewRequest("GET", "http://localhost", nil)
req.Close = true
return doRequest(req, client, log)
}
示例2: GetMetric
func GetMetric(params interface{}, log *logger.Logger) interface{} {
difference := make(map[string]uint64)
device := params.(string)
device_type := getDeviceType(device)
new_metrics := initLastMetrics(device)
metrics, err := getDiskMetrics(device, device_type)
if new_metrics {
log.Log("debug", "New metrics, sending zeroes")
}
if err != nil {
log.Log("crit", fmt.Sprintf("%s", err))
}
for metric, value := range metrics {
if new_metrics {
difference[metric] = 0
} else {
difference[metric] = value - readMetric(device, metric)
if int64(value-readMetric(device, metric)) < 0 {
difference[metric] = 0
}
}
writeMetric(device, metric, value)
}
return difference
}
示例3: GetMetric
func GetMetric(params interface{}, log *logger.Logger) interface{} {
var loadavg [3]C.double
log.Log("debug", "Calling getloadavg()")
C.getloadavg(&loadavg[0], 3)
return loadavg
}
示例4: GetMetric
func GetMetric(params interface{}, log *logger.Logger) interface{} {
result, err := gm.MemoryUsage()
if err != nil {
log.Log("crit", err.Error())
return nil
}
return result
}
示例5: GetMetric
func GetMetric(params interface{}, log *logger.Logger) interface{} {
results, err := ioUsage.Metric(params.(string))
if err != nil {
log.Log("crit", err.Error())
return nil
}
return results
}
示例6: GetMetric
func GetMetric(params interface{}, log *logger.Logger) interface{} {
res, err := gm.ProcessMemoryUsage(params.(string))
if err != nil {
log.Log("crit", err.Error())
return nil
}
return res
}
示例7: readURL
func readURL(url string, log *logger.Logger) interface{} {
req, err := http.NewRequest("GET", url, nil)
req.Close = true
if err != nil {
log.Log("crit", fmt.Sprintf("URL '%s' is malformed: %s", url, err.Error()))
return nil
}
return doRequest(req, &http.Client{}, log)
}
示例8: Start
func Start(listen string, config types.CirconusConfig, log *logger.Logger) error {
go query.ResultPoller(config, log)
log.Log("info", "Starting Web Service")
s := &http.Server{
Addr: listen,
Handler: &WebHandler{Config: config, Logger: log},
}
return s.ListenAndServe()
}
示例9: ResultPoller
func ResultPoller(config types.CirconusConfig, log *logger.Logger) {
log.Log("info", "Starting Result Poller")
interval_duration := time.Second * time.Duration(config.PollInterval)
for {
start := time.Now()
AllPlugins(config, log)
duration := time.Now().Sub(start)
if duration < interval_duration {
time.Sleep(interval_duration - duration)
}
}
}
示例10: AllPlugins
func AllPlugins(config types.CirconusConfig, log *logger.Logger) {
rwmutex.Lock()
defer rwmutex.Unlock()
if pluginResults == nil {
pluginResults = make(types.PluginResultCollection)
}
log.Log("debug", "Querying All Plugins")
for key, _ := range config.Plugins {
pluginResults[key] = Plugin(key, config, log)
}
log.Log("debug", "Done Querying All Plugins")
}
示例11: Plugin
func Plugin(name string, config types.CirconusConfig, log *logger.Logger) types.PluginResult {
log.Log("debug", fmt.Sprintf("Plugin %s Requested", name))
item, ok := config.Plugins[name]
if ok {
t, ok := types.Plugins[item.Type]
if ok {
log.Log("debug", fmt.Sprintf("Plugin %s exists, running", name))
return t(item.Params, log)
}
}
return nil
}
示例12: getJiffies
func getJiffies(log *logger.Logger) (jiffies int64, cpus int64) {
content, err := ioutil.ReadFile("/proc/stat")
if err != nil {
log.Log("crit", fmt.Sprintf("While processing the cpu_usage package: %s"))
return 0, 0
}
lines := strings.Split(string(content), "\n")
for _, line := range lines {
if strings.Index(line, "cpu ") == 0 {
/* cpu with no number is the aggregate of all of them -- this is what we
* want to parse
*/
parts := strings.Split(line, " ")
/* 2 - 11 are the time aggregates */
for x := 2; x <= 11; x++ {
/* 5 is the idle time, which we don't want */
if x == 5 {
continue
}
/* integer all the things */
part, err := strconv.Atoi(parts[x])
if err != nil {
log.Log("crit", fmt.Sprintf("Could not convert integer from string while processing cpu_usage: %s", parts[x]))
return 0, 0
}
jiffies += int64(part)
}
} else if strings.Index(line, "cpu") == 0 {
/* cpu with a number is the specific time -- cheat and use this for the
* processor count since we've already read it
*/
cpus++
}
}
return jiffies, cpus
}
示例13: GetMetric
func GetMetric(params interface{}, log *logger.Logger) interface{} {
total := uint(0)
page_size := uint(C.get_pgsz())
for _, pid := range util.GetPids(params.(string), log) {
path := "/proc/" + pid + "/statm"
f, err := os.Open(path)
if err != nil {
log.Log("crit", "Could not open "+path+": "+err.Error())
return nil
}
defer f.Close()
content, err := ioutil.ReadAll(f)
if err != nil {
log.Log("crit", "Could not read from "+path+": "+err.Error())
return nil
}
parts := strings.Split(string(content), " ")
mem, err := strconv.Atoi(parts[1])
if err != nil {
log.Log("crit", "Trouble converting resident size "+parts[1]+" to integer: "+err.Error())
return nil
}
total += uint(mem) * page_size
}
return total
}
示例14: doRequest
func doRequest(req *http.Request, client *http.Client, log *logger.Logger) interface{} {
var json_out interface{}
resp, err := client.Do(req)
defer resp.Body.Close()
if err != nil {
log.Log("crit", fmt.Sprintf("Could not contact resource at URL '%s': %s", req.URL.String(), err.Error()))
return nil
}
out, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Log("crit", fmt.Sprintf("Error while gathering output from URL '%s': %s", req.URL.String(), err.Error()))
return nil
}
err = json.Unmarshal(out, &json_out)
if err != nil {
log.Log("crit", fmt.Sprintf("Error while marshalling content: %s: %s", string(out), err.Error()))
return nil
}
return json_out
}
示例15: GetMetric
func GetMetric(params interface{}, log *logger.Logger) interface{} {
path := C.CString(params.(string))
stat := C.go_statvfs(path)
readonly := C.go_fs_readonly(path)
log.Log("debug", fmt.Sprintf("blocks size on %s: %v", string(*path), stat.f_bsize))
log.Log("debug", fmt.Sprintf("blocks total on %s: %v", string(*path), stat.f_blocks))
log.Log("debug", fmt.Sprintf("blocks free on %s: %v", string(*path), stat.f_bavail))
defer C.free(unsafe.Pointer(stat))
defer C.free(unsafe.Pointer(path))
blocks := uint64(stat.f_blocks)
avail := uint64(stat.f_bavail)
free := float64(0)
if avail != 0 {
free = math.Ceil(((float64(blocks) - float64(avail)) / float64(blocks)) * 100)
}
return [4]interface{}{
free,
avail * uint64(stat.f_frsize),
blocks * uint64(stat.f_frsize),
readonly == 1,
}
}