コード例 #1
0
ファイル: perf_export.go プロジェクト: AntonioSun/lta
/*
PerfCounterExport will wxport performance counters collected from MS load
test to .csv files for perfmon to view
*/
func PerfCounterExport(options Options, ltRunId int, machineNameFilter string, pathOut string) {
	conn := getConnection(getConnectionString(options))
	defer conn.Close()
	log.Printf("[%s] Program started\n", progname)

	// get TraceName according to LoadTestRunId
	r, err := table.Get(conn,
		"SELECT TraceName from LoadTestRun WHERE LoadTestRunId = ?", ltRunId)
	check(err)
	ltTraceName := U8ToGoString(r.MustGetScaler(0, "TraceName").([]uint8))

	resultFilePre := pathOut + string(os.PathSeparator)
	resultFilePre = filepath.Dir(resultFilePre) +
		string(os.PathSeparator) + ltTraceName
	os.Mkdir(resultFilePre, os.ModePerm)
	// so far path only, now append folder name as file prefix
	resultFilePre += string(os.PathSeparator) + ltTraceName

	log.Printf("[%s] Exporting LoadTest %d\n  to %s-...\n  with step of %d\n",
		progname, ltRunId, resultFilePre, options.Step)

	if machineNameFilter != "" {
		fmt.Printf("  limiting to only export machine %s\n\n", machineNameFilter)
		savePerfmonAsCsv(options.NoClobber, conn, machineNameFilter, ltRunId, resultFilePre)
		os.Exit(0)
	}

	/*
			Get all machine names

		    SELECT  category.MachineName
		      FROM  LoadTestPerformanceCounterCategory AS category
		      JOIN  LoadTestPerformanceCounterInstance AS instance
		        ON  category.LoadTestRunId = instance.LoadTestRunId
		       AND  instance.LoadTestRunId = (
		            SELECT MAX(LoadTestRunId) from LoadTestRun )
		     GROUP  BY MachineName

	*/

	machines, err := table.Get(conn,
		"SELECT  category.MachineName"+
			"  FROM  LoadTestPerformanceCounterCategory AS category"+
			"  JOIN  LoadTestPerformanceCounterInstance AS instance"+
			"    ON  category.LoadTestRunId = instance.LoadTestRunId"+
			"   AND  instance.LoadTestRunId = ?"+
			" GROUP  BY MachineName", ltRunId)
	if err != nil {
		log.Fatal(err)
	}

	for _, machine := range machines.Rows {
		// machine.MustGet("MachineName").(string)
		machineName := U8ToGoString(machine.MustGet("MachineName").([]uint8))
		savePerfmonAsCsv(options.NoClobber, conn, machineName, ltRunId, resultFilePre)
	}

	log.Printf("[%s] Exporting finished correctly.\n", progname)
	return
}
コード例 #2
0
ファイル: OdbcTableOut.go プロジェクト: suntong/lang
func main() {
	connStr := "driver=sql server;server=(local);database=tempdb;trusted_connection=yes"
	if len(os.Args) > 1 && len(os.Args[1]) > 1 {
		connStr = os.Args[1]
	}

	fmt.Fprintf(os.Stderr, "\nProgram starts\n")

	//log.Printf("Connecting with '%s'\n", connStr)
	conn, err := sql.Open("odbc", connStr)
	if err != nil {
		fmt.Println("Connecting Error")
		return
	}
	defer conn.Close()

	connTbl := "sys.databases"
	if len(os.Args) > 2 {
		connTbl = os.Args[2]
	}
	table, err := table.Get(conn, "select * from "+connTbl)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Fprintf(os.Stderr, "\nDump table\n")
	dumpTable(table)
	fmt.Fprintf(os.Stderr, "\nFinished correctly\n")
	return
}
コード例 #3
0
ファイル: OdbcTable.go プロジェクト: suntong/lang
func testExec(conn *sql.DB) {
	table, err := table.Get(conn, "EXEC sp_executesql N'Select * from Instances(5)'")
	if err != nil {
		log.Fatal(err)
	}

	dumpTable(table)

}
コード例 #4
0
ファイル: OdbcTable.go プロジェクト: suntong/lang
/*

testTVF: to test Table-Valued Functions of MS SQL Server

Need to define the following in tempdb:

	Create Function Instances (@Bottom int)
	Returns Table
	As
	Return
	(
	select top 5 database_id, name, create_date from sys.databases WHERE database_id >= @Bottom
	)

Here is how to run:

	Select * from Instances(5)

*/
func testTVF(conn *sql.DB) {
	table, err := table.Get(conn, "Select * from Instances(?)", 5)
	if err != nil {
		log.Fatal(err)
	}

	dumpTable(table)

}
コード例 #5
0
ファイル: OdbcTable.go プロジェクト: suntong/lang
func main() {
	connStr := "driver=sql server;server=(local);database=tempdb;trusted_connection=yes;"
	if len(os.Args) > 1 {
		connStr = os.Args[1]
	}
	log.Printf("Connecting with '%s'\n", connStr)
	conn, err := sql.Open("odbc", connStr)
	if err != nil {
		fmt.Println("Connecting Error")
		return
	}
	defer conn.Close()

	r, err := table.Get(conn, "select top 5 database_id, name, create_date from sys.databases WHERE database_id >= ?", 1)
	if err != nil {
		log.Fatal(err)
	}

	dumpTable(r)

	r, err = table.Get(conn, "select top 5 database_id, name, create_date from sys.databases WHERE database_id = ?", 1)
	if err != nil {
		log.Fatal(err)
	}

	Id := r.MustGetScaler(0, "database_id")
	theId := int(Id.(int32))
	fmt.Printf("Id : %#v, %d\n", Id, theId)

	n0 := r.MustGetScaler(0, "name").(string)
	n := string(n0)
	fmt.Printf("Id : %#v, %s, %s\n", n0, n0, n)

	os.Exit(0)

	testTVF(conn)
	testExec(conn)
	testWeirdNames(conn)

	fmt.Fprintf(os.Stderr, "\nFinished correctly\n")
	return
}
コード例 #6
0
ファイル: OdbcTable.go プロジェクト: suntong/lang
// testWeirdNames
// Check for GO ODBC issue 23
// Ref: https://code.google.com/p/odbc/issues/detail?id=23
func testWeirdNames(conn *sql.DB) {
	table, err := table.Get(conn, "Select "+
		"'1' AS '(PDH-CSV 4.0) (Eastern Daylight Time)(240)', "+
		"'1' AS '\\\\MYDBSVR01\\Memory\\Available MBytes', "+
		"'1' AS '\\\\MYDBSVR01\\Memory\\Page Faults/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Memory\\Pages/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Memory\\% Committed Bytes In Use', "+
		"'1' AS '\\\\MYDBSVR01\\Memory\\Pool Paged Bytes', "+
		"'1' AS '\\\\MYDBSVR01\\Memory\\Pool Nonpaged Bytes', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Teredo Tunneling Pseudo-Interface)\\Current Bandwidth', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _38)\\Current Bandwidth', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _39)\\Current Bandwidth', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(isatap.dayforce.com)\\Current Bandwidth', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Teredo Tunneling Pseudo-Interface)\\Output Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _38)\\Output Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _39)\\Output Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(isatap.dayforce.com)\\Output Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Teredo Tunneling Pseudo-Interface)\\Bytes Total/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _38)\\Bytes Total/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _39)\\Bytes Total/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(isatap.dayforce.com)\\Bytes Total/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Teredo Tunneling Pseudo-Interface)\\Packets Sent/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _38)\\Packets Sent/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _39)\\Packets Sent/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(isatap.dayforce.com)\\Packets Sent/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Teredo Tunneling Pseudo-Interface)\\Bytes Sent/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _38)\\Bytes Sent/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _39)\\Bytes Sent/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(isatap.dayforce.com)\\Bytes Sent/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Teredo Tunneling Pseudo-Interface)\\Packets Received/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _38)\\Packets Received/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _39)\\Packets Received/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(isatap.dayforce.com)\\Packets Received/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Teredo Tunneling Pseudo-Interface)\\Bytes Received/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _38)\\Bytes Received/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _39)\\Bytes Received/sec', "+
		"'1' AS '\\\\MYDBSVR01\\Network Interface(isatap.dayforce.com)\\Bytes Received/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Avg. Disk sec/Read', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Avg. Disk sec/Read', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Avg. Disk sec/Read', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Disk Writes/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Disk Writes/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Disk Writes/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Disk Reads/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Disk Reads/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Disk Reads/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Disk Write Bytes/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Disk Write Bytes/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Disk Write Bytes/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\% Disk Read Time', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\% Disk Read Time', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\% Disk Read Time', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Avg. Disk Bytes/Write', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Avg. Disk Bytes/Write', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Avg. Disk Bytes/Write', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Avg. Disk sec/Transfer', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Avg. Disk sec/Transfer', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Avg. Disk sec/Transfer', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Disk Transfers/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Disk Transfers/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Disk Transfers/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Disk Read Bytes/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Disk Read Bytes/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Disk Read Bytes/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Disk Bytes/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Disk Bytes/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Disk Bytes/sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Avg. Disk Write Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Avg. Disk Write Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Avg. Disk Write Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\% Disk Write Time', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\% Disk Write Time', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\% Disk Write Time', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Current Disk Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Current Disk Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Current Disk Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Split IO/Sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Split IO/Sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Split IO/Sec', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\% Disk Time', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\% Disk Time', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\% Disk Time', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Avg. Disk Bytes/Read', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Avg. Disk Bytes/Read', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Avg. Disk Bytes/Read', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Avg. Disk Bytes/Transfer', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Avg. Disk Bytes/Transfer', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Avg. Disk Bytes/Transfer', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Avg. Disk Read Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Avg. Disk Read Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Avg. Disk Read Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Avg. Disk Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Avg. Disk Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Avg. Disk Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\% Idle Time', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\% Idle Time', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\% Idle Time', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(0 C: P: D:)\\Avg. Disk sec/Write', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(1 F:)\\Avg. Disk sec/Write', "+
		"'1' AS '\\\\MYDBSVR01\\PhysicalDisk(_Total)\\Avg. Disk sec/Write', "+
		"'1' AS '\\\\MYDBSVR01\\Processor(_Total)\\% Processor Time', "+
		"'1' AS '\\\\MYDBSVR01\\Processor(_Total)\\% Privileged Time', "+
		"'1' AS '\\\\MYDBSVR01\\Processor(_Total)\\% User Time', "+
		"'1' AS '\\\\MYDBSVR01\\System\\Processor Queue Length', "+
		"'1' AS '\\\\MYDBSVR01\\System\\Threads', "+
		"'1' AS '\\\\MYDBSVR01\\System\\Context Switches/sec', "+
		"'1' AS '\\\\MYDBSVR01\\System\\Processes', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlservr)\\Virtual Bytes', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlwriter)\\Virtual Bytes', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlservr)\\% User Time', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlwriter)\\% User Time', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlservr)\\Thread Count', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlwriter)\\Thread Count', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlservr)\\Working Set', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlwriter)\\Working Set', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlservr)\\% Privileged Time', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlwriter)\\% Privileged Time', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlservr)\\Private Bytes', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlwriter)\\Private Bytes', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlservr)\\Handle Count', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlwriter)\\Handle Count', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlservr)\\% Processor Time', "+
		"'1' AS '\\\\MYDBSVR01\\Process(sqlwriter)\\% Processor Time', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Access Methods\\Page Splits/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Access Methods\\Index Searches/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Access Methods\\Pages Allocated/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Access Methods\\Range Scans/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Access Methods\\Table Lock Escalations/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Access Methods\\Probe Scans/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Access Methods\\Full Scans/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(000)\\Free list empty/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(001)\\Free list empty/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(005)\\Free list empty/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(002)\\Free list empty/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(006)\\Free list empty/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(004)\\Free list empty/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(007)\\Free list empty/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(003)\\Free list empty/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(000)\\Free pages', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(001)\\Free pages', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(005)\\Free pages', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(002)\\Free pages', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(006)\\Free pages', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(004)\\Free pages', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(007)\\Free pages', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(003)\\Free pages', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(000)\\Free list requests/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(001)\\Free list requests/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(005)\\Free list requests/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(002)\\Free list requests/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(006)\\Free list requests/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(004)\\Free list requests/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(007)\\Free list requests/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Buffer Partition(003)\\Free list requests/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Databases(_Total)\\Log Flushes/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Databases(_Total)\\Transactions/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Databases(_Total)\\Log Cache Hit Ratio', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Databases(_Total)\\Active Transactions', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Databases(_Total)\\Log Cache Reads/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Databases(_Total)\\Log Truncations', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Databases(_Total)\\Log Flush Waits/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:General Statistics\\Logouts/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:General Statistics\\User Connections', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:General Statistics\\Logins/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Latches\\Average Latch Wait Time (ms)', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Latches\\Latch Waits/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Locks(_Total)\\Average Wait Time (ms)', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Locks(_Total)\\Lock Waits/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Locks(_Total)\\Lock Timeouts/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Locks(_Total)\\Number of Deadlocks/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:Locks(_Total)\\Lock Wait Time (ms)', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:SQL Statistics\\Failed Auto-Params/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:SQL Statistics\\SQL Re-Compilations/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:SQL Statistics\\SQL Compilations/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:SQL Statistics\\Unsafe Auto-Params/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:SQL Statistics\\Batch Requests/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:SQL Statistics\\Auto-Param Attempts/sec', "+
		"'1' AS '\\\\MYDBSVR01\\SQLServer:SQL Statistics\\Safe Auto-Params/sec'")
	if err != nil {
		log.Fatal(err)
	}

	dumpTable(table)

}
コード例 #7
0
ファイル: PunchGen.go プロジェクト: suntong/lang
func main() {
	flag.Usage = usage
	flag.Parse()

	// The cs, cd,dn & sd are mandatory flag
	// fmt.Fprintln(os.Stderr, progname, len(flag.Args()))
	if len(*fServer)*len(*fDb)*len(*fDeviceName)*len(*fStartDate) == 0 {
		if len(os.Args) > 1 {
			fmt.Fprintf(os.Stderr, "\n[%s] Error: not enough mandatory flag specified.\n",
				progname)
		}
		usage()
	}

	startDate, _ := time.Parse(formDate, *fStartDate)
	startTime, _ := time.Parse(formDate+formTime, *fStartDate+*fStartTime)
	durStartTime := startTime.Sub(startDate)
	_ = durStartTime

	// Construct the Go MSSQL odbc SqlConnectionString
	// https://code.google.com/p/odbc/source/browse/mssql_test.go
	var c string
	if *fSqlConnectionString == "" {
		var params map[string]string
		params = map[string]string{
			"driver":             "sql server",
			"server":             *fServer,
			"database":           *fDb,
			"trusted_connection": "yes",
		}

		for n, v := range params {
			c += n + "=" + v + ";"
		}

		log.Printf("[%s] Generating punches from %s@%s ",
			progname, *fDb, *fServer)

	} else {
		c = *fSqlConnectionString
		log.Printf("[%s] Generating punches from ConnectionString %s ",
			progname, *fSqlConnectionString)
	}
	// log.Println("Connection string: " + c)
	_startTime, _ := time.Parse(formTime, *fStartTime)

	conn, err := sql.Open("odbc", c)
	if err != nil {
		fmt.Println("Connecting Error")
		return
	}
	defer conn.Close()

	sql := badgeIdSql1 + *fEmpFilter + badgeIdSql2
	//log.Printf("[%s] SQL: %s ", progname, sql)

	badges, err := table.Get(conn, sql)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("[%s] Generating punches for %d people ... ",
		progname, len(badges.Rows))
	// log.Printf("[%s]  starting\n\t\t\t\t from %s\n\t\t\t\t to   %s",
	// progname, startTime.Format(formDate+"T"+formTime),
	// startTime.Add(*fDurGen).Format(formDate+"T"+formTime))
	log.Printf("[%s]  starting from %s to %s\n\t\t\t\t\t from  %s  to  %s",
		progname, startTime.Format(formDate),
		startTime.Add(*fDurGen).Format(formDate),
		_startTime.Format(formTime),
		_startTime.Add(*fDurShift).Format(formTime))

	fmt.Println("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<RawPunchImport>")
	for genDate := startDate; genDate.Before(startTime.Add(*fDurGen)); genDate = genDate.Add(durOneDay) {
		log.Printf("[%s]  generating for %s", progname, genDate.Format(formDate))

		for _, badge := range badges.Rows {
			badgeId := badge.MustGet("BadgeId").(string)
			// punch-in
			fmt.Printf("\t<RawPunch>\n\t\t<BadgeId>%s</BadgeId>"+
				"\n\t\t<DeviceName>%s</DeviceName>"+
				"\n\t\t<Time>%s</Time>"+
				"\n\t\t<Type>%d</Type>\n\t</RawPunch>\n",
				badgeId, *fDeviceName,
				startTime.Format(formDate+"T"+formTime+".000"), *fCodeIn)
			// punch-out
			fmt.Printf("\t<RawPunch>\n\t\t<BadgeId>%s</BadgeId>"+
				"\n\t\t<DeviceName>%s</DeviceName>"+
				"\n\t\t<Time>%s</Time>"+
				"\n\t\t<Type>%d</Type>\n\t</RawPunch>\n",
				badgeId, *fDeviceName,
				startTime.Add(*fDurShift).Format(formDate+"T"+formTime+".000"),
				*fCodeOut)
		}
	}
	fmt.Println("</RawPunchImport>")

	log.Printf("[%s] RawPunchXml generation finished correctly.\n", progname)
	return
}
コード例 #8
0
ファイル: perf_export.go プロジェクト: AntonioSun/lta
func savePerfmonAsCsv(fNoClobber bool, conn *sql.DB, machineName string, _runId int, resultFilePre string) {
	// Only use right(5)
	const keep = 5
	if len(machineName) > keep {
		machineName = machineName[len(machineName)-keep:]
	}

	log.Printf("[%s]   Collecting data for %s...\n", progname, machineName)

	// if no clobber and the destination file exists, skip
	if options.NoClobber {
		if _, err := os.Stat(resultFilePre + "-" + machineName + ".csv"); err == nil {
			log.Printf("[%s]   (Host %s skipped for no clobbering)\n",
				progname, machineName)
			return
		}
	}

	sql := fmt.Sprintf("exec TSL_prc_PerfCounterCollectionInCsvFormat"+
		" @RunId = %d, @InstanceName=N'\\\\%%%s\\%%'", _runId, machineName)
	//log.Println("] sql string: " + sql)
	table, err := table.Get(conn, sql)
	if err != nil {
		log.Printf("[%s]   Skipping it for the fatal error:\n\t\t    %v\n",
			progname, err.Error())
		return
	}

	log.Printf("[%s]   Exporting %s data...\n", progname, machineName)

	// open the output file
	file, err := os.Create(resultFilePre + "-" + machineName + ".csv")
	if err != nil {
		panic(err)
	}
	// close file on exit and check for its returned error
	defer func() {
		if err := file.Close(); err != nil {
			panic(err)
		}
	}()

	// output header
	for i, element := range table.ColumnName {
		if i != 0 {
			fmt.Fprintf(file, ",")
		}
		fmt.Fprintf(file, "\"%s\"", element)
	}
	fmt.Fprintf(file, "\n")

	// output body
	const layout = "01/02/2006 15:04:05.999"
	for j, row := range table.Rows {
		for i, colname := range table.ColumnName {
			if i != 0 {
				fmt.Fprintf(file, ",")
			}
			switch x := row.MustGet(colname).(type) {
			case string: // x is a string
				fmt.Fprintf(file, "\"%s\"", x)
			case int: // now x is an int
				fmt.Fprintf(file, "\"%d\"", x)
			case int32: // now x is an int32
				fmt.Fprintf(file, "\"%d\"", x)
			case int64: // now x is an int64
				fmt.Fprintf(file, "\"%d\"", x)
			case float32: // now x is an float32
				fmt.Fprintf(file, "\"%f\"", x)
			case float64: // now x is an float64
				fmt.Fprintf(file, "\"%f\"", x)
			case time.Time: // now x is a time.Time
				fmt.Fprintf(file, "\"%s\"", x.Format(layout))
			default:
				fmt.Fprintf(file, "\"%s\"", x)
			}
		}
		fmt.Fprintf(file, "\n")
		if j%options.Step == 0 {
			fmt.Fprintf(os.Stderr, ".")
		}
	}
	fmt.Fprintf(os.Stderr, "\n")

}
コード例 #9
0
ファイル: PerfCounterExport.go プロジェクト: suntong/lang
func main() {
	flag.Usage = usage
	flag.Parse()

	// The resultFilePre is a mandatory non-flag arguments
	if len(flag.Args()) < 1 {
		usage()
	}
	resultFilePre := flag.Args()[0]
	// if path only, append folder name as file prefix
	if *fPathOnly {
		resultFilePre += string(os.PathSeparator)
		resultFilePre = filepath.Dir(resultFilePre) +
			string(os.PathSeparator) + filepath.Base(resultFilePre)
		//log.Println("] resultFilePre=" + resultFilePre)
	}

	// Construct the Go MSSQL odbc SqlConnectionString
	// https://code.google.com/p/odbc/source/browse/mssql_test.go
	var c string
	if *fSqlConnectionString == "" {
		var params map[string]string
		params = map[string]string{
			"driver":             "sql server",
			"server":             *fServer,
			"database":           *fPerfDb,
			"trusted_connection": "yes",
		}

		for n, v := range params {
			c += n + "=" + v + ";"
		}
	} else {
		c = *fSqlConnectionString
	}
	log.Println("Connection string: " + c)

	conn, err := sql.Open("odbc", c)
	if err != nil {
		fmt.Println("Connecting Error")
		return
	}
	defer conn.Close()

	log.Printf("[%s] Program started\n", progname)

	if *fLoadTestRunId < 0 {
		// No Loadtest specified. Use Max RunId.
		runId, err := table.Get(conn,
			"SELECT MAX(LoadTestRunId) AS RunId from LoadTestRun")
		if err != nil {
			log.Fatal(err)
		}

		maxRunId := runId.MustGetScaler(0, "RunId")
		*fLoadTestRunId = int(maxRunId.(int32))
	}
	log.Printf("[%s] Exporting LoadTest %d\n  to %s-...\n  with progress step of %d\n",
		progname, *fLoadTestRunId, resultFilePre, *fStep)

	if *fMachineNameFilter != "" {
		fmt.Printf("  limiting to only export machine %s\n\n", *fMachineNameFilter)
		savePerfmonAsCsv(fNoClobber, conn, *fMachineNameFilter, *fLoadTestRunId, resultFilePre)
		os.Exit(0)
	}

	/*
			Get all machine names

		    SELECT  category.MachineName
		      FROM  LoadTestPerformanceCounterCategory AS category
		      JOIN  LoadTestPerformanceCounterInstance AS instance
		        ON  category.LoadTestRunId = instance.LoadTestRunId
		       AND  instance.LoadTestRunId = (
		            SELECT MAX(LoadTestRunId) from LoadTestRun )
		     GROUP  BY MachineName

	*/

	machines, err := table.Get(conn,
		"SELECT  category.MachineName"+
			"  FROM  LoadTestPerformanceCounterCategory AS category"+
			"  JOIN  LoadTestPerformanceCounterInstance AS instance"+
			"    ON  category.LoadTestRunId = instance.LoadTestRunId"+
			"   AND  instance.LoadTestRunId = ?"+
			" GROUP  BY MachineName", *fLoadTestRunId)
	if err != nil {
		log.Fatal(err)
	}

	for _, machine := range machines.Rows {
		machineName := machine.MustGet("MachineName").(string)
		savePerfmonAsCsv(fNoClobber, conn, machineName, *fLoadTestRunId, resultFilePre)
	}

	log.Printf("[%s] Exporting finished correctly.\n", progname)
	return
}