- 
  StackOverflow 文档
 
- 
  Bosun 教程
 
- 
  Scollector 外部收集器
 
- 
  Powershell 外部收集器脚本功能
 
<#
    .DESCRIPTION
        Writes the metric out in bosun external collector format which is compatible with scollector external scripts
    .PARAMETER metric
        Name of the metric (eg : my.metric)
    .PARAMETER type
        Type of metric (counter, gauge, etc)
    .PARAMETER unit
        Type of unit (connections, operations, etc)
    .PARAMETER desc
        Description of the metric
    .PARAMETER value
        The current value for the metric
#>
function Write-Metric
{
param(
    [string]$metric,
    [string]$type,
    [string]$unit,
    [string]$desc,
    $value
)
$epoch = New-Object DateTime (1970,1,1)
$obj = @{
    metric = $metric
    name = "rate"
    value = $type
}
Write-Host (ConvertTo-Json $obj -Compress)
$obj.name="unit"
$obj.value=$unit
Write-Host (ConvertTo-Json $obj -Compress)
$obj.name="desc"
$obj.value=$desc
Write-Host (ConvertTo-Json $obj -Compress)
$output = @{
    metric = $metric
    timestamp= [int]([datetime]::UtcNow.Subtract($epoch).TotalSeconds)
    value=$value
    tags= @{
        host=$env:computername.ToLower()
    }
}
Write-Host (ConvertTo-Json $output -Compress)
}