Пример #1
0
func (c LogConn) UpdateNode(node *uc.Node) error {
	now := time.Now()
	node.UpdatedAt = now
	for _, cont := range node.Containers {
		cont.UpdateLastValue()
		for _, inter := range cont.NetworkInterfaces {
			for _, stat := range inter.NetworkStats {
				enetstat := convertToElasticNetStat(cont, inter, stat)
				enetstat.UpdatedAt = now
				enetstatBytes, err := json.Marshal(enetstat)
				if err != nil {
					log.Error("error while marshalling '%+v': \"%v\"", enetstat, err)
				}
				enetstatBytes = append(enetstatBytes, '\n')
				_, err = c.lsConn.Write(enetstatBytes)
				if err != nil {
					log.Error("error while sending bytes to logstash '%+v': \"%v\"", enetstat, err)
					if err := c.reconnectToLogstash(); err != nil {
						log.Error("Fail to reconnect: %#v", err)
					}
				}
			}
		}
	}
	return nil
}
Пример #2
0
func (c EConn) UpdateNode(node *uc.Node) error {
	now := time.Now()
	node.UpdatedAt = now
	currIndexName := c.indexName + now.Format(indexFormatString)
	bulkReq := c.Bulk().Index(currIndexName).Refresh(true)
	for _, cont := range node.Containers {
		cont.UpdateLastValue()
		for _, inter := range cont.NetworkInterfaces {
			for _, stat := range inter.NetworkStats {
				enetstat := convertToElasticNetStat(cont, inter, stat)
				enetstat.UpdatedAt = now
				bulkReq.Add(elastic.NewBulkIndexRequest().Index(currIndexName).
					Type(NodeTableName).Timestamp(enetstat.UpdatedAt.Format(time.RFC3339Nano)).Doc(enetstat))
			}
		}
	}
	_, err := bulkReq.Do()
	if err != nil {
		return err
	}
	return nil
}