public static List<AvailabilityGroupReplicaInfo> PopulateFromConnection(DbConnection conn, SQLNode node) { List<AvailabilityGroupReplicaInfo> groups; List<DatabaseReplicaState> databases; var sql = node.GetFetchSQL<AvailabilityGroupReplicaInfo>() + "\n\n" + node.GetFetchSQL<DatabaseReplicaState>(); using (var multi = conn.QueryMultiple(sql)) { groups = multi.Read<AvailabilityGroupReplicaInfo>().ToList(); databases = multi.Read<DatabaseReplicaState>().ToList(); } Func<string, string, PerfCounterRecord> getCounter = (cn, n) => node.GetPerfCounter("Availability Replica", cn, n); groups.ForEach(r => { r.Databases = databases.Where(gdb => r.GroupId == gdb.GroupId && r.ReplicaId == gdb.ReplicaId).ToList(); var instanceName = r.AvailabilityGroupName + ":" + r.ReplicaServerName; var sc = getCounter("Bytes Sent to Transport/sec", instanceName); if (sc != null) { r.BytesSentPerSecond = sc.CalculatedValue; r.BytesSentTotal = sc.CurrentValue; } var rc = getCounter("Bytes Received from Replica/sec", instanceName); if (rc != null) { r.BytesReceivedPerSecond = rc.CalculatedValue; r.BytesReceivedTotal = rc.CurrentValue; } }); return groups; }
public static List <AvailabilityGroupReplicaInfo> PopulateFromConnection(DbConnection conn, SQLNode node) { List <AvailabilityGroupReplicaInfo> groups; List <DatabaseReplicaState> databases; var sql = node.GetFetchSQL <AvailabilityGroupReplicaInfo>() + "\n\n" + node.GetFetchSQL <DatabaseReplicaState>(); using (var multi = conn.QueryMultiple(sql)) { groups = multi.Read <AvailabilityGroupReplicaInfo>().ToList(); databases = multi.Read <DatabaseReplicaState>().ToList(); } Func <string, string, PerfCounterRecord> getCounter = (cn, n) => node.GetPerfCounter("Availability Replica", cn, n); groups.ForEach(r => { r.Databases = databases.Where(gdb => r.GroupId == gdb.GroupId && r.ReplicaId == gdb.ReplicaId).ToList(); var instanceName = r.AvailabilityGroupName + ":" + r.ReplicaServerName; var sc = getCounter("Bytes Sent to Transport/sec", instanceName); if (sc != null) { r.BytesSentPerSecond = sc.CalculatedValue; r.BytesSentTotal = sc.CurrentValue; } var rc = getCounter("Bytes Received from Replica/sec", instanceName); if (rc != null) { r.BytesReceivedPerSecond = rc.CalculatedValue; r.BytesReceivedTotal = rc.CurrentValue; } }); return(groups); }