This file contains hidden or 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
| #!/bin/bash | |
| # Check out the blog post at: | |
| # | |
| # http://www.philipotoole.com/influxdb-and-grafana-howto | |
| # | |
| # for full details on how to use this script. | |
| AWS_EC2_HOSTNAME_URL=http://169.254.169.254/latest/meta-data/public-hostname | |
| INFLUXDB_DATABASE=test1 |
This file contains hidden or 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
| package main | |
| import ( | |
| "bufio" | |
| "encoding/csv" | |
| "encoding/json" | |
| "fmt" | |
| "io" | |
| "os" | |
| "path/filepath" |
This file contains hidden or 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
| # Example controller | |
| class IncomesController < ApplicationController | |
| # Include the print | |
| include Controllers::Print | |
| # GET /incomes/1 | |
| def show | |
| @income = present Income.find(params[:id]) | |
| respond_to do |format| |
This file contains hidden or 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
| type PayloadCollection struct { | |
| WindowsVersion string `json:"version"` | |
| Token string `json:"token"` | |
| Payloads []Payload `json:"data"` | |
| } | |
| type Payload struct { | |
| // [redacted] | |
| } |
This file contains hidden or 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
| func payloadHandler(w http.ResponseWriter, r *http.Request) { | |
| if r.Method != "POST" { | |
| w.WriteHeader(http.StatusMethodNotAllowed) | |
| return | |
| } | |
| // Read the body into a string for json decoding | |
| var content = &PayloadCollection{} | |
| err := json.NewDecoder(io.LimitReader(r.Body, MaxLength)).Decode(&content) |
This file contains hidden or 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
| var Queue chan Payload | |
| func init() { | |
| Queue = make(chan Payload, MAX_QUEUE) | |
| } | |
| func payloadHandler(w http.ResponseWriter, r *http.Request) { | |
| ... | |
| // Go through each payload and queue items individually to be posted to S3 | |
| for _, payload := range content.Payloads { |
This file contains hidden or 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
| func StartProcessor() { | |
| for { | |
| select { | |
| case job := <-Queue: | |
| job.payload.UploadToS3() // <-- STILL NOT GOOD | |
| } | |
| } | |
| } |
This file contains hidden or 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
| var ( | |
| MaxWorker = os.Getenv("MAX_WORKERS") | |
| MaxQueue = os.Getenv("MAX_QUEUE") | |
| ) | |
| // Job represents the job to be run | |
| type Job struct { | |
| Payload Payload | |
| } |
This file contains hidden or 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
| func payloadHandler(w http.ResponseWriter, r *http.Request) { | |
| if r.Method != "POST" { | |
| w.WriteHeader(http.StatusMethodNotAllowed) | |
| return | |
| } | |
| // Read the body into a string for json decoding | |
| var content = &PayloadCollection{} | |
| err := json.NewDecoder(io.LimitReader(r.Body, MaxLength)).Decode(&content) |
This file contains hidden or 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
| type Dispatcher struct { | |
| // A pool of workers channels that are registered with the dispatcher | |
| WorkerPool chan chan Job | |
| } | |
| func NewDispatcher(maxWorkers int) *Dispatcher { | |
| pool := make(chan chan Job, maxWorkers) | |
| return &Dispatcher{WorkerPool: pool} | |
| } |
OlderNewer