// translateFS creates all the TimeSeries for a given FsStats and volume name. func translateFS(volume string, fs *stats.FsStats, tsFactory *timeSeriesFactory) ([]*v3.TimeSeries, error) { var timeSeries []*v3.TimeSeries // First, check that we've been given all the data we need. if fs == nil { return nil, fmt.Errorf("File-system information missing.") } if fs.CapacityBytes == nil { return nil, fmt.Errorf("CapacityBytes is missing from FsStats %v", fs) } if fs.UsedBytes == nil { return nil, fmt.Errorf("UsedBytes is missing from FsStats %v", fs) } // For some reason the Kubelet doesn't return when this sample is from, // so we'll use now. now := time.Now() resourceLabels := map[string]string{"device_name": volume} // Total disk available. diskTotalPoint := tsFactory.newPoint(&v3.TypedValue{ Int64Value: monitor.Int64Ptr(int64(*fs.CapacityBytes)), ForceSendFields: []string{"Int64Value"}, }, now, diskTotalMD.MetricKind) timeSeries = append(timeSeries, tsFactory.newTimeSeries(resourceLabels, diskTotalMD, diskTotalPoint)) // Total disk used. diskUsedPoint := tsFactory.newPoint(&v3.TypedValue{ Int64Value: monitor.Int64Ptr(int64(*fs.UsedBytes)), ForceSendFields: []string{"Int64Value"}, }, now, diskUsedMD.MetricKind) timeSeries = append(timeSeries, tsFactory.newTimeSeries(resourceLabels, diskUsedMD, diskUsedPoint)) return timeSeries, nil }
// translateMemory creates all the TimeSeries for a given MemoryStats. func translateMemory(memory *stats.MemoryStats, tsFactory *timeSeriesFactory) ([]*v3.TimeSeries, error) { var timeSeries []*v3.TimeSeries // First, check that we've been given all the data we need. if memory == nil { return nil, fmt.Errorf("Memory information missing.") } if memory.MajorPageFaults == nil { return nil, fmt.Errorf("MajorPageFaults missing in MemoryStats %v", memory) } if memory.PageFaults == nil { return nil, fmt.Errorf("PageFaults missing in MemoryStats %v", memory) } if memory.WorkingSetBytes == nil { return nil, fmt.Errorf("WorkingSetBytes information missing in MemoryStats %v", memory) } if memory.UsageBytes == nil { return nil, fmt.Errorf("UsageBytes information missing in MemoryStats %v", memory) } // Major page faults. majorPFPoint := tsFactory.newPoint(&v3.TypedValue{ Int64Value: monitor.Int64Ptr(int64(*memory.MajorPageFaults)), ForceSendFields: []string{"Int64Value"}, }, memory.Time.Time, pageFaultsMD.MetricKind) timeSeries = append(timeSeries, tsFactory.newTimeSeries(majorPageFaultLabels, pageFaultsMD, majorPFPoint)) // Minor page faults. minorPFPoint := tsFactory.newPoint(&v3.TypedValue{ Int64Value: monitor.Int64Ptr(int64(*memory.PageFaults - *memory.MajorPageFaults)), ForceSendFields: []string{"Int64Value"}, }, memory.Time.Time, pageFaultsMD.MetricKind) timeSeries = append(timeSeries, tsFactory.newTimeSeries(minorPageFaultLabels, pageFaultsMD, minorPFPoint)) // Non-evictable memory. nonEvictMemPoint := tsFactory.newPoint(&v3.TypedValue{ Int64Value: monitor.Int64Ptr(int64(*memory.WorkingSetBytes)), ForceSendFields: []string{"Int64Value"}, }, memory.Time.Time, memUsedMD.MetricKind) timeSeries = append(timeSeries, tsFactory.newTimeSeries(memUsedNonEvictableLabels, memUsedMD, nonEvictMemPoint)) // Evictable memory. evictMemPoint := tsFactory.newPoint(&v3.TypedValue{ Int64Value: monitor.Int64Ptr(int64(*memory.UsageBytes - *memory.WorkingSetBytes)), ForceSendFields: []string{"Int64Value"}, }, memory.Time.Time, memUsedMD.MetricKind) timeSeries = append(timeSeries, tsFactory.newTimeSeries(memUsedEvictableLabels, memUsedMD, evictMemPoint)) // Available memory. This may or may not be present, so don't fail if it's absent. if memory.AvailableBytes != nil { availableMemPoint := tsFactory.newPoint(&v3.TypedValue{ Int64Value: monitor.Int64Ptr(int64(*memory.AvailableBytes)), ForceSendFields: []string{"Int64Value"}, }, memory.Time.Time, memTotalMD.MetricKind) timeSeries = append(timeSeries, tsFactory.newTimeSeries(noLabels, memTotalMD, availableMemPoint)) } return timeSeries, nil }
// translateEviction give a GCM v3 TimeSeries for the node_eviction_count metric. func (t *Translator) translateEviction(metrics *Metrics) *v3.TimeSeries { monitoredLabels := map[string]string{ "project_id": t.project, "cluster_name": t.cluster, "zone": t.zone, "instance_id": t.instanceID, "namespace_id": "", "pod_id": "machine", "container_name": "", } now := time.Now().Format(time.RFC3339) createTime := time.Unix(metrics.CreateTime, 0).Format(time.RFC3339) point := &v3.Point{ Interval: &v3.TimeInterval{ StartTime: createTime, EndTime: now, }, Value: &v3.TypedValue{ Int64Value: monitor.Int64Ptr(metrics.NodeEvictions), ForceSendFields: []string{"Int64Value"}, }, } return &v3.TimeSeries{ Metric: &v3.Metric{ Labels: noLabels, Type: "container.googleapis.com/master/node_controller/node_eviction_count", }, MetricKind: "CUMULATIVE", ValueType: "INT64", Resource: &v3.MonitoredResource{ Labels: monitoredLabels, Type: "gke_container", }, Points: []*v3.Point{point}, } }