mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-13 19:56:38 +05:00
both multiple raters and status page working
This commit is contained in:
@@ -19,7 +19,6 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -30,17 +29,6 @@ type IncorrectParameters struct {
|
||||
Error string
|
||||
}
|
||||
|
||||
/*
|
||||
Handler for the statistics web client
|
||||
*/
|
||||
func statusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, "<html><body><ol>")
|
||||
for _, addr := range raterList.clientAddresses {
|
||||
fmt.Fprint(w, fmt.Sprintf("<li>Client: %v</li>", addr))
|
||||
}
|
||||
fmt.Fprint(w, "</ol></body></html>")
|
||||
}
|
||||
|
||||
/*
|
||||
curl "http://127.0.0.1:8000/getcost?cstmid=vdf&subj=rif&dest=0257"
|
||||
*/
|
||||
@@ -216,7 +204,7 @@ func resetUserBudget(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func listenToHttpRequests() {
|
||||
http.HandleFunc("/", statusHandler)
|
||||
http.Handle("/static/", http.FileServer(http.Dir("")))
|
||||
http.HandleFunc("/getcost", getCostHandler)
|
||||
http.HandleFunc("/debitbalance", debitBalanceHandler)
|
||||
http.HandleFunc("/debitsms", debitSMSHandler)
|
||||
@@ -226,12 +214,9 @@ func listenToHttpRequests() {
|
||||
http.HandleFunc("/resetvolumediscountseconds", resetVolumeDiscountSeconds)
|
||||
http.HandleFunc("/addrecievedcallseconds", addRecievedCallSeconds)
|
||||
http.HandleFunc("/resetuserbudget", resetUserBudget)
|
||||
<<<<<<< Updated upstream
|
||||
=======
|
||||
http.HandleFunc("/", statusHandler)
|
||||
http.HandleFunc("/getmem", memoryHandler)
|
||||
http.HandleFunc("/raters", ratersHandler)
|
||||
>>>>>>> Stashed changes
|
||||
log.Print("The server is listening on ", *httpApiAddress)
|
||||
http.ListenAndServe(*httpApiAddress, nil)
|
||||
}
|
||||
|
||||
@@ -18,12 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package main
|
||||
|
||||
import (
|
||||
"os/signal"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/rpc"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/rpc"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
@@ -33,11 +34,37 @@ RPC Server that handles the registering and unregistering of raters.
|
||||
*/
|
||||
type RaterServer byte
|
||||
|
||||
func listenToRPCRaterRequests(){
|
||||
raterServer := new(RaterServer)
|
||||
rpc.Register(raterServer)
|
||||
func listenToRPCRaterRequests() {
|
||||
/*rpc.Register(new(RaterServer))
|
||||
rpc.HandleHTTP()
|
||||
http.ListenAndServe(*raterAddress, nil)
|
||||
http.ListenAndServe(*raterAddress, nil)*/
|
||||
|
||||
rpc.Register(new(RaterServer))
|
||||
rpc.HandleHTTP()
|
||||
l, e := net.Listen("tcp", *raterAddress)
|
||||
if e != nil {
|
||||
log.Fatal("listen error:", e)
|
||||
}
|
||||
go http.Serve(l, nil)
|
||||
|
||||
/*log.Print("Starting Server...")
|
||||
l, err := net.Listen("tcp", *raterAddress)
|
||||
defer l.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Print("listening on: ", l.Addr())
|
||||
rpc.Register(new(RaterServer))
|
||||
for {
|
||||
log.Print("waiting for connections ...")
|
||||
conn, err := l.Accept()
|
||||
if err != nil {
|
||||
log.Printf("accept error: %s", conn)
|
||||
continue
|
||||
}
|
||||
log.Printf("connection started: %v", conn.RemoteAddr())
|
||||
go rpc.ServeConn(conn)
|
||||
}*/
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -19,7 +19,6 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -51,5 +50,6 @@ Ajax Handler for current used memory value
|
||||
func memoryHandler(w http.ResponseWriter, r *http.Request) {
|
||||
memstats := new(runtime.MemStats)
|
||||
runtime.ReadMemStats(memstats)
|
||||
fmt.Fprint(w, memstats.HeapAlloc/1024, memstats.Sys/1024)
|
||||
enc := json.NewEncoder(w)
|
||||
enc.Encode([]uint64{memstats.HeapAlloc / 1024, memstats.Sys / 1024})
|
||||
}
|
||||
|
||||
@@ -92,8 +92,7 @@
|
||||
limit = limit.slice(1);
|
||||
}
|
||||
|
||||
$.get("/getmem", function(memValue){
|
||||
memValue = memValue.split(" ");
|
||||
$.getJSON("/getmem", function(memValue){
|
||||
now = new Date()
|
||||
timeOffsetInHours = (now.getTimezoneOffset()/60) * (-1);
|
||||
now.setHours(now.getHours() + timeOffsetInHours);
|
||||
@@ -125,7 +124,7 @@
|
||||
|
||||
update();
|
||||
$("#rater-refresh").click(function(){
|
||||
$.get("/raters", function(raters){
|
||||
$.getJSON("/raters", function(raters){
|
||||
$("tr", "#rater-table").remove()
|
||||
console.log(raters);
|
||||
for(var i=0; i<raters.length; i++){
|
||||
|
||||
@@ -127,8 +127,8 @@ func (s *Storage) Shutdown(args string, reply *string) (err error) {
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
getter, err := timespans.NewKyotoStorage("storage.kch")
|
||||
//getter, err := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
//getter, err := timespans.NewKyotoStorage("storage.kch")
|
||||
getter, err := timespans.NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
if err != nil {
|
||||
log.Printf("Cannot open storage file: %v", err)
|
||||
|
||||
@@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package main
|
||||
|
||||
import (
|
||||
"os/signal"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"log"
|
||||
"net/rpc"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user