-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
254 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
curl -u $LIBRATO_EMAIL:$LIBRATO_TOKEN \ | ||
-d '&gauges[0][name]=CPU'\ | ||
'&gauges[0][value]='`echo $(ps aux | awk '{s=s+$3}; END{print s}')`''\ | ||
'&gauges[0][source]=clojurians-log'\ | ||
'&gauges[1][name]=MEM'\ | ||
'&gauges[1][value]='`echo $(ps aux | awk '{s=s+$4}; END{print s}')`''\ | ||
'&gauges[1][source]=clojurians-log' \ | ||
'&gauges[1][name]=Disk'\ | ||
'&gauges[2][value]='`df | grep /dev/vda1 | awk '{print $5}' | sed s/%//`''\ | ||
'&gauges[2][source]=clojurians-log' \ | ||
-X POST https://metrics-api.librato.com/v1/metrics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'time' | ||
require 'net/http' | ||
require 'json' | ||
|
||
ENDPOINT = 'https://metrics-api.librato.com/v1/metrics' | ||
|
||
def read_log(path) | ||
IO.read(path).split("\n").map { |l| d,*r = l.split(" - "); [Time.parse(d), *r] rescue nil }.compact | ||
end | ||
|
||
def log_since(log, time) | ||
log.select { |l| l[0] >= time } | ||
end | ||
|
||
def histo(values) | ||
values.each.with_object(Hash.new(0)) do |v, h| | ||
h[v]+=1 | ||
end | ||
end | ||
|
||
def POST(uri, headers = {}) | ||
uri = URI(uri) | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
http.use_ssl = true if uri.scheme == 'https' | ||
request = Net::HTTP::Post.new(uri.request_uri, headers) | ||
yield request | ||
response = http.request(request) | ||
end | ||
|
||
def req_time_bucket(t) | ||
if t > 10 | ||
"10s+" | ||
else | ||
"#{t.round}s" | ||
end | ||
end | ||
|
||
loop do | ||
log = read_log('/var/log/nginx/access.log') | ||
log = log_since(log, Time.now - 60) | ||
|
||
unless log.empty? | ||
codes = histo(log.map{|l| l[2]}) | ||
request_times = histo(log.map{|l| req_time_bucket(l[3].to_f)}) | ||
|
||
codes = codes.map { |k,v| ["HTTP_#{k}", v] }.to_h | ||
request_times = request_times.map { |k,v| ["req_time_#{k}", v]}.to_h | ||
|
||
payload = codes.merge(request_times).map.with_index do |(name,count), idx| | ||
{"gauges[#{idx}][name]" => name, | ||
"gauges[#{idx}][value]" => count, | ||
"gauges[#{idx}][source]" => 'clojurians-log' | ||
} | ||
end.reduce(&:merge) | ||
|
||
p payload | ||
|
||
res = POST(ENDPOINT, {'Content-Type' => 'application/x-www-form-urlencoded'}) do |req| | ||
req.basic_auth ENV['LIBRATO_EMAIL'], ENV['LIBRATO_TOKEN'] | ||
req.set_form_data(payload) | ||
end | ||
|
||
p res | ||
p res.body | ||
end | ||
|
||
sleep 60 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
cd /var/clojure_app | ||
cp rtmbot/logs/* logs/logs | ||
cd logs | ||
./sync | ||
{ | ||
echo "(require 'clojurians-log.repl)" | ||
echo "(load-slack-data!)" | ||
git diff-tree --no-commit-id --name-only -r HEAD | grep logs/201 | xargs -n 1 printf '(clojurians-log.repl/load-log-file! (clojure.java.io/file "'$(pwd)'/%s"))\n' | ||
} | nc localhost 50505 | ||
sudo systemctl restart clojure_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
User-agent: SemrushBot | ||
Disallow: / | ||
|
||
User-agent: SemrushBot-SA | ||
Disallow: / | ||
|
||
User-agent: dotbot | ||
Disallow: / | ||
|
||
User-agent: linkdexbot/2.0 | ||
Disallow: / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(ns clojurians-log.db.import-test | ||
(:require [clojure.test :refer :all] | ||
[clojurians-log.db.import :as import])) | ||
|
||
(deftest event->tx-test | ||
(testing "returns valid datomic transaction data" | ||
(is (= #:message{:key "C0617A8PQ--1517728899.000025" | ||
:ts "1517728899.000025" | ||
:day "2018-02-04" | ||
:text ":smile:" | ||
:channel [:channel/slack-id "C0617A8PQ"] | ||
:user [:user/slack-id "U051BLM8F"]} | ||
(import/event->tx {:source_team "T03RZGPFR" | ||
:text ":smile:" | ||
:ts "1517728899.000025" | ||
:user "U051BLM8F" | ||
:team "T03RZGPFR" | ||
:type "message" | ||
:channel "C0617A8PQ"})))) | ||
|
||
(testing "parses thread info" | ||
(is (= {:message/thread-ts "1517483637.000077" | ||
:message/thread-inst #inst "2018-02-01T11:13:57.000-00:00"} | ||
(-> (import/event->tx {:source_team "T03RZGPFR" | ||
:reply_broadcast true | ||
:channel "C03S1L9DN" | ||
:type "message" | ||
:thread_ts "1517483637.000077" | ||
:ts "1517487432.000382" | ||
:team "T03RZGPFR" | ||
:user "U7THYHQ1F" | ||
:text "Wow, thanks!"}) | ||
(select-keys [:message/thread-ts :message/thread-inst]))))) | ||
|
||
(testing "puts threaded messages on the day of the thread" | ||
(is (= "2018-02-06" | ||
(:message/day (import/event->tx {:thread_ts "1517932488.000769" | ||
:source_team "T03RZGPFR" | ||
:text "posted on 2018-02-08, replying to a message from 2018-02-06" | ||
:ts "1518050759.000174" | ||
:user "U8MJBRSR5" | ||
:team "T03RZGPFR" | ||
:type "message" | ||
:channel "C03RZRRMP"})))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(ns clojurians-log.repl-test | ||
(:require [clojurians-log.repl :as repl] | ||
[clojurians-log.slack-api :as slack] | ||
[clojure.test :refer :all])) | ||
|
||
|
||
(deftest load-slack-data!-test | ||
(testing "it handles renames" | ||
(with-redefs [slack/users (constantly []) | ||
slack/channels (constantly {:id "C03RZGPG1" | ||
:name "announcements" | ||
:creator "U03RZGPFT" | ||
:created 1425231209})] | ||
(repl/load-slack-data!) | ||
) | ||
|
||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
(ns clojurians-log.slack-api-test | ||
(:require [clojurians-log.slack-api :as slack] | ||
[clojurians-log.db.queries :as queries] | ||
[clojurians-log.test-helper :refer [test-conn]] | ||
[clojure.test :refer :all] | ||
[datomic.api :as d])) | ||
|
||
(deftest import-channels!-test | ||
(testing "it handles renames" | ||
(let [conn (test-conn)] | ||
(with-redefs [slack/users (constantly [{:id "U03RZGPFT"}]) | ||
slack/channels (constantly [{:id "C03RZGPG1" | ||
:name "announcements" | ||
:creator "U03RZGPFT" | ||
:created 1425231209}])] | ||
|
||
(slack/import-users! conn) | ||
(slack/import-channels! conn) | ||
(is (= (select-keys (queries/channel (d/db conn) "announcements") | ||
[:channel/slack-id :channel/name]) | ||
{:channel/slack-id "C03RZGPG1" | ||
:channel/name "announcements"}))) | ||
|
||
(with-redefs [slack/users (constantly [{:id "U03RZGPFT"}]) | ||
slack/channels (constantly [{:id "C03RZGPG1" | ||
:name "admin-announcements" | ||
:creator "U03RZGPFT" | ||
:created 1425231209}])] | ||
|
||
(slack/import-channels! conn) | ||
(is (= (select-keys (queries/channel (d/db conn) "admin-announcements") | ||
[:channel/slack-id :channel/name]) | ||
{:channel/slack-id "C03RZGPG1" | ||
:channel/name "admin-announcements"})))))) |