本文整理匯總了Golang中github.com/elleFlorio/gru/Godeps/_workspace/src/github.com/Sirupsen/logrus.WithFields函數的典型用法代碼示例。如果您正苦於以下問題:Golang WithFields函數的具體用法?Golang WithFields怎麽用?Golang WithFields使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了WithFields函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: updateMetric
func updateMetric(target string, metricType enum.MetricType, metric string, toAdd []float64) {
defer mutex_instMet.Unlock()
mutex_instMet.Lock()
switch metricType {
case enum.METRIC_T_BASE:
if toUpdateInstace, ok := instancesMetrics[target]; ok {
values := toUpdateInstace.BaseMetrics[metric]
values = append(values, toAdd...)
toUpdateInstace.BaseMetrics[metric] = values
} else {
log.WithFields(log.Fields{
"target": target,
"metric": metric,
}).Errorln("Cannot update instance metric: unknown instance")
}
case enum.METRIC_T_USER:
if toUpdateService, ok := servicesMetrics[target]; ok {
values := toUpdateService.UserMetrics[metric]
values = append(values, toAdd...)
toUpdateService.UserMetrics[metric] = values
} else {
log.WithFields(log.Fields{
"target": target,
"metric": metric,
}).Errorln("Cannot update service metric: unknown service")
}
}
}
示例2: AssignSpecifiPortsToService
func AssignSpecifiPortsToService(name string, id string, ports map[string][]string) error {
defer runtime.Gosched()
mutex_port.Lock()
servicePorts := resources.Network.ServicePorts[name]
// Check if ALL the bindings are possible
// Otherwise "abort" the operation
for guest, bindings := range ports {
status := servicePorts.Status[guest]
for _, binding := range bindings {
if contains(binding, status.Occupied) {
servicePorts.LastAssigned = make(map[string][]string)
mutex_port.Unlock()
return errPortAlreadyOccupied
}
}
}
for guest, bindings := range ports {
status := servicePorts.Status[guest]
for _, binding := range bindings {
if contains(binding, status.Available) {
status.Available, status.Occupied = moveSpecificItem(binding, status.Available, status.Occupied)
} else {
log.WithFields(log.Fields{
"service": name,
"guest": guest,
"port": binding,
}).Warnln("Cannot find port in available ones. Adding it to occupied")
status.Occupied = append(status.Occupied, binding)
}
}
servicePorts.Status[guest] = status
servicePorts.LastAssigned = ports
}
resources.Network.ServicePorts[name] = servicePorts
instanceBindings[id] = ports
mutex_port.Unlock()
log.WithFields(log.Fields{
"service": name,
"instance": id,
"ports": ports,
}).Debugln("Assigned ports to service instance")
return nil
}
示例3: readCommand
func readCommand(r *http.Request) (Command, error) {
var err error
var cmd Command
body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1048576))
if err != nil {
log.WithField("err", err).Errorln("Error reading command body")
return Command{}, err
}
if err = r.Body.Close(); err != nil {
log.WithField("err", err).Errorln("Error closing command body")
return Command{}, err
}
if err = json.Unmarshal(body, &cmd); err != nil {
log.WithField("err", err).Errorln("Error unmarshaling command body")
return Command{}, err
}
cmd.Timestamp = time.Now()
log.WithFields(log.Fields{
"name": cmd.Name,
"target": cmd.Target,
"timestamp": cmd.Timestamp,
}).Debugln("Received command")
return cmd, nil
}
示例4: RequestPortsForService
func RequestPortsForService(name string) (map[string]string, error) {
defer runtime.Gosched()
mutex_port.Lock()
servicePorts := resources.Network.ServicePorts[name]
// Check if all the ports can be assigned
// otherwise "abort" the operation
for _, host := range servicePorts.Status {
if len(host.Available) < 1 {
servicePorts.LastRequested = make(map[string]string)
resources.Network.ServicePorts[name] = servicePorts
mutex_port.Unlock()
return make(map[string]string), ErrNoAvailablePorts
}
}
requestedPorts := make(map[string]string)
for guest, host := range servicePorts.Status {
requestedPorts[guest] = host.Available[len(host.Available)-1]
}
servicePorts.LastRequested = requestedPorts
resources.Network.ServicePorts[name] = servicePorts
mutex_port.Unlock()
log.WithFields(log.Fields{
"service": name,
"requestedPorts": requestedPorts,
}).Debugln("Requested ports for service")
return requestedPorts, nil
}
示例5: stopInstance
func stopInstance(name string, instance string) {
log.Debugln("Changing instance status to stop...")
status := srv.GetServiceInstanceStatus(name, instance)
if status == enum.STOPPED {
log.Debugln("Instance already stopped")
return
}
err := srv.ChangeServiceInstanceStatus(name, instance, status, enum.STOPPED)
if err != nil {
log.WithField("err", err).Errorln("Cannot stop service instance")
return
}
log.Debugln("Updating events...")
evt_mutex.Lock()
srvEvents := events.Service[name]
srvEvents.Stop = append(srvEvents.Stop, instance)
events.Service[name] = srvEvents
evt_mutex.Unlock()
log.Debugln("Unregistering instance...")
srv.UnregisterServiceInstance(name, instance)
log.WithFields(log.Fields{
"service": name,
"id": instance,
}).Infoln("stopped instance")
}
示例6: computeSysMetrics
func computeSysMetrics(instMetrics map[string]data.MetricData) data.MetricData {
// TODO - improve by adding capacity
baseMetrics := make(map[string]float64)
cpuSys := 0.0
memSys := make([]float64, 0, len(instMetrics))
for instance, metrics := range instMetrics {
service, err := srv.GetServiceById(instance)
if err != nil {
log.WithFields(log.Fields{
"instance": instance,
}).Errorln("Cannot find service by instance")
} else {
instCpus := service.Docker.CPUnumber
instCpuValue := metrics.BaseMetrics[enum.METRIC_CPU_AVG.ToString()] * float64(instCpus)
// CPU
cpuSys += instCpuValue
// MEM
// TODO
}
}
baseMetrics[enum.METRIC_CPU_AVG.ToString()] = cpuSys / float64(res.GetResources().CPU.Total)
baseMetrics[enum.METRIC_MEM_AVG.ToString()] = utils.Mean(memSys)
sysMetrics := data.MetricData{
BaseMetrics: baseMetrics,
}
return sysMetrics
}
示例7: GetCoresAvailable
func GetCoresAvailable(number int) (string, bool) {
defer runtime.Gosched()
cores_str := make([]string, 0, number)
mutex_cpu.RLock()
for i := 0; i < len(resources.CPU.Cores); i++ {
if resources.CPU.Cores[i] == true {
cores_str = append(cores_str, strconv.Itoa(i))
}
if len(cores_str) >= number {
break
}
}
if len(cores_str) < number {
log.Debugln("Error getting available cores: number of free cores < ", number)
mutex_cpu.RUnlock()
return "", false
}
mutex_cpu.RUnlock()
cores := strings.Join(cores_str, ",")
log.WithFields(log.Fields{
"number": number,
"cores": cores,
}).Debugln("Getting available cores")
return cores, true
}
示例8: keepAlive
func keepAlive(name string, id string) {
var err error
discoveryConf := cfg.GetAgentDiscovery()
ticker := time.NewTicker(time.Duration(discoveryConf.TTL-1) * time.Second)
opt := discovery.Options{
"TTL": time.Duration(discoveryConf.TTL) * time.Second,
}
ch_stop := ch.CreateInstanceChannel(id)
isntanceKey := discoveryConf.AppRoot + "/" + name + "/" + id
instanceValue := addressMap[id]
for {
select {
case <-ticker.C:
err = discovery.Set(isntanceKey, instanceValue, opt)
if err != nil {
log.WithFields(log.Fields{
"service": name,
"instance": id,
"address": instanceValue,
"err": err,
}).Errorln("Error keeping instance alive")
}
case <-ch_stop:
log.Debugln("Stopping keep alive routine")
return
}
}
}
示例9: updateNodeResources
func updateNodeResources() {
res.ComputeUsedResources()
log.WithFields(log.Fields{
"totalcpu": res.GetResources().CPU.Total,
"usedcpu": res.GetResources().CPU.Used,
"totalmem": res.GetResources().Memory.Total,
"usedmem": res.GetResources().Memory.Used,
}).Debugln("Updated node resources")
}
示例10: executeActions
func executeActions(target *cfg.Service, actions []enum.Action) {
var err error
for _, actionType := range actions {
config := buildConfig(target, actionType)
actExecutor := action.Get(actionType)
err = actExecutor.Run(config)
if err != nil {
log.WithFields(log.Fields{
"err": err,
"action": actionType.ToString(),
}).Errorln("Action not executed")
}
log.WithFields(log.Fields{
"target": target.Name,
"action": actionType.ToString(),
}).Infoln("Action executed")
}
}
示例11: displayPolicy
func displayPolicy(chosenPolicy *data.Policy) {
targets := make([]string, 0, len(chosenPolicy.Targets))
for _, target := range chosenPolicy.Targets {
targets = append(targets, target)
}
log.WithFields(log.Fields{
"name": chosenPolicy.Name,
"weight": fmt.Sprintf("%.2f", chosenPolicy.Weight),
"targets": targets,
}).Infoln("Policy to actuate")
}
示例12: initializeStorage
func initializeStorage() {
_, err := storage.New(cfg.GetAgentStorage().StorageService)
if err != nil {
log.WithFields(log.Fields{
"status": "warning",
"error": err,
"default": storage.Name(),
}).Warnln("Error initializing storage service")
} else {
log.WithField(storage.Name(), "ok").Infoln("Storage service initialized")
}
}
示例13: initializeMetricSerivice
func initializeMetricSerivice() {
_, err := metric.New(cfg.GetAgentMetric().MetricService, cfg.GetAgentMetric().Configuration)
if err != nil {
log.WithFields(log.Fields{
"status": "warning",
"error": err,
"default": metric.Name(),
}).Warnln("Error initializing metric service")
} else {
log.WithField(metric.Name(), "ok").Infoln("Metric service initialized")
}
}
示例14: initiailizeMonitoring
func initiailizeMonitoring() {
defer log.Infoln("Initializing autonomic monitoring")
ch_aut_err := chn.GetAutonomicErrChannel()
enableLogReading = cfg.GetAgentAutonomic().EnableLogReading
mtr.Initialize(srv.List())
// Start log reader if needed
if enableLogReading {
lgr.StartLogReader()
log.WithField("logreader", enableLogReading).Debugln("Log reading is enabled")
}
// Get the list of containers (running or not) to monitor
containers, err := container.Docker().Client.ListContainers(true, false, "")
if err != nil {
log.WithField("err", err).Debugln("Error monitoring containers")
ch_aut_err <- err
}
// Start the monitor for each configured service
for _, c := range containers {
info, _ := container.Docker().Client.InspectContainer(c.Id)
status := getContainerStatus(info)
service, err := srv.GetServiceByImage(c.Image)
if err != nil {
log.WithFields(log.Fields{
"err": err,
"image": c.Image,
}).Warningln("Error monitoring service")
} else {
e := evt.Event{
Service: service.Name,
Image: c.Image,
Instance: c.Id,
Status: status,
}
evt.HandleCreateEvent(e)
evt.HanldeStartEvent(e)
mtr.AddInstance(c.Id)
if _, ok := instBuffer[c.Id]; !ok {
instBuffer[c.Id] = instanceMetricBuffer{
cpuInst: utils.BuildBuffer(c_B_SIZE),
cpuSys: utils.BuildBuffer(c_B_SIZE),
}
}
container.Docker().Client.StartMonitorStats(c.Id, statCallBack, ch_mnt_stats_err)
if status == enum.PENDING && enableLogReading {
startMonitorLog(c.Id)
}
}
}
}
示例15: FreePortsFromService
func FreePortsFromService(name string, id string) {
defer runtime.Gosched()
mutex_port.Lock()
servicePorts := resources.Network.ServicePorts[name]
if ports, ok := instanceBindings[id]; ok {
for guest, bindings := range ports {
status := servicePorts.Status[guest]
for _, binding := range bindings {
if contains(binding, status.Occupied) {
status.Occupied, status.Available = moveSpecificItem(binding, status.Occupied, status.Available)
} else {
log.WithFields(log.Fields{
"service": name,
"instance": id,
"guest": guest,
"host": binding,
}).Warnln("Cannot find port in occupied list")
}
}
servicePorts.Status[guest] = status
}
resources.Network.ServicePorts[name] = servicePorts
delete(instanceBindings, id)
log.WithFields(log.Fields{
"service": name,
"instance": id,
"ports": ports,
}).Debugln("Released ports of service instance")
} else {
log.WithFields(log.Fields{
"service": name,
"instance": id,
}).Warnln("Cannot find instance id in port map")
}
mutex_port.Unlock()
}