Skip to content
Permalink
Browse files

Hello World

Initial commit of Opserver
  • Loading branch information
NickCraver committed Oct 15, 2013
0 parents commit 957a0296fda3662be1fd5683682075c970824154
Showing 489 changed files with 172,239 additions and 0 deletions.
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
@@ -0,0 +1,221 @@
#################
## Eclipse
#################

*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf

#############
## Windows detritus
#############

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac crap
.DS_Store


#############
## Python
#############

*.py[co]

# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

#Mr Developer
.mr.developer.cfg

.hg
.hgignore
Opserver/config/*.json
Opserver/config/*.config
*.StackOverflow.*
@@ -0,0 +1,15 @@
namespace StackExchange.Opserver
{
internal partial class Current
{
public static Helpers.LocalCache LocalCache = new Helpers.LocalCache();
}

public static class CoreCurrent
{
public static Helpers.LocalCache LocalCache
{
get { return Current.LocalCache; }
}
}
}
@@ -0,0 +1,101 @@
using System;
using StackExchange.Exceptional;
using StackExchange.Opserver.SettingsProviders;

namespace StackExchange.Opserver
{
internal static partial class Current
{
public static SettingsProvider Settings
{
get { return SettingsProvider.Current; }
}

/// <summary>
/// manually write an exception to our standard exception log
/// </summary>
public static void LogException(string message, Exception innerException, string key = null, int? reLogDelaySeconds = null)
{
var ex = new Exception(message, innerException);
LogException(ex);
}

/// <summary>
/// manually write an exception to our standard exception log
/// </summary>
public static void LogException(Exception ex, string key = null, int? reLogDelaySeconds = null)
{
if (!ShouldLog(key)) return;
ErrorStore.LogExceptionWithoutContext(ex, appendFullStackTrace: true);
RecordLogged(key);
}

/// <summary>
/// record that an exception was logged in local cache for the specified length of time (default of 30 minutes)
/// </summary>
private static void RecordLogged(string key, int? reLogDelaySeconds = 30 * 60 * 60)
{
if (key.IsNullOrEmpty() || !reLogDelaySeconds.HasValue) return;
LocalCache.Set("ExceptionLogRetry-" + key, true, reLogDelaySeconds.Value);
}

/// <summary>
/// see if an exception with the given key should be logged, based on if it was logged recently
/// </summary>
private static bool ShouldLog(string key)
{
if (key.IsNullOrEmpty()) return true;
return !LocalCache.Get<bool?>("ExceptionLogRetry-"+key).GetValueOrDefault();
}

/// <summary>
/// Caches a backoff for the given command
/// </summary>
public static void SetBackOff(string key, int durationSeconds)
{
LocalCache.Set("BackOff-" + key, true, durationSeconds);
}

/// <summary>
/// Whether this given key should backoff and not proceed in its action
/// </summary>
public static bool ShouldBackOff(string key)
{
return LocalCache.Get<bool?>("BackOff-" + key).GetValueOrDefault();
}

public static int DefaultExceptionBackOffSeconds = 5;

/// <summary>
/// Executes a command with a backoff. If a previous command errored or set a backoff on execution, a default(T) will be returned.
/// </summary>
/// <typeparam name="T">Result type</typeparam>
/// <param name="key">The backoff cache key to use</param>
/// <param name="toRun">The degate to execute</param>
/// <param name="exceptionBackOffSeconds">How long to backoff if an exception arises</param>
/// <param name="defaultResult">The return to provide if told to BACK THE HELL OFF</param>
public static T ExecWithBackoff<T>(string key, Func<BackOffArgs, T> toRun, int? exceptionBackOffSeconds = null, T defaultResult = default(T))
{
if (ShouldBackOff(key))
return defaultResult;
var b = new BackOffArgs();
try
{
var result = toRun(b);
if (b.BackOffSeconds.HasValue)
SetBackOff(key, b.BackOffSeconds.GetValueOrDefault());
return result;
}
catch (Exception)
{
SetBackOff(key, exceptionBackOffSeconds.GetValueOrDefault(DefaultExceptionBackOffSeconds));
return defaultResult;
}
}

public class BackOffArgs
{
public int? BackOffSeconds { get; set; }
}
}
}

0 comments on commit 957a029

Please sign in to comment.
You can’t perform that action at this time.