iPhoneからPythonで作ったAPIを叩いて、XenServerのリソースを見れるようにしてみた。
とりあえず、機能はこれだけ。
・仮想マシン一覧
・仮想マシン情報
・リソース情報
・CPU使用率のグラフ化
core-plotは色をつけた。
折れ線グラフの下側に色を付けたいのに、つけられない。
レイヤー的に、折れ線の下よりも折れ線の上の方が上になるらしい…。
メモリのラベルは、NSNumberじゃないといけないらしい。
時間軸を表したいのに…。
ソース
多分こんな感じ。
-(void)reloadData { // データ取得 [self getRRD]; // XYグラフを作成してビューにのせる graph = [[[CPXYGraph alloc] initWithFrame:layerHost.bounds] autorelease]; layerHost.hostedLayer = graph; // メモリラベル表示 graph.plotAreaFrame.masksToBorder = NO; // グラフの範囲を決める //float max_value = [[[rdd objectForKey:@"cpu0"] objectForKey:@"max_value"] floatValue] * 1.05; int values_length = [[[rrd objectForKey:@"cpu0"] objectForKey:@"values"] count]; CPXYPlotSpace *plotSpace; plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace; plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0) length:CPDecimalFromFloat(values_length)]; //plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0) length:CPDecimalFromFloat(max_value)]; plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0) length:CPDecimalFromFloat(100.0)]; // データはdataSourceプロトコルで提供 CPScatterPlot *scatterPlot; scatterPlot = [[[CPScatterPlot alloc] init] autorelease]; scatterPlot.identifier = @"log plot"; scatterPlot.dataSource = self; // 線 scatterPlot.dataLineStyle.lineWidth = 2.f; scatterPlot.dataLineStyle.lineColor = [CPColor greenColor]; // グラフ枠内(ラインの上) CPColor *areaColor = [CPColor colorWithComponentRed:0.93 green:0.93 blue:0.93 alpha:1.0]; scatterPlot.areaFill = [CPFill fillWithColor:areaColor]; //CPGradient *areaGradient = [CPGradient gradientWithBeginningColor:areaColor endingColor:areaColor]; //areaGradient.angle = -90.0f; //CPFill *areaGradientFill = [CPFill fillWithGradient:areaGradient]; //scatterPlot.areaFill = areaGradientFill; scatterPlot.areaBaseValue = CPDecimalFromFloat(100.0); // グラフ枠線 CPLineStyle *borderLineStyle = [CPLineStyle lineStyle]; borderLineStyle.lineColor = [CPColor colorWithComponentRed:0.7 green:0.7 blue:0.7 alpha:1.0]; borderLineStyle.lineWidth = 1.0f; graph.plotAreaFrame.borderLineStyle = borderLineStyle; // グラフ枠内 CPColor *frameColor1 = [CPColor colorWithComponentRed:0.5 green:0.5 blue:0.5 alpha:1.0]; CPColor *frameColor2 = [CPColor colorWithComponentRed:0.95 green:0.95 blue:0.95 alpha:1.0]; CPGradient *frameGradient = [CPGradient gradientWithBeginningColor:frameColor1 endingColor:frameColor2]; frameGradient.angle = -90.0f; CPFill *frameGradientFill = [CPFill fillWithGradient:frameGradient]; [graph.plotAreaFrame setFill:frameGradientFill]; // グラフ枠外 CPColor *graphColor = [CPColor colorWithComponentRed:0.9 green:0.9 blue:0.9 alpha:1.0]; //CPGradient *graphGradient = [CPGradient gradientWithBeginningColor:graphColor endingColor:[CPColor clearColor]]; //graph.fill = [CPFill fillWithGradient:graphGradient]; graph.fill = [CPFill fillWithColor:graphColor]; // Axes CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet; axisSet.yAxis.majorIntervalLength = CPDecimalFromString(@"10"); axisSet.yAxis.minorTicksPerInterval = 1; axisSet.yAxis.orthogonalCoordinateDecimal = CPDecimalFromString(@"1.0"); axisSet.xAxis.majorIntervalLength = CPDecimalFromString(@"10"); axisSet.xAxis.minorTicksPerInterval = 0; axisSet.xAxis.orthogonalCoordinateDecimal = CPDecimalFromString(@"1.0"); axisSet.xAxis.isFloatingAxis = YES; axisSet.xAxis.labelExclusionRanges = [NSArray arrayWithObjects:[CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-100) length:CPDecimalFromFloat(300)], nil]; // padding graph.paddingLeft = 40; graph.paddingRight = 10; graph.paddingTop = 15; graph.paddingBottom = 25; [graph addPlot:scatterPlot]; }