Skip to content

Instantly share code, notes, and snippets.

@akshendra
akshendra / cw-mongo.py
Last active October 30, 2019 09:53
Mongo info on cloudwatch
#!/usr/bin/env python3
import os
import pprint
import boto3
from pymongo import MongoClient
pp = pprint.PrettyPrinter(indent=2)
dbName = os.environ['MONGO_DB_NAME']
dbReplicaSet = os.environ['MONGO_REPLICA_SET']
@akshendra
akshendra / redis.conf
Created June 18, 2018 11:07
Cluster configuration for redis
################################## NETWORK #####################################
bind 0.0.0.0
protected-mode no
port 6379
tcp-backlog 511
## Close the connection after a client is idle for N seconds (0 to disable)
timeout 0
## ACK time period
@akshendra
akshendra / cw-ec2:redis-cw.py
Last active November 26, 2021 11:33
Send redis info to cloudwatch
#!/usr/bin/env python3
'''
Send Redis usage metrics to CloudWatch
'''
import redis
import json
import boto3
import os
@akshendra
akshendra / cw-ec2:rabbit.py
Last active June 12, 2018 13:56
Send RabbitMQ queues data to cloudwatch
#!/usr/bin/env python3
'''
Send rabbitmq queue data to cloudwatch
'''
import boto3
import os
import json
import requests
@akshendra
akshendra / cw-ecs:machine.py
Last active June 12, 2018 13:36
Send machine related into to Cloudwatch, like RAM, disk etc
#!/usr/bin/env python3
# Machine info on EC2 linux machines
import re
import os
import boto3
machine = os.environ['MACHINE_NAME']
region = os.environ['AWS_REGION']
@akshendra
akshendra / cw-ec2:setup.sh
Last active December 24, 2019 11:24
Setup ec2 for sending info to cloudwatch
#!/usr/bin/env bash
# Setup for gathering metrices, debian based
required_env='AWS_REGION, MONITOR_DISKS, MACHINE_NAME';
function checkEnv() {
echo "Checking $1"
local val=$(env | grep "$1")
echo $val
@akshendra
akshendra / mongo-bulk.js
Created April 17, 2018 06:06
mongo bulk insert
function updateOrUpsertMany(mongo, col, docs) {
const bulk = mongo.colection(col).initializeUnorderedBulkOp();
docs.forEach(doc => {
bulk.find({ _id: doc._id }).upsert().updateOne({ $set: doc });
});
if (docs.length > 0) {
return bulk.execute()
.catch((ex) => {
if (ex.message.indexOf('E11000 duplicate key error collection') !== -1) {
return this.updateOrUpsertMany(mongo, col, docs);
@akshendra
akshendra / ssh-alias-for-aws-ec2.py
Last active December 10, 2017 15:30
Generate ssh aliases for aws ec2 instances
#!/usr/bin/env python3
"""
Create ssh shortcut alias
"""
import boto3
ec2 = boto3.client('ec2')
@akshendra
akshendra / qerror.js
Created June 9, 2017 11:11
Extended error
/**
* @class QError
*/
class QError extends Error {
/**
* @param {string} message
* @param {string} [type=error]
* @param {Object} [cause=null] - extra data for debugging
*/
'use strict';
/**
* =============================================================================================
* A state container
* @exports {Object} Continer
*
* // in the very beginning
* const con = require('container.js')
* con.add('logger', new Logger('log'));