Windows Service and Performance Info using C# - c#

We have hundreds of database and application servers in our datacenter and we are currently using various third party tools to monitor. All appear to have their stengths and weaknesses.
I would like to create a simple Windows Service using C# that can check the most common performance counters on a Windows system every 5 mins or so and upload the results to a WCF service.
My questions are:
1) Having never worked with Performance Counters in .NET, is this something that is fairly simple to do?
2) Are there any permission issues I need to concern myself with? The service will likely be running under "localsystem" or a domain user account.
3) What are the common performance counters I should be looking for... Memory, CPU, Disk?
4) Has anyone else written code similar to this and do they have any examples to get me started?
Any help would be appreciated.

Monitoring performance counters isn't hard using .NET however I recommend using existing tools (such as SCOM) that will do exactly this for you.

In case others may find this useful (or myself in the future) ;)
Yes - Performance Counters
Unfortunately I don't know the answer to this one, but I'll update if I learn it. :D
This will depend on the context. You will likely want to monitor slightly different counters for Database servers vs Application servers. There are many excellent resources on this.
Here are a couple key files I found on various projects on Github. They may not be ideal, or reflect the above articles, but they give an idea on the structure. You can also refer to the examples in the official documentation on the PerformanceCounter Class.
TelemetryInstrumentService.cs by Scott DeHaan
CounterWatcher.cs by CryptonZylog

Related

Simulate load and analyze for a .net web service and SQL server

