<commit_before>#!/usr/bin/env python

import os
import sys

import time
import json

import psutil
import pycurl

THRESHOLD      = 90.0 # percentage
REPEAT_EVERY   = 5    # seconds
MAX_OCCURRENCE = 5    # times
KILL_ENABLED   = False

my_pid   = os.getpid()
bad_guys = {}

PAYLOAD  = {
    "channel"    : "#_devops",
    "username"   : "py_assassin",
    "icon_emoji" : ":snake:"
}

slack = pycurl.Curl()
slack.setopt(pycurl.URL, "<KEY>")
slack.setopt(pycurl.POST, 1)

def slack_it(message):

    print message

    PAYLOAD['text'] = message
    slack.setopt(pycurl.POSTFIELDS, "payload=%s" % json.dumps(PAYLOAD))
    slack.perform()


def get_top_processes():

    procs = []

    for p in psutil.process_iter():

        if p.pid == my_pid:
            continue

        try:
            p.dict = p.as_dict(['get_cpu_percent', 'name', 'status'])

        except:
            pass

        else:
            if p.dict['cpu_percent'] > THRESHOLD:
                procs.append(p)

    # return processes sorted by CPU percent usage
    return sorted(procs, key=lambda p: p.dict['cpu_percent'], reverse = True)<commit_msg>Add SLACK as an optional feature<commit_after>#!/usr/bin/env python

import os
import sys

import time
import json

import psutil
import pycurl

THRESHOLD      = 90.0 # percentage
REPEAT_EVERY   = 5    # seconds
MAX_OCCURRENCE = 5    # times
KILL_ENABLED   = False
SLACK_ENABLED  = False

my_pid   = os.getpid()
bad_guys = {}

PAYLOAD  = {
    "channel"    : "#_devops",
    "username"   : "py_assassin",
    "icon_emoji" : ":snake:"
}

slack = pycurl.Curl()
slack.setopt(pycurl.URL, "<KEY>")
slack.setopt(pycurl.POST, 1)

def slack_it(message):

    print message

    if not SLACK_ENABLED:
        return

    PAYLOAD['text'] = message
    slack.setopt(pycurl.POSTFIELDS, "payload=%s" % json.dumps(PAYLOAD))
    slack.perform()


def get_top_processes():

    procs = []

    for p in psutil.process_iter():

        if p.pid == my_pid:
            continue

        try:
            p.dict = p.as_dict(['get_cpu_percent', 'name', 'status'])

        except:
            pass

        else:
            if p.dict['cpu_percent'] > THRESHOLD:
                procs.append(p)

    # return processes sorted by CPU percent usage
    return sorted(procs, key=lambda p: p.dict['cpu_percent'], reverse = True)
{'fraction_non_alphanumeric': 0.12392426850258176, 'fraction_numerical': 0.0051635111876075735, 'mean_word_length': 2.528072837632777, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7444567', 'n_tokens_mistral': 870, 'n_tokens_neox': 829, 'n_words': 186}