-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsp_graphitesend.sql
81 lines (75 loc) · 2.48 KB
/
sp_graphitesend.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
USE [master]
GO
-- enable 'TRUSTWORTHY'
-- required for 'external access' of clr code (-> sending tcp packets).
ALTER DATABASE [master] SET TRUSTWORTHY ON;
GO
-- enable clr code
EXEC sp_configure 'clr enabled', 1
GO
RECONFIGURE
GO
-- Check if procedure and assembly already exist and drop them
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_graphitesend]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_graphitesend]
GO
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_graphitesendseries]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].sp_graphitesendseries
GO
IF EXISTS (SELECT * FROM sys.assemblies WHERE name = N'Graphite.TSql')
DROP ASSEMBLY [Graphite.TSql]
GO
-- Add Graphite.TSql.dll assembly
CREATE ASSEMBLY [Graphite.TSql]
AUTHORIZATION [dbo]
FROM '<your/path/to/Graphite.TSql.dll>'
WITH PERMISSION_SET = EXTERNAL_ACCESS
GO
-- Create stored procedure 'sp_graphitesend'
CREATE PROCEDURE sp_graphitesend
(
@host nvarchar(255),
@port int,
@key nvarchar(255),
@value int
)
AS
EXTERNAL NAME [Graphite.TSql].[Graphite.TSql.GraphiteProcedures].GraphiteSend
GO
-- --------------------------------------------------------------------------
-- Example usage:
--
-- EXEC sp_graphitesend N'192.168.0.1', 2003, 'stats.events.myserver.test', 1
--
-- --------------------------------------------------------------------------
GO
-- Create stored procedure 'sp_graphitesendseries'
CREATE PROCEDURE sp_graphitesendseries
(
@host nvarchar(255),
@port int,
@points NVARCHAR(MAX),
@returnstring NVARCHAR(MAX) OUTPUT
)
AS
EXTERNAL NAME [Graphite.TSql].[Graphite.TSql.GraphiteProcedures].GraphiteSendSeries
GO
-- --------------------------------------------------------------------------
-- Example usage:
-- Send several series points to graphite to optimize clr by using xml syntax.
-- CREATE TABLE #GraphiteTable ([key] nvarchar(255), value INT );
--
-- INSERT INTO #GraphiteTable VALUES ('stats.events.myserver.test', 15);
-- INSERT INTO #GraphiteTable VALUES ('stats.events.myserver.test1', 12);
-- INSERT INTO #GraphiteTable VALUES ('stats.events.myserver.test2', 87);
--
-- DECLARE @outputString NVARCHAR(MAX)
-- DECLARE @inputString NVARCHAR(MAX)
-- SET @inputString = (SELECT * FROM #GraphiteTable FOR XML PATH('Points'), ROOT('Root'))
-- EXEC sp_graphitesendseries N'192.168.0.1', 2003, @inputString, @outputString OUT
-- SELECT @outputString
--
-- DROP TABLE #GraphiteTable;
--
-- --------------------------------------------------------------------------
GO