Here is my scenario, I developed an android application that periodically makes calls to a web service, which in turn performs queries against a database. In the field there will be hundreds of these devices running constantly polling roughly every 60 seconds. There are some concerns about efficiency due to the volume and frequency of use and I have been told to find any potential performance issues and come up with strategies to combat them. (All I've seen is issues with heavily fragmented indexes)
So my questions to you are:
What are some ways of simulating load on a web service?
With SQL - I am familiar with examining execution plans, is there anything beyond that I should be concerned with?
How do I measure the 'efficiency' of a .net web service? What kinds of things should I be on the lookout for? Is there a tool I can use to see hot spots and potential bottlenecks?
I appreciate any resources and insight you can provide, thanks!
If you have access to an MSDN Ultimate license you can use the load test projects that are built into Visual Studio. Using their load tests you can run whatever load test you engineer and it records performance data so you can see the impact during the test.
http://www.microsoft.com/visualstudio/eng/products/compare
In the Feature Comparison > Testing Tools section they have a video covering load testing.
If your web service is running over HTTP (which is likely), than most web load testing software has the capability to do what you need. A few of them can even record traffic from a local Android device, which you can then customize to generated the load you need.
I'll suggest our own product, Load Tester LITE, which may be able to do everything you need for free. The recording ability depends on the specific version of Android you have available - our support guys will be happy to help you work through it.

Lightweight profiling for Silverlight?

I would like to profile certain actions in my application in a production environment.
I have previously used Stopwatch in .NET
It does not seem to exist in Silverlight (despite being in the documentation).
Can anyone suggest some alternatives? Is there anything better than DateTime.UtcNow?
I have used Yourkit and use ANTs in development, but I would like to gather information about performance of deployed software. I do not have access to the kind of data the users have, but can gather some logging.
Is this post any use at all?
It sounds like you want to deploy profiling IN your application so you can see how it performs on the user's PC?
Firstly you could have a look at this answer. Standard timers (eg looking at the value of DateTime.Now) are only going to give you rough resolution, which seems to be around 16ms at best.
Otherwise you can grab a performance profiling tool, there are several now which work out of the box with Silverlight, are easy enough to use and don't really take that long to get started with, with free evaluations. Two such tools JetBrains dotTrace and RedGate ANTS
Have you looked at this question: How to profile a silverlight application?
Are you looking for something other than this?
Telerik also has a pretty fantastic product for profiling named : JustTrace
JustTrace enables the profiling of local applications, running applications, Silverlight applications and local ASP .NET web site.

monitor internet usage in .net

I want to write a method in C# to check which applications in my machine/server are using internet connection at a particular point in time and if possible, how much bandwidth they are using. Can anyone please help me get a head start on this?
I decided to write an answer because comments are too small.
Well, reading other Q&A on stackoverflow and looking around on the internet, I didn't find a simple solution for your problem.
Actually, for .NET processes is really simple, you just need to retrieve informations from ".NET CLR Networking - Bytes Received/Bytes Sent" performance counters, as shown in this Q&A
But in general, getting per-process used bandwidth isn't an easy work.
For example "Microsoft Network Monitor" sniffer can trace the process that generates internet packets only for TCP traffic, because probably it maps IP-port pairs with processes using them (or something similar, TCP is a connected protocol so it is simpler).
Anyway if you want to give it a try you can use the exposed API (look at this blog entry for some hint).
However, as suggested in these Q&A's (LINK 1, LINK 2), the right, and probably the only way, is to write a NDIS/TDI driver that can intercept network traffic and exposing a .NET callable API to it.
The problem is that such drivers can't be written in managed code, and so you need to implement it in C/C++.
Obviously, if you manage to find an already written driver/sniffer exposing a callable API, you can use it.
For example WinPCap has one (and some .NET wrappers like SharpPCap or PCap.Net), but I don't think (not sure) it's able to get packets's source-process information.
As digEmAll noted, in pre-Vista Windows you are reduced to writing your own driver or using a 3-rd party one. In Vista, 2008 and Windows 7 you can use the GetPerTcpConnectionEStats API (there is a large example of its usage on the MSDN page). Resource Monitor relies on this API, together with the older GetTcpTable/GetTcpRow APIs, for extended network statistics.
I found Process Monitor as a very useful tool and it served my purpose so I didnt had to write any code although i am yet to check out whether it gives any API which i can use in my application to get some information I need.
Thanks everyone for helping me out.

Guidance for Migrating MS Access Apps to .Net Apps

I will soon begin the painful*(kidding)* process of migrating multiple, separate, Access Applications to "Real" applications*(notice the quotes, no flame wars please)*. Most likely this will be Web Apps as the usual reason is multiple users and deployability but I will take it case by case.
Some of these are traditional Access apps using Access as the back end and others are using SQL Server(a central one) as the back end.
What I am looking for is a combination of your experience doing this and what resources you used to help.
Websites, apps, standards, best practices, gotcha's, don't forget's, etcetera.
I am a 1 person C# shop with SQL Server back end so whether Web or not I will be looking that direction.
Also, is it overkill or unattainable to try and develop a Framework for this kind of thing? Would there just be TOO MANY variables to even try and walk this path? Anyone ever try this?
Some further info based on below questions. We currently have ~250 users and they are spread between 5 Locations.
What I meant by deployability is perhaps a little vague. I simply meant that we are a Non-Profit Organization and as such we do not have the best bandwidth available so deploying full apps, even through ClickOnce can be tricky when combinded with the highly fickle nature of my users*(I want that box purple, no green, no get rid of it altogether type stuff...)*.
My idea is to try and develop a "framework", of sorts, that will help to streamline the process of moving an Access App to a .Net App.
Now I fully understand that this "framework" may be nothing more than a set of steps and guidelines; like, Use ORM*(LINQ2SQL or SubSonic)*to generate DAL, Copy UI to corresponding UserControls, rewrite Business Logic.
I am just looking for your experience/expertise to help me streamline my streamlining process... ;)
Those apps which use an Access database to store tables and which need web access should first be upsized to SQL Server. There is a tool from the SQL Server group. SQL Server Migration Assistant for Access (SSMA Access)
Then consider moving to the web only that portion of the app that requires remote access. And leaving the rest of the app in Access. That could save a considerable amount of time.
Alternatively consider going to Terminal Server. That along with a VPN means just some software licensing costs and next to no work on your part.
That said what do you mean by "multiple users" and "deployability"? Possibly we can give you some suggestions there. Access is multi user out of the box. However if you have mission critical data or can't rekey the data in the event of a corruption or have more than 25-50 users on the LAN then you should be moving the data to SQL Server.
Now that it's public Access 2010 can deploy applications to the web. All kinds of very interesting stuff can be done. For more information check the Microsoft Access product group blog or my blog with the appropriate Access 2010 tags
Speaking from experience I think you would need to upgrade on a case by case basis. Upgrading is essentially a re-write from scratch and you should take the opportunity here to re-design as necessary. The type of application structure and code style used for Access (likely to be procedural I'm guessing) is very different to a well designed OO .Net app.
You will be able to re-use the SQL Server databases of course and, depending on the apps maybe even the Access ones. If you're feeling brave you could even try the upsizing wizard although I wouldn't recommend it as we found the results less than ideal.
I would also advise you take a look at some kind of ORM tool (we use Subsonic) as this can massively reduce the amount of boiler plate code you need to write. Some ORM tools will also generate DDL for your database too.
We follow these standards (good idea to pick a standard early on and stick to it we found) and also found this really useful to get up and running.
Hope this was some help.

Track used applications

I've been using Wakoopa recently, and I find it quite amusing.
I had no idea ( well I had an idea but never got real data about it ) on how much time I spend in SO until this:
alt text http://img396.imageshack.us/img396/4699/wakoopaim1.png
So my programming question is:
How can I programmatically track the applications being used?
My initial though was to use something like "tasklist" command and "netstat" and pool every 15 minutes or something like that, but I don't think this is the way they're doing this.
Is there a library in .NET ( in C# I guess ) to do this? Does windows provides some kind of service like this? What about java?
I usually have at least some vague idea on how some programming task could be performed, but for this I don't have a clue.
The wakoopa app tracker works on OSX and Linux too, but it is clear to me they are three different apps, one per platform
BTW, how much do you used SO? :)
Here is a link to an article with source covering the Process Structure Routines API Detecting Windows NT/2K process execution. I thought that the SysInternals site had source to Process Monitor, but I don't see any. The article should point you in the right direction for Windows systems.
Here is a link that may be helpful for Linux systems PROCPS
Here is a link to a java swing top utility Monitor It uses JNI, so not sure if it really fits as a java solution.
And to answer the SO question, I only periodically visit the site. I find I spend too much time on it if I visit regularly.
Familiarize yourself with the Server Explorer in Visual Studio -- look under 'Process'.
Then read up on the PerformanceCounter class.

Categories

Resources