แทรกผลลัพธ์ของกระบวนงานที่จัดเก็บไว้ในตารางชั่วคราวและตารางอุณหภูมิแบบสอบถาม
Aug 16 2020
ฉันมี proc ที่เก็บไว้ต่อไปนี้ซึ่งพยายามจะ:
- ดำเนินการขั้นตอนที่ระบบจัดเก็บ (sp_monitorconfig) และใส่ผลลัพธ์ที่กำหนดไว้ในตารางชั่วคราว
- เลือกจากตารางชั่วคราวนี้และเพิ่มคอลัมน์ที่กำหนดเอง 2 คอลัมน์ (SOURCESERVER & CollectionTime)
- ชุดผลลัพธ์สุดท้ายนี้จะถูกส่งเข้าสู่ Logstash ผ่าน jdbc job
ฉันกำลังใช้ SAP ASE 16 (Sybase) และกำลังรับข้อผิดพลาดที่ไม่ถูกต้องไวยากรณ์ที่คำว่า 'exec' ฉันไม่แน่ใจว่าฉันต้องนำหน้า proc ที่เก็บไว้หรืออะไร แต่ตอนนี้ฉันนิ่งงันและขอความช่วยเหลือใด ๆ
USE db
GO
CREATE PROCEDURE sp_active_con_ratio.sql AS
DECLARE @servername varchar(32) DECLARE @collecttime DATETIME DECLARE @procparam varchar(32)
select
@servername = @@servername
select
@collecttime = getdate()
select
@procparam = 'number of user connections' CREATE TABLE #TempUserConnections
(
TempName varchar(35),
FreeConnections int,
ActiveConnections int,
PercentActive char(6),
MaxUsed int,
Reuse_cnt int,
Instance_Name varchar(30) NULL
)
INSERT INTO
#TempUserConnections (TempName, FreeConnections, ActiveConnections, PercentActive, MaxUsed, Reuse_cnt, Instance_Name)
exec sp_monitorconfig @procparam **ERROR HERE**
SELECT
@servername AS 'SOURCESERVER',
FreeConnections,
ActiveConnections,
PercentActive,
MaxUsed,
@collecttime AS 'CollectionTime'
FROM
#TempUserConnections
DROP TABLE #TempUserConnections
RETURN
GO
ขอบคุณ!
คำตอบ
markp-fuso Aug 17 2020 at 00:28
ฉันลืมไปว่าsp_monitorconfig
มีพารามิเตอร์อินพุตที่เป็นทางเลือก ( @result_tbl_name
) ที่อนุญาตให้ตัวดำเนินการกำหนดตารางที่ควรแทรกผลลัพธ์
จากเอกสารเกี่ยวกับsp_monitorconfigตัวอย่าง # 8 ...
ขั้นแรกให้สร้างตารางเพื่อเก็บผลลัพธ์ ในขณะที่ชื่อตารางอาจแตกต่างกันไปคุณจะต้องเก็บชื่อคอลัมน์ / ประเภทข้อมูลตามที่กำหนดไว้:
create table sample_table
(Name varchar(35),
Config_val int,
System_val int,
Total_val int,
Num_free int,
Num_active int,
Pct_act char(6),
Max_Used int,
Reuse_cnt int,
Date varchar(30),
Instance_Name varchar(35))
ในการจับเมตริกสองสามรายการ:
exec sp_monitorconfig "locks", sample_table
exec sp_monitorconfig "number of alarms", sample_table
เมตริกการแสดงผล:
-- select * from sample_table
exec sp_autoformat sample_data
go
sp_autoformat sample_table
2> go
Name Config_val System_val Total_val Num_free Num_active Pct_act Max_Used Reuse_cnt Date Instance_Name
---------------- ---------- ---------- --------- -------- ---------- ------- -------- --------- ------------------- -------------
number of locks 10000 942 10000 9717 283 2.83 308 0 Aug 16 2020 12:26PM
number of alarms 400 0 400 386 14 3.50 14 0 Aug 16 2020 12:26PM