1

I am currently using sp_user_counter1 to store database information on Perfmon, which can be recovered by AWS CloudWatch, but the values are Decimal, and the sp_user_counter1 parameter supplied must be an int.

So when I give the stored procedure a value of 12.34567 it report 12.00000 to the perfmon counter....

The sp code is:

 CREATE PROCEDURE sys.sp_user_counter1 @newvalue INT AS
 DBCC setinstance ('SQLServer:User Settable', 'Query', 'User counter 1', @newvalue)

Can I just call DBCC setinstance and give it the decimal value??? I never tried this because I didnt found anyone doing this, I dont know the consequences....

Can this be done?? Is this secure??

Here is the User Setabble documentation: https://msdn.microsoft.com/en-us/library/ms187480.aspx

asked Apr 14, 2016 at 19:51

1 Answer 1

0

Running this:

CREATE PROCEDURE dbo.set_user_counter1 
(
 @newvalue DECIMAL(18,2)
)
AS
BEGIN
 DBCC setinstance (
 'SQLServer:User Settable'
 , 'Query'
 , 'User counter 1'
 , @newvalue
 );
END;
GO
EXEC dbo.set_user_counter1 12.5

results in:

Msg 2560, Level 16, State 9, Procedure set_user_counter1, Line 7
Parameter 4 is incorrect for this DBCC statement.

Running the following shows you the "help" entry for the DBCC setinstance:

DBCC TRACEON (2588); /* show DBCC Help */
DBCC TRACEON (2520); /* show undocumented command help */
DBCC HELP ('setinstance')

This returns:

dbcc setinstance (objectname, countername, instancename, value)

DBCC execution completed. If DBCC printed error messages, contact your system administrator.

Unfortunately, that is no help determining if value can only be an int.

In fact, the MSDN page you linked states the following:

A counter can monitor any single integer value

answered Apr 14, 2016 at 20:06
1
  • 1
    Oh perfect, I think I will do the bad way, multiplying by 1000 and then dividing by 1000 when retrieving the counter... Commented Apr 14, 2016 at 21:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.