1

In my ASP.NET MVC3 application hosted in Windows Azure I want to know how many times the application has been restarted (so that I know the startup sequence is correct). So I need some kind of "variable" that I could "increment" from inside Application_Start() but it should be stored in some persistent way because otherwise it will simply not survive the application restart. The storage needs to be per instance of application.

Of course I could use system registry or some temporary file but I guess there should be something better.

Is there anything in ASP.NET infrastructure that I could use for my scenario?

sharptooth
  • 167,383
  • 100
  • 513
  • 979
  • If you have access to the file system, you could store in the AppData directory in a Text or XML file. If you have access to SQL Server you can also store it there. This seems pretty straight forward, or am I missing something? – Erik Philips Oct 09 '13 at 07:11
  • @ErikPhilips: Yeap, this is quite straightforward, but that's quite a lot of code. I hoped there's something easier like a session variable. – sharptooth Oct 09 '13 at 07:42
  • @ErikPhilips - If this is a web role running in a Cloud Service, local storage won't suffice, as there's no guarantee the storage will remain in existence. Also: even if you *did* store on each instance, you'd then only be able to collect such data by connecting to each instance. And once you scale *in* to fewer instances, you'd lose valuable data. See Gaurav's answer below for an externalized, durable storage solution. – David Makogon Oct 09 '13 at 12:53

2 Answers2

2

You could possible use Windows Azure Table Storage for that. Just thinking out loud, you could have a table called ApplicationRestarts and every time application starts, you could put an entity into that table. The entity could have the following attributes:

  • PartitionKey: Could be the date/time when an application was restarted. Or it could be role instance name.
  • RowKey: Same as above. If you choose date/time as PartitionKey, then role instance name could be RowKey or vice-versa.
  • RoleName: Name of the role (just in case you're intersted in capturing that).
  • RoleInstanceName: Name of the role instance.
  • RestartTimestamp: Date/time role instance was restarted.
  • Metadata: Some other information that you may want to capture.
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
0

If you are using Windows Azure Virtual Machine, you can create a powershell script that will be fired after the recycle pool event.

http://blogs.technet.com/b/wincat/archive/2011/08/25/trigger-a-powershell-script-from-a-windows-event.aspx

More useful links:

https://webmasters.stackexchange.com/a/17633

https://stackoverflow.com/a/13623638/1384539

Community
  • 1
  • 1
Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
  • Okay, it fires and then I do what? – sharptooth Oct 09 '13 at 13:38
  • Since you can capture the event, you can do whatever you want. i.e send a email, create a dashboard, – Thiago Custodio Oct 09 '13 at 13:45
  • Sure, but those won't be very useful for programmatically finding out *how many times the application restarted*, will they? – sharptooth Oct 09 '13 at 13:48
  • Right, I just gave you another point of view... you should create your own storage system. I recommend a NoSql like Redis or MongoDB, since it's very fast and you can perform querys on that. Another option, you could use Elmah to store that in XML files or SQL Server. – Thiago Custodio Oct 09 '13 at 14:20