本文整理匯總了Golang中github.com/elastic/beats/libbeat/common.Time函數的典型用法代碼示例。如果您正苦於以下問題:Golang Time函數的具體用法?Golang Time怎麽用?Golang Time使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Time函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetBlkioEvent
func (d *EventGenerator) GetBlkioEvent(container *docker.APIContainers, stats *docker.Stats) common.MapStr {
logp.Debug("generator", "Generate blkio event %v", container.ID)
blkioStats := d.buildStats(stats.Read, stats.BlkioStats.IOServicedRecursive)
var event common.MapStr
d.BlkioStats.RLock()
oldBlkioStats, ok := d.BlkioStats.M[container.ID]
d.BlkioStats.RUnlock()
if ok {
calculator := d.CalculatorFactory.NewBlkioCalculator(oldBlkioStats, blkioStats)
event = common.MapStr{
"@timestamp": common.Time(stats.Read),
"type": "blkio",
"containerID": container.ID,
"containerName": d.extractContainerName(container.Names),
"containerLabels": d.buildLabelArray(container.Labels),
"dockerSocket": d.Socket,
"blkio": common.MapStr{
"read_ps": calculator.GetReadPs(),
"write_ps": calculator.GetWritePs(),
"total_ps": calculator.GetTotalPs(),
},
}
} else {
event = common.MapStr{
"@timestamp": common.Time(stats.Read),
"type": "blkio",
"containerID": container.ID,
"containerName": d.extractContainerName(container.Names),
"containerLabels": d.buildLabelArray(container.Labels),
"dockerSocket": d.Socket,
"blkio": common.MapStr{
"read_ps": float64(0),
"write_ps": float64(0),
"total_ps": float64(0),
},
}
}
d.BlkioStats.Lock()
d.BlkioStats.M[container.ID] = blkioStats
// purge old saved data
for containerId, blkioStat := range d.BlkioStats.M {
// if data older than two ticks, then delete it
if d.expiredSavedData(blkioStat.Time) {
delete(d.BlkioStats.M, containerId)
}
}
d.BlkioStats.Unlock()
return event
}
示例2: toTime
func toTime(key string, data map[string]interface{}) (interface{}, error) {
emptyIface, exists := data[key]
if !exists {
return common.Time(time.Unix(0, 0)), fmt.Errorf("Key %s not found", key)
}
ts, ok := emptyIface.(time.Time)
if !ok {
return common.Time(time.Unix(0, 0)), fmt.Errorf("Expected date, found %T", emptyIface)
}
return common.Time(ts), nil
}
示例3: processGroups
func processGroups(groups []string, topic string, pids map[int32]int64) []common.MapStr {
var events []common.MapStr
for _, group := range groups {
pid_offsets, err := getConsumerOffsets(group, topic, pids)
if err == nil {
for pid, offset := range pid_offsets {
event := common.MapStr{
"@timestamp": common.Time(time.Now()),
"type": "consumer",
"partition": pid,
"topic": topic,
"group": group,
"offset": offset,
}
size, ok := pids[pid]
if ok {
event.Update(common.MapStr{"lag": size - offset})
}
events = append(events, event)
}
} else {
logp.Debug("kafkabeat", "No offsets for group %s on topic %s", group, topic)
}
}
return events
}
示例4: Publish
func (fp *PhpfpmPublisher) Publish(data map[string]interface{}) {
fp.client.PublishEvent(common.MapStr{
"@timestamp": common.Time(time.Now()),
"type": "phpfpm",
"phpfpm": data,
})
}
示例5: GetCpuEvent
func (d *EventGenerator) GetCpuEvent(container *docker.APIContainers, stats *docker.Stats) common.MapStr {
logp.Debug("generator", "Generate cpu event %v", container.ID)
calculator := d.CalculatorFactory.NewCPUCalculator(
calculator.CPUData{
PerCpuUsage: stats.PreCPUStats.CPUUsage.PercpuUsage,
TotalUsage: stats.PreCPUStats.CPUUsage.TotalUsage,
UsageInKernelmode: stats.PreCPUStats.CPUUsage.UsageInKernelmode,
UsageInUsermode: stats.PreCPUStats.CPUUsage.UsageInUsermode,
},
calculator.CPUData{
PerCpuUsage: stats.CPUStats.CPUUsage.PercpuUsage,
TotalUsage: stats.CPUStats.CPUUsage.TotalUsage,
UsageInKernelmode: stats.CPUStats.CPUUsage.UsageInKernelmode,
UsageInUsermode: stats.CPUStats.CPUUsage.UsageInUsermode,
},
)
event := common.MapStr{
"@timestamp": common.Time(stats.Read),
"type": "cpu",
"containerID": container.ID,
"containerName": d.extractContainerName(container.Names),
"containerLabels": d.buildLabelArray(container.Labels),
"dockerSocket": d.Socket,
"cpu": common.MapStr{
"percpuUsage": calculator.PerCpuUsage(),
"totalUsage": calculator.TotalUsage(),
"usageInKernelmode": calculator.UsageInKernelmode(),
"usageInUsermode": calculator.UsageInUsermode(),
},
}
return event
}
示例6: ToMapStr
func (lr LogRecord) ToMapStr() common.MapStr {
m := common.MapStr{
"eventLogName": lr.EventLogName,
"sourceName": lr.SourceName,
"computerName": lr.ComputerName,
"recordNumber": lr.RecordNumber,
"eventID": lr.EventID,
"eventType": lr.EventType,
"message": lr.Message,
"@timestamp": common.Time(lr.TimeGenerated),
"type": "eventlog",
}
if lr.EventCategory != "" {
m["eventCategory"] = lr.EventCategory
}
if lr.UserSID != nil {
m["userSID"] = common.MapStr{
"name": lr.UserSID.Name,
"domain": lr.UserSID.Domain,
"type": lr.UserSID.SIDType.String(),
}
}
return m
}
示例7: TestHttpEventToMapStr
func TestHttpEventToMapStr(t *testing.T) {
now := time.Now()
fields := make(map[string]string)
fields["field1"] = "value1"
fields["field2"] = "value2"
request := Request{}
request.Url = "www.example.org"
headers := make(map[string]string)
headers["header1"] = "value1"
request.Headers = headers
request.Body = "Body"
request.Method = "get"
event := HttpEvent{}
event.Fields = fields
event.DocumentType = "test"
event.ReadTime = now
event.Request = request
mapStr := event.ToMapStr()
_, fieldsExist := mapStr["fields"]
assert.True(t, fieldsExist)
_, requestExist := mapStr["request"]
assert.True(t, requestExist)
assert.Equal(t, "test", mapStr["type"])
assert.Equal(t, common.Time(now), mapStr["@timestamp"])
}
示例8: ToMapStr
func (e *Event) ToMapStr() common.MapStr {
event := common.MapStr{
common.EventMetadataKey: e.EventMetadata,
"@timestamp": common.Time(e.ReadTime),
"source": e.State.Source,
"offset": e.State.Offset, // Offset here is the offset before the starting char.
"type": e.DocumentType,
"input_type": e.InputType,
}
// Add data fields which are added by the readers
for key, value := range e.Data {
event[key] = value
}
// Check if json fields exist
var jsonFields common.MapStr
if fields, ok := event["json"]; ok {
jsonFields = fields.(common.MapStr)
}
if e.JSONConfig != nil && len(jsonFields) > 0 {
mergeJSONFields(e, event, jsonFields)
} else if e.Text != nil {
event["message"] = *e.Text
}
return event
}
示例9: ToMapStr
func (f *FileEvent) ToMapStr() common.MapStr {
event := common.MapStr{
"@timestamp": common.Time(f.ReadTime),
"source": f.Source,
"offset": f.Offset, // Offset here is the offset before the starting char.
"message": f.Text,
"type": f.DocumentType,
"input_type": f.InputType,
"count": 1,
}
if f.Fields != nil {
if f.fieldsUnderRoot {
for key, value := range *f.Fields {
// in case of conflicts, overwrite
_, found := event[key]
if found {
logp.Warn("Overwriting %s key", key)
}
event[key] = value
}
} else {
event["fields"] = f.Fields
}
}
return event
}
示例10: collectFileSystemStats
func collectFileSystemStats(fss []sigar.FileSystem) []common.MapStr {
events := make([]common.MapStr, 0, len(fss))
for _, fs := range fss {
fsStat, err := GetFileSystemStat(fs)
if err != nil {
logp.Debug("topbeat", "Skip filesystem %d: %v", fsStat, err)
continue
}
addFileSystemUsedPercentage(fsStat)
event := common.MapStr{
"@timestamp": common.Time(time.Now()),
"type": "filesystem",
"count": 1,
"fs": common.MapStr{
"device_name": fsStat.DevName,
"mount_point": fsStat.Mount,
"total": fsStat.Total,
"used": fsStat.Used,
"free": fsStat.Free,
"avail": fsStat.Avail,
"files": fsStat.Files,
"free_files": fsStat.FreeFiles,
"used_p": fsStat.UsedPercent,
},
}
events = append(events, event)
}
return events
}
示例11: getCpuEvent
func (d *EventGenerator) getCpuEvent(container *docker.APIContainers, stats *docker.Stats) common.MapStr {
calculator := d.calculatorFactory.newCPUCalculator(
CPUData{
perCpuUsage: stats.PreCPUStats.CPUUsage.PercpuUsage,
totalUsage: stats.PreCPUStats.CPUUsage.TotalUsage,
usageInKernelmode: stats.PreCPUStats.CPUUsage.UsageInKernelmode,
usageInUsermode: stats.PreCPUStats.CPUUsage.UsageInUsermode,
},
CPUData{
perCpuUsage: stats.CPUStats.CPUUsage.PercpuUsage,
totalUsage: stats.CPUStats.CPUUsage.TotalUsage,
usageInKernelmode: stats.CPUStats.CPUUsage.UsageInKernelmode,
usageInUsermode: stats.CPUStats.CPUUsage.UsageInUsermode,
},
)
event := common.MapStr{
"@timestamp": common.Time(stats.Read),
"type": "cpu",
"containerID": container.ID,
"containerName": d.extractContainerName(container.Names),
"cpu": common.MapStr{
"percpuUsage": calculator.perCpuUsage(),
"totalUsage": calculator.totalUsage(),
"usageInKernelmode": calculator.usageInKernelmode(),
"usageInUsermode": calculator.usageInUsermode(),
},
}
return event
}
示例12: testSendMultipleViaLogstash
func testSendMultipleViaLogstash(t *testing.T, name string, tls bool) {
ls := newTestLogstashOutput(t, name, tls)
defer ls.Cleanup()
for i := 0; i < 10; i++ {
event := common.MapStr{
"@timestamp": common.Time(time.Now()),
"host": "test-host",
"type": "log",
"message": fmt.Sprintf("hello world - %v", i),
}
ls.PublishEvent(nil, testOptions, event)
}
// wait for logstash event flush + elasticsearch
waitUntilTrue(5*time.Second, checkIndex(ls, 10))
// search value in logstash elasticsearch index
resp, err := ls.Read()
if err != nil {
return
}
if len(resp) != 10 {
t.Errorf("wrong number of results: %d", len(resp))
}
}
示例13: TestClientPublishEvent
func TestClientPublishEvent(t *testing.T) {
index := "beat-int-pub-single-event"
output, client := connectTestEs(t, map[string]interface{}{
"index": index,
})
// drop old index preparing test
client.Delete(index, "", "", nil)
event := outputs.Data{Event: common.MapStr{
"@timestamp": common.Time(time.Now()),
"type": "libbeat",
"message": "Test message from libbeat",
}}
err := output.PublishEvent(nil, outputs.Options{Guaranteed: true}, event)
if err != nil {
t.Fatal(err)
}
_, _, err = client.Refresh(index)
if err != nil {
t.Fatal(err)
}
_, resp, err := client.CountSearchURI(index, "", nil)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, 1, resp.Count)
}
示例14: TestUseType
func TestUseType(t *testing.T) {
if testing.Short() {
t.Skip("Skipping in short mode. Requires Kafka")
}
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"kafka"})
}
id := strconv.Itoa(rand.New(rand.NewSource(int64(time.Now().Nanosecond()))).Int())
logType := fmt.Sprintf("log-type-%s", id)
kafka := newTestKafkaOutput(t, "", true)
event := common.MapStr{
"@timestamp": common.Time(time.Now()),
"host": "test-host",
"type": logType,
"message": id,
}
if err := kafka.PublishEvent(nil, testOptions, event); err != nil {
t.Fatal(err)
}
messages := testReadFromKafkaTopic(t, logType, 1, 5*time.Second)
if assert.Len(t, messages, 1) {
msg := messages[0]
logp.Debug("kafka", "%s: %s", msg.Key, msg.Value)
assert.Contains(t, string(msg.Value), id)
}
}
示例15: GetCoreStats
func (cpu *CPU) GetCoreStats() ([]common.MapStr, error) {
events := []common.MapStr{}
cpuCoreStat, err := GetCpuTimesList()
if err != nil {
logp.Warn("Getting cpu core times: %v", err)
return nil, err
}
cpu.AddCpuPercentageList(cpuCoreStat)
for coreNumber, stat := range cpuCoreStat {
coreStat := cpu.GetCpuStatEvent(&stat)
coreStat["id"] = coreNumber
event := common.MapStr{
"@timestamp": common.Time(time.Now()),
"type": "core",
"core": coreStat,
}
events = append(events, event)
}
return events, nil
}