Skip to content

Instantly share code, notes, and snippets.

hostname, _ := os.Hostname()
value := someWork()
fmt.Printf("PUTVAL %s/my-plugin/gauge-my_metric interval=%d N:%s\n", hostname, interval, value)
@jacoelho
jacoelho / collectd.go
Last active August 5, 2016 20:48
sample collectd plugin
package main
import (
"flag"
"time"
)
func main() {
var (
interval = flag.Int("interval", 5, "time in seconds between collection")
package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"os"
"strings"
(defn get-all-todo
[]
(let [result (jdbc/with-db-connection
[conn (db-connection)]
(jdbc/query conn
["select * from todo_list"]))]
{:status 200
:body {:result result}}))
(defn create-todo
(defn create-table
[]
(jdbc/db-do-commands
(db-connection)
(jdbc/create-table-ddl :todo_list
[[:id :int "PRIMARY KEY AUTO_INCREMENT"]
[:title "varchar(30)"]
[:text "varchar(1024)"]])))
(def db-config
{:classname "org.h2.Driver"
:subprotocol "h2"
:subname "mem:todo"
:user ""
:password ""})
(defn pool
[config]
(let [cpds
(defroutes app-routes
(GET "/" [] (get-all-todo))
(POST "/" {params :params} (create-todo params))
(context "/:id" [id]
(GET "/" [] (get-todo id))
(PUT "/" {params :params} (update-todo id params))
(DELETE "/" [] (delete-todo id)))
(not-found "sorry"))
(def app
(-> app-routes
wrap-json-params
wrap-json-response))
(ns todo-rest.core
(:require [ring.adapter.jetty :as jetty]
[ring.middleware.reload :refer [wrap-reload]]
[compojure.core :refer [defroutes context GET POST PUT DELETE]]
[compojure.route :refer [not-found]])
(:gen-class))
(defroutes app-routes
(GET "/" [] {:status 200 :body "hello world" :headers {}})
(not-found "sorry"))
(defproject todo-rest "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
[ring "1.5.0"]
[compojure "1.5.1"]]
:min-lein-version "2.0.0"
:main todo-rest.core