Skip to content

Instantly share code, notes, and snippets.

View tomaustin700's full-sized avatar
🏠
Working from home

Tom Austin tomaustin700

🏠
Working from home
View GitHub Profile
@tomaustin700
tomaustin700 / bosun.conf
Created May 5, 2019 13:21
Supervisor file for Bosun
[program:bosun]
command=/bosun/bosun -c /data/bosun.toml
stdout_logfile=/var/log/bosun.out.log
stderr_logfile=/var/log/bosun.err.log
autostart=true
autorestart=true
@tomaustin700
tomaustin700 / bosun.toml
Last active May 5, 2019 13:14
Sample Bosun.toml file
# Hostname will be used when links are created in templates (i.e. acknowledge links)
#Hostname = "bosun.example.com"
# The HTTP IP and Port to Listen on. Default is ":8070"
#HTTPListen = ":8080"
# Alert checks are run by default every CheckFrequency * DefaultRunEvery. RunEvery can be overridden
# by indivdual alerts. Defaults are "5m" and 1
CheckFrequency = "1m"
DefaultRunEvery = 5
public static async Task Time(Func<Task> action, EventGauge gauge)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
await action.Invoke();
stopwatch.Stop();
gauge.Record(stopwatch.Elapsed.TotalMilliseconds, DateTime.Now);
}
await Time(async () =>
{
await GetWeather();
}, _timer);
_timer = _collector.CreateMetric<EventGauge>("GetWeather", "time taken", "measures time taken to get weather from api");
static MetricsCollector _collector;
_collector = new MetricsCollector(new BosunOptions(ex => Handle(ex))
{
MetricsNamePrefix = "TestApp.",
BosunUrl = new System.Uri("http://192.168.1.5:8070"),
PropertyToTagName = NameTransformers.CamelToLowerSnakeCase,
ThrowOnPostFail = true,
DefaultTags = new Dictionary<string, string>{ {"host", NameTransformers.Sanitize(Environment.MachineName.ToLower())},
{ "client", "home" }, }
//Returns time taken for execution of synchronous code
var syncTime = Metricity.Timings.Time(() =>
{
SyncMethod();
});
//Returns time taken for execution of asynchronous code
var asyncTime = Metricity.Timings.Time(async () =>
{
await ASyncMethod();
@tomaustin700
tomaustin700 / VarbinaryToByte[]C#
Created April 20, 2018 10:23
Converts SQL varbinary image into C# Byte[]
string stringFromSQL = "0x6100730064006600";
List<byte> byteList = new List<byte>();
string hexPart = stringFromSQL.Substring(2);
for (int i = 0; i < hexPart.Length / 2; i++)
{
string hexNumber = hexPart.Substring(i * 2, 2);
byteList.Add((byte)Convert.ToInt32(hexNumber, 16));
}
@tomaustin700
tomaustin700 / ListExtensions.cs
Created April 18, 2018 07:12
Extension method for generating a Cartesian product
public static class ListExtentions
{
public static IEnumerable Cartesian(this IEnumerable<IEnumerable> items)
{
var slots = items
// initialize enumerators
.Select(x => x.GetEnumerator())
// get only those that could start in case there is an empty collection
.Where(x => x.MoveNext())
.ToArray();
#!/usr/bin/env bash
# ----------------------------------------------------------------------------------
# Script for checking the temperature reported by the ambient temperature sensor,
# and if deemed to high send the raw IPMI command to enable dynamic fan control.
#
# Requires ipmitool – apt-get install ipmitool
# Tested on Ubuntu 17.04
# ----------------------------------------------------------------------------------