在上一篇文章中,我们使用Grafana从SQL Server的表中取数,然后通过Dashboard实现了对Lync/Skype服务器的实时会议以及用户数的监控。那么在本篇文章中,我们将继续使用Grafana来实现对Lync/Skype服务器的点对点(Peer-to-Peer)的通话质量数据进行监控。
如何使用Grafana监控Lync/Skype服务器的实时会议数
Skype服务器的实时会议数来源
Skype的通话质量数据存储在后端数据库,我们可以使用内置的视图QoEReportsCallDetailView来获取到这些数据。
点对点(Peer-to-Peer)通话质量数据获取
第一次筛选 - 获取点对点数据以及通话方向
虽然内置的视图QoEReportsCallDetailView可以满足我们的取数需求,但由于点对点的通话与会议的通话均存储在此视图中,并且每通点对点通话均有两个方向(主叫->被叫,被叫->主叫),所以我们需要对数据进行一些筛选以获得我们想要的数据,语句如下:
--定义取数时间间隔
declare @date1 datetime
declare @date2 datetime
set @date1 = (SELECT DATEADD(minute,-5,GETUTCDATE()))
set @date2 = (SELECT GETUTCDATE());
SELECT
StartTime,
EndTime,
AudioSenderIsCallerPAI,
CallerPAI,
CalleePAI,
CallerSubnet,
CalleeSubnet,
--定义通话质量好坏
CASE When
AudioRoundTrip > '500'
or AudioJitterInterArrival > '30'
or AudioDegradationAvg > '1'
or AudioRatioConcealedSamplesAvg > '0.07'
or AudioPacketLossRate > '0.1'
Then '1'
Else '0'
End AS ClassifiedPoorCall,
--定义通话方向
Case When
AudioSenderIsCallerPAI = '1'
Then 'Caller'
Else 'Callee'
End AS Role
From QoEReportsCallDetailView
where StartTime > @date1 and StartTime < @date2
--排除会议数据
and CallerURI not like '%:id:%'
and CalleeURI not like '%:id:%'
and AudioSenderIsCallerPAI is not NULL
定义取数时间间隔的目的:
- 减少查询时间,保证数据的时效性。
- ”少量多次“取数,防止影响后端SQL Server数据库性能
运行以上语句,我们就可以得到一个类似如下的查询结果:
之后我们即可和之前一样,将这些数据存储在一个新的SQL表中,由于创建表格的方法在本系列文章的第一,二篇均有讲述,本文将不再赘述,仅展示使用Powershell脚本将数据导入SQL的方法,脚本如下:
#Connect to SQL database
Function SQLConnectionWindows
{
param
(
[string]$server,
[string]$database
)
$SQLCon = New-Object System.Data.SqlClient.SqlConnection
$SQLCon.ConnectionString = "Data Source=$server;Initial Catalog=$database;Integrated Security=SSPI;"
try
{
$SQLCon.Open()
return $SQLCon
}
catch [exception]
{
Write-Warning ('Connect to database failed with error message:{0}' -f ,$_)
$SQLCon.Dispose()
return $null
}
}
Function SQLConnectionSQL
{
param
(
[string]$server,
[string]$database,
[string]$uid,
[string]$pwd
)
$SQLCon = New-Object System.Data.SqlClient.SqlConnection
$SQLCon.ConnectionString = "Data Source=$server;Initial Catalog=$database;User ID=$uid;pwd=$pwd;"
try
{
$SQLCon.Open()
return $SQLCon
}
catch [exception]
{
Write-Warning ('Connect to database failed with error message:{0}' -f ,$_)
$SQLCon.Dispose()
return $null
}
}
Function SQLCommand
{
param
(
[System.Data.SqlClient.SqlConnection]$SQLConnection,
[string]$command
)
$dataset = New-Object System.Data.DataSet
$dataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter($command,$SQLConnection)
$dataAdapter.Fill($dataset) | Out-Null
return $dataset.Tables[0]
}
$SQLServer = 'SkypeBackendSqlServer'
$SQLDBName = 'QoEMetrics'
$Cred = 'Password'
$conn = SQLConnectionWindows -server $SQLServer -database $SQLDBName -uid 'UserName' -pwd $Cred
$SqlQuery = "
--定义取数时间间隔
declare @date1 datetime
declare @date2 datetime
set @date1 = (SELECT DATEADD(minute,-5,GETUTCDATE()))
set @date2 = (SELECT GETUTCDATE());
SELECT
StartTime,
EndTime,
AudioSenderIsCallerPAI,
CallerPAI,
CalleePAI,
CallerSubnet,
CalleeSubnet,
--定义通话质量好坏
CASE When
AudioRoundTrip > '500'
or AudioJitterInterArrival > '30'
or AudioDegradationAvg > '1'
or AudioRatioConcealedSamplesAvg > '0.07'
or AudioPacketLossRate > '0.1'
Then '1'
Else '0'
End AS ClassifiedPoorCall,
--定义通话方向
Case When
AudioSenderIsCallerPAI = '1'
Then 'Caller'
Else 'Callee'
End AS Role
From QoEReportsCallDetailView
where StartTime > @date1 and StartTime < @date2
--排除会议数据
and CallerURI not like '%:id:%'
and CalleeURI not like '%:id:%'
and AudioSenderIsCallerPAI is not NULL
"
$DataTables = SQLCommand -SQLConnection $conn -command $SqlQuery
$Server = 'SqlServerName'
$DBName = 'DBName'
$userName = "UserName"
$Cred = 'Password'
$Newconn = SQLConnectionSQL -server $Server -database $DBName -uid $userName -pwd $Cred
#更新至数据库
$bulkCopy = new-object ("Data.SqlClient.SqlBulkCopy") $Newconn
$bulkCopy.DestinationTableName = "Skype_P2P_Original_Data"
$bulkCopy.WriteToServer($DataTables)
第二次筛选 - 定义通话位置
当我们进行第一次筛选后,可以看到我们获取到了点对点呼叫的一些关键数据:
- 主叫子网
- 被叫子网
- 通话方向
- 通话质量好坏
那么接下来,我们就可以对这些数据进行二次筛选,以定义呼叫所属位置。
导入子网数据
在一个大型企业,涉及到的网段非常复杂,为了简化操作,我们可以预先将这些网段及其对应的位置信息导入在SQL表中,以供之后取数使用,示例如下:
判断通话位置
当子网数据导入后,我们就可以使用如下SQL语句来判断通话的位置:
declare @date1 datetime
declare @date2 datetime
set @date1 = (SELECT DATEADD(minute,-5,GETUTCDATE()))
set @date2 = (SELECT GETUTCDATE());
SELECT
StartTime,
EndTime,
AudioSenderIsCallerPAI,
CallerPAI,
CalleePAI,
CallerSubnet,
CalleeSubnet,
ClassifiedPoorCall,
Role,
--判断城市--
---根据主叫子网以及呼叫方向定义城市1---
When
CallerSubnet in (select Address from [DBNa].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where City = '城市1')
and AudioSenderIsCallerPAI = '1'
Then '城市1'
---根据主叫子网以及呼叫方向定义城市2---
When
CallerSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where City = '城市2')
and AudioSenderIsCallerPAI = '1'
Then '城市2'
---根据被叫子网以及呼叫方向定义城市1---
When
CalleeSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where City = '城市1')
and AudioSenderIsCallerPAI = '0'
Then '城市1'
---根据被叫子网以及呼叫方向定义城市2---
When
CalleeSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where City = '城市2')
and AudioSenderIsCallerPAI = '0'
Then '城市2'
---根据主叫子网以及呼叫方向定义城市1中的Plant---
Case When
CallerSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant1')
and AudioSenderIsCallerPAI = '1'
Then 'Plant1'
When
CallerSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant2')
and AudioSenderIsCallerPAI = '1'
Then 'Plant2'
---根据主叫子网以及呼叫方向定义城市2中的Plant---
When
CallerSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant1')
and AudioSenderIsCallerPAI = '1'
Then 'Plant1'
When
CallerSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant2')
and AudioSenderIsCallerPAI = '1'
Then 'Plant2'
---根据被叫子网以及呼叫方向定义城市1中的Plant---
When
CalleeSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant1')
and AudioSenderIsCallerPAI = '0'
Then 'Plant1'
When
CalleeSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant2')
and AudioSenderIsCallerPAI = '0'
Then 'Plant2'
---根据被叫子网以及呼叫方向定义城市2中的Plant---
When
CalleeSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant1')
and AudioSenderIsCallerPAI = '0'
Then 'Plant1'
When
CalleeSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant2')
and AudioSenderIsCallerPAI = '0'
Then 'Plant2'
ELSE
'Internet'
End AS 'Plant'
From [DBName].[dbo].[Skype_02_P2P_Original_Data]
where StartTime > @date1 and StartTime < @date2
运行以上语句,我们就可以得到一个类似如下的查询结果:
之后我们即可将这些数据存储在新的SQL表中,使用Powershell脚本将数据导入SQL的方法脚本如下:
#Connect to SQL database
Function SQLConnectionSQL
{
param
(
[string]$server,
[string]$database,
[string]$uid,
[string]$pwd
)
$SQLCon = New-Object System.Data.SqlClient.SqlConnection
$SQLCon.ConnectionString = "Data Source=$server;Initial Catalog=$database;User ID=$uid;pwd=$pwd;"
try
{
$SQLCon.Open()
return $SQLCon
}
catch [exception]
{
Write-Warning ('Connect to database failed with error message:{0}' -f ,$_)
$SQLCon.Dispose()
return $null
}
}
Function SQLCommand
{
param
(
[System.Data.SqlClient.SqlConnection]$SQLConnection,
[string]$command
)
$dataset = New-Object System.Data.DataSet
$dataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter($command,$SQLConnection)
$dataAdapter.Fill($dataset) | Out-Null
return $dataset.Tables[0]
}
$Server = 'SqlServer'
$DBName = 'DBName'
$userName = "UserName"
$Cred = 'Password'
$conn = SQLConnectionSQL -server $Server -database $DBName -uid $userName -pwd $Cred
$SqlQuery = "
declare @date1 datetime
declare @date2 datetime
set @date1 = (SELECT DATEADD(minute,-5,GETUTCDATE()))
set @date2 = (SELECT GETUTCDATE());
SELECT
StartTime,
EndTime,
AudioSenderIsCallerPAI,
CallerPAI,
CalleePAI,
CallerSubnet,
CalleeSubnet,
ClassifiedPoorCall,
Role,
--判断城市--
---根据主叫子网以及呼叫方向定义城市1---
When
CallerSubnet in (select Address from [DBNa].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where City = '城市1')
and AudioSenderIsCallerPAI = '1'
Then '城市1'
---根据主叫子网以及呼叫方向定义城市2---
When
CallerSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where City = '城市2')
and AudioSenderIsCallerPAI = '1'
Then '城市2'
---根据被叫子网以及呼叫方向定义城市1---
When
CalleeSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where City = '城市1')
and AudioSenderIsCallerPAI = '0'
Then '城市1'
---根据被叫子网以及呼叫方向定义城市2---
When
CalleeSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where City = '城市2')
and AudioSenderIsCallerPAI = '0'
Then '城市2'
---根据主叫子网以及呼叫方向定义城市1中的Plant---
Case When
CallerSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant1')
and AudioSenderIsCallerPAI = '1'
Then 'Plant1'
When
CallerSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant2')
and AudioSenderIsCallerPAI = '1'
Then 'Plant2'
---根据主叫子网以及呼叫方向定义城市2中的Plant---
When
CallerSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant1')
and AudioSenderIsCallerPAI = '1'
Then 'Plant1'
When
CallerSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant2')
and AudioSenderIsCallerPAI = '1'
Then 'Plant2'
---根据被叫子网以及呼叫方向定义城市1中的Plant---
When
CalleeSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant1')
and AudioSenderIsCallerPAI = '0'
Then 'Plant1'
When
CalleeSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant2')
and AudioSenderIsCallerPAI = '0'
Then 'Plant2'
---根据被叫子网以及呼叫方向定义城市2中的Plant---
When
CalleeSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant1')
and AudioSenderIsCallerPAI = '0'
Then 'Plant1'
When
CalleeSubnet in (select Address from [DBName].[dbo].[Skype_EnterpriseVoice_Subnet_Map] where Plant = 'Plant2')
and AudioSenderIsCallerPAI = '0'
Then 'Plant2'
ELSE
'Internet'
End AS 'Plant'
From [DBName].[dbo].[Skype_P2P_Original_Data]
where StartTime > @date1 and StartTime < @date2
"
$DataTables = SQLCommand -SQLConnection $conn -command $SqlQuery
#更新至数据库
$bulkCopy = new-object ("Data.SqlClient.SqlBulkCopy") $conn
$bulkCopy.DestinationTableName = "Skype_Result_Data"
$bulkCopy.WriteToServer($DataTables)
创建自动化任务计划(Task Schedule)
在上面的步骤中,我们使用了2个脚本:
- 脚本1:从Skype后端数据库获取到点对点呼叫数据,存储在SQL表1中。
- 脚本2:对SQL表1中的数据进行处理,判断位置信息,存储再SQL表2中。
所以我们需要分别创建2个任务计划,以调用前文中的脚本,将数据每隔5分钟将数据导入到SQL表中。由于任务计划在此系列前两篇文章中已经有所展示,将不在此文中赘述。
在Grafana中创建Dashboard
我们导航到Grafana Dashboard界面,之后点击左侧的➕:
在弹出的New Panel界面,选择Add Query:
我们在Query的配置界面,选择之前添加的对应的SQL数据源,之后分别输入两条SQL查询语句,这两条语句分别对应点对点通话质量好坏,之后选择时序(Time series)格式:
Query 1
select count(*) as 'Good', $__timeEpoch(StartTime)
from
(
select * from [DBName].[dbo].[Skype_Result_Data]
Where Plant = 'Location'
and ClassifiedPoorCall = '0'
) as tmp
where $__timeFilter(StartTime)
group by StartTime
Query 2
select count(*) as 'Poor', $__timeEpoch(StartTime)
from
(
select * from [DBName].[dbo].[Skype_Result_Data]
Where Plant = 'Location'
and ClassifiedPoorCall = '1'
) as tmp
where $__timeFilter(StartTime)
group by StartTime
在Visualization界面,我们选择Pie Chart,并进行如下配置:
在General界面,为Dashboard起一个Title,之后保存:
之后我们将得到下面的一个Dashboard:
Dashboard最终效果展示
同时我们可以根据保存在SQL表中的点对点通话质量和位置数据,来生成多个类似的图形,之后将其整合。在展示某个城市总数据的同时,也能看到各个plant的数据,类似效果如下:
本章总结
在此篇文章中,我们了解了:
- 如何获取Skype点对点呼叫数据
- 如何对数据进行二次处理并导入SQL Server表
- 如何通过Grafana展示点对点呼叫质量
在此系列文章的下一部分,我们将继续使用Grafana来展示Skype会议(Conference)的通话质量数据。
标签:dbo,where,Lync,Grafana,---,Skype,AudioSenderIsCallerPAI,DBName From: https://blog.51cto.com/fantacyzmr/6148337