統計與計量‎ > ‎應用總覽‎ > ‎

CPU 使用率分析

進階分析

資料結構

統計分析圖表:

ANOVA(CPU_USER)
Tables of means
Grand mean
         
33.65927 

 factor(HOSTNAME) 
    F12APDB1 F12APDB2
        61.7    0.013
rep     18.0   15.000


ANOVA(CPU_WAIT)
Tables of means
Grand mean
         
1.875587 

 factor(HOSTNAME) 
    F12APDB1 F12APDB2
        3.44  0.00103
rep    18.00 15.00000


ANOVA(CPU_SYS)
Tables of means
Grand mean
         
3.274888 

 factor(HOSTNAME) 
    F12APDB1 F12APDB2
        5.91     0.11
rep    18.00    15.00

GNU-R:

library(DBI)
library(RMySQL)
library(car)

GetDB <- function (SQL) {
  mySQL.Connection <- dbConnect(MySQL(), host=mySQL.Host, user=mySQL.User, password=mySQL.Password, db=mySQL.Schema)

  ResultSet <- dbGetQuery(mySQL.Connection, SQL)
  dbDisconnect(mySQL.Connection)
  
  ResultSet
}

SaveScatterPlotGraphics <- function(pngFileName, formula, graphicsTitle, graphicsXTitle, graphicsYTitle) {
  png(file=pngFileName)
    scatterplot(formula, reg.line=lm, smooth=TRUE, spread=TRUE, boxplots='xy', span=0.5, main=graphicsTitle, xlab=graphicsXTitle, ylab=graphicsYTitle)
  dev.off()
}

PrintANOVA <- function (formula, heading) {
  cat(paste("ANOVA(", heading, ")", sep=""))
  cat("\n")
  R.ANOVA.CPU_USER = aov(formula)
  summary(R.ANOVA.CPU_USER) 
  print(model.tables(R.ANOVA.CPU_USER, "means"), digits=3)
  cat("\n\n")
}

mySQL.Host <- "127.0.0.1"
mySQL.User <- "nmon"
mySQL.Password <- "nmon"
mySQL.Schema <- "nmon"

R.Chart.Folder <- "/var/nmon/Results/Graphics"
R.Analysis.Folder <- "/var/nmon/Results/Analysis"

mySQL.SQL <- paste("SELECT DISTINCT DATE(ZZZZ) AS TXN_DATE FROM ", mySQL.Schema, ".cpu_all ORDER BY ZZZZ LIMIT 30", sep="")
mySQL.DATA <- GetDB(mySQL.SQL)

Date.Start <- mySQL.DATA$TXN_DATE[1]
Date.End <- mySQL.DATA$TXN_DATE[length(mySQL.DATA$TXN_DATE)]

mySQL.SQL <- paste("SELECT HOSTNAME, TO_DAYS(DATE(ZZZZ)) AS TXN_DATE,
AVG(USER_PCT) AS CPU_USER, AVG(SYS_PCT) AS CPU_SYS, AVG(WAIT_PCT) AS CPU_WAIT FROM "
, mySQL.Schema, ".cpu_all WHERE DATE(ZZZZ) BETWEEN '", Date.Start, "' AND '", Date.End, "' GROUP BY HOSTNAME, DATE(ZZZZ) ORDER BY HOSTNAME, DATE(ZZZZ)", sep="") mySQL.DATA <- GetDB(mySQL.SQL) TXN_DATE <- (mySQL.DATA$TXN_DATE) HOSTNAME <- (mySQL.DATA$HOSTNAME) CPU_USER <- (mySQL.DATA$CPU_USER) CPU_WAIT <- (mySQL.DATA$CPU_WAIT) CPU_SYS <- (mySQL.DATA$CPU_SYS) mySQL.Chart <- paste(R.Chart.Folder, "/", "AVG_HOST_CPU_USER.png", sep="") SaveScatterPlotGraphics(mySQL.Chart, CPU_USER~TXN_DATE | HOSTNAME, "CPU.USER~TXN.DATE by HOST (Last 30 Days)", "Day #", "CPU%") mySQL.Chart <- paste(R.Chart.Folder, "/", "AVG_HOST_CPU_WAIT.png", sep="") SaveScatterPlotGraphics(mySQL.Chart, CPU_WAIT~TXN_DATE | HOSTNAME, "CPU.WAIT~TXN.DATE by HOST (Last 30 Days)", "Day #", "CPU%") mySQL.Chart <- paste(R.Chart.Folder, "/", "AVG_HOST_CPU_SYS.png", sep="") SaveScatterPlotGraphics(mySQL.Chart, CPU_SYS~TXN_DATE | HOSTNAME, "CPU.SYS~TXN.DATE by HOST (Last 30 Days)", "Day #", "CPU%") sink(paste(R.Analysis.Folder, "/", "AVG_HOST_CPU.txt", sep="")) PrintANOVA(CPU_USER~factor(HOSTNAME), "CPU_USER") PrintANOVA(CPU_WAIT~factor(HOSTNAME), "CPU_WAIT") PrintANOVA(CPU_SYS~factor(HOSTNAME), "CPU_SYS") sink() rm(list=(ls()))
ċ
ReportDB-AVG_CPU.R
(3k)
李智,
2012年7月4日 上午8:57