Перейти к содержимому

Как мониторить 1с кластер по пользователям с помощью grafana.

Задача мониторить 1с кластер в разрезе пользователей. Вытащить данные из Central 1c 8.3 servers

Как мониторить 1с кластер по пользователям с помощью grafana.

Создаем бузу на mssql monitoring

Потом создаем таблицу  sessions

create table sessions(
    [id serial] INT IDENTITY (1,1) PRIMARY KEY,
    [server] varchar(255) NOT NULL,
    [clock]  DATETIME NOT NULL DEFAULT (GETDATE()),
    [uuid] varchar(255) NOT NULL,
    [base] varchar(255),
    [user] varchar(255) ,
    [type] varchar(255) NOT NULL,
    [started] datetime,
    [last] datetime,
    [sleep] varchar(255),
    [current] bigint,
    [5min] bigint,
    [total] bigint,
    [duration_cur] bigint,
    [duration_db_cur] bigint
);

С помощью powershell записываем в таблицу

ping | Out-Null



$cluster = .\rac.exe cluster list | % {if ($_ -match 'cluster'){$_ -replace "^.*?: "}}
#$cluster
$racInfobases = .\rac.exe infobase --cluster=$cluster summary list
#.\rac.exe session
#.\rac.exe session --cluster=$cluster info --session=28e5603b-cb9c-449d-bcde-a2c843bd2d68

$sessionBase = @()
$infoBaseBase = @()


foreach ($racInfobase in $racInfobases)
{
    if ($racInfobase -match "infobase")
    {
        $infoBase = New-Object -TypeName PSObject
        $infoBase | Add-Member -Type NoteProperty -Name infobase -Value ([string]($racInfobase -replace "^.*?: "))
    }
    if ($racInfobase -match "name")
    {
        $infoBase | Add-Member -Type NoteProperty -Name name -Value ([string]($racInfobase -replace "^.*?: "))
        $infoBaseBase += $infoBase
    }
}
if ($debug -eq 1)
{
    $infoBaseBase | sort name | ft * -AutoSize
}

$racSessions = .\rac.exe session --cluster=$cluster list
Foreach($racSession in $racSessions)
{
    if ($racSession -match "session ")
    {
        if ($debug -eq 1)
        {
            $racSession -replace "^.*?: "
        }
        $Session = New-Object -TypeName PSObject
        $Session | Add-Member -Type NoteProperty -Name uid -Value ([string]($racSession-replace "^.*?: "))
    }
    elseif ($racSession -match "infobase")
    {
        $infoBaseUid = $racSession -replace "^.*?: "
        #$infoBaseUid
        $infoBaseName = $infoBaseBase | ? {$_.infobase -match "$infobaseUid"} | select -expand name
        #$infoBaseName
        $Session | Add-Member -Type NoteProperty -Name base -Value ([string]($infoBaseName))
    }
    elseif ($racSession -match "user.name")
    {
        $session | Add-Member -Type NoteProperty -Name user -Value ([string]($racSession-replace "^.*?: "))
    }
    elseif ($racSession -match "app-id")
    {
        $session | Add-Member -Type NoteProperty -Name type -Value ([string]($racSession-replace "^.*?: "))
    }
    elseif ($racSession -match "started.at")
    {
        $started = $racSession -replace "^.*?: "
        $session | Add-Member -Type NoteProperty -Name Started -Value ([string]($([datetime]$started).ToString("yyyy-MM-dd HH:mm:ss")))
    }
    elseif ($racSession -match "last.active.at")
    {
        $last = $racSession -replace "^.*?: "
        $session | Add-Member -Type NoteProperty -Name Last -Value ([string]($([datetime]$last).ToString("yyyy-MM-dd HH:mm:ss")))
    }
    elseif ($racsession -match "hibernate ")
    {
        if ($racsession -match "yes")
        {$Sleep = 1}
        elseif ($racsession -match "no")
        {$Sleep = 0}
        $session | Add-Member -Type NoteProperty -Name sleep -Value ([int]$Sleep)
    }
    elseif ($racSession -match "duration.current ")
    {
        $session | Add-Member -Type NoteProperty -Name dur_current -Value ([long]($racSession-replace "^.*?: "))
    }
    elseif ($racSession -match "duration.current-dbms")
    {
        $session | Add-Member -Type NoteProperty -Name dur_db_cur -Value ([long]($racSession-replace "^.*?: "))
    }
    elseif ($racSession -match "memory.current")
    {
        $session | Add-Member -Type NoteProperty -Name m_current -Value ([long]($racSession-replace "^.*?: "))
    }
    elseif ($racSession -match "memory.last")
    {
        $session | Add-Member -Type NoteProperty -Name m_5min -Value ([long]($racSession-replace "^.*?: "))
    }
    elseif ($racSession -match "memory.total")
    {
        if ($debug -eq 1)
        {
            $racSession
        }
        $session | Add-Member -Type NoteProperty -Name m_total -Value ([long]($racSession-replace "^.*?: "))
        $sessionBase += $session
    }
}
$sessionBase | sort M_Current | ft * -AutoSize

$dataSource = “db01.admin.ru”
$database = “monitoring”
$auth = “Integrated Security=SSPI;”
$connectionString = “Provider=sqloledb; ” +
“Data Source=$dataSource; ” +
“Initial Catalog=$database; ” +
“$auth; “
$connection = New-Object System.Data.OleDb.OleDbConnection $connectionString
$command = New-Object System.Data.OleDb.OleDbCommand $sql,$connection
$connection.Open()

foreach ($sOut in $sessionBase)
{
    if ($sOut){
    $values = "'$server','"+$sOut.uid+"','"+$sOut.base+"','"+$sOut.user+"','"+$sOut.type+"','"+$sOut.started+"','"+$sOut.last+"','"+$sOut.sleep+"','"+$sOut.dur_current+"','"+$sOut.dur_db_cur+"','"+$sOut.m_current+"','"+$sOut.m_5min+"','"+$sOut.m_total+"'"
    $values 
    
    $command.CommandText = "INSERT INTO [1c_monitoring].[dbo].[sessions] ([server],[uuid],[base],[user],[type],[started],[last],[sleep],[duration_cur],[duration_db_cur],[Current],[5min],[Total]) VALUES ($values);"
      $command.ExecuteNonQuery()                                                   
        }
}
#$Reader.Close()

$command = New-Object data.OleDb.OleDbCommand $sql
$command.connection = $connection

$Connection.Close()

Как мониторить 1с кластер по пользователям с помощью grafana.

 

Similar Posts:

Добавить комментарий

Ваш адрес email не будет опубликован